Add ink! linting MVP stage

Sergej Kostjucenko requested to merge cmichi-implemnt-dylint-mvp into master

Created by: cmichi

Closes https://github.com/paritytech/cargo-contract/issues/281.

This is an MVP, there are a couple shortcomings for which I want to create follow-up issues:

  • As it is now, we unfortunately have to require users to install dylint and dylint-driver manually. We should look into making those cargo dependencies instead. However, this is not straight forward. Especially for the dylint-driver (which is used as a linker) I'm not sure if this is even possible.

  • I haven't yet managed to get rid of some driver build overhead, this happens every time the linting is applied:

    [1/2] Checking ink! lints                                                     
    Building driver for toolchain `nightly-2021-11-04-x86_64-unknown-linux-gnu`        
  • We should render and publish a proper website displaying info about the linting rules. Similar to https://rust-lang.github.io/rust-clippy/master/.

  • We should recognize if the call to ink_lang::utils::initialize_contract is nested within the constructor. So if it's not called directly in the constructor, but instead in a sub-function.

How it works:

  • ink_linting/ contains the ink! linting driver (i.e. the linting rules).
  • build.rs builds these rules into a *.so/*.dll, this file is included via include_bytes! into the cargo-contract executable.

Try it out:

git checkout cmichi-implemnt-dylint-mvp
RUST_LOG=info cargo run -- contract check --manifest-path ../ink/examples/flipper/Cargo.toml --verbose

Merge request reports