Skip to content

axelarnetwork/axelar-lints

Repository files navigation

Axelar Lints

Built using the dylint library (https://github.com/trailofbits/dylint).

Setup

Installing Dylint

# If this causes issues, try switching to a more recent version of rust.
cargo install cargo-dylint dylint-link

Using Dylint

Writing lints

Using Dylint, you can either set up lints as standalone libraries, or as a combined library. Currently, I've set up a library named "amplifier_lints" which will hold lints for axelar-amplifier.

You can set up a lint with cargo dylint new new_lint_name. Your new_lint_name/src/lib.rs file will be where you write your lint.

Combined libraries can contain a number of your lints. They have a number of requirements for the organization. Follow these requirements to get one working.

Here are some resources for creating lints:

  • Dylint has some good example lints that can help you get a good feel for how lints work.
  • Starting from LateLintPass in the rust docs and searching for functions in the rust docs can help in finding specific functionality for linting.

Running Dylint on Target Workspaces

To run a lint/library of lints from this repository, in the target workspace, add

[workspace.metadata.dylint]

[[workspace.metadata.dylint.libraries]]
git = "https://github.com/axelarnetwork/axelar-lints",
branch = "..", # Optional, for testings axelar-lints branches
pattern = [
    "amplifier-lints",
    ...
]

to the Cargo.toml file, and run cargo dylint --all.

Conditional Compilation

From what it appears, test code will not be linted by default (correct if wrong). Otherwise, allow a lint to be ignored as such:

#[cfg_attr(dylint_lib = "LIBRARY_NAME", allow(LINT_NAME))]

(e.g. LIBRARY_NAME="amplifier_lints", LINT_NAME="unwraps_outside_tests"), or if it is a pre-expansion lint,

#[allow(unknown_lints)]
#[allow(PRE_EXPANSION_LINT_NAME)]

NOTE: name your lint/library with underscores and not dashes in the Cargo.toml file, otherwise conditional compilation may not function properly (fairly certain this is a rust feature? remove this line if unnecessary).

Credits

About

Custom rust linter library

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages