A collection of lints to catch common mistakes and improve your Cairo code.
cairo-lint can either be used as a library or as a standalone binary. It can either just detect or fix the detected problems.
To use it with scarb simply install it like so:
cargo install scarb-cairo-lint --git https://github.com/keep-starknet-strange/cairo-lint
and then either run:
# Checks for bad patterns
scarb cairo-lint
# Checks and fixes what it can
scarb cairo-lint --fix
Note: You can also include test files with the --test
flag
0xLucqs 💻 |
Marco Araya Jiménez 💻 |
Mathieu 💻 |
Lau Chaves 💻 |
Renzo Banegas 💻 |
Steven 💻 |
Lindsay Morales 💻 |
Bernal Hidalgo 💻 |
Charlotte 💻 |
Bruno Ambricca 💻 |
guha-rahul 💻 |
Yusuf Habib 💻 |
To run the tests you'll need to provide the path to the cairo corelib (at some point this should be automated but we're not there yet).
CORELIB_PATH="/path/to/corelib/src" cargo test
To add a new test you can use the dev cli with:
cargo run --bin create_test <lint_name>
Each lint should have its own tests and should be extensive. To create a new test for a lint you need to create a file in the test_files folder and should be named as your lint. The file should have this format:
//! > Test name
//! > cairo_code
fn main() {
let a: Option<felt252> = Option::Some(1);
}
Then in the test file declare your lint like so:
test_file!(if_let, "Test name");
The first argument is the lint name (also the file name) and the other ones are the test names. After that you can run
FIX_TESTS=1 cargo test -p cairo-lint-core <name_of_lint>
This will generate the expected values in your test file. Make sure it is correct.