An open API service indexing awesome lists of open source software.

https://github.com/keep-starknet-strange/cairo-lint

A collection of lints to catch common mistakes and improve your Cairo code.
https://github.com/keep-starknet-strange/cairo-lint

cairo cairo-lang starknet zk zkp

Last synced: 6 months ago
JSON representation

A collection of lints to catch common mistakes and improve your Cairo code.

Awesome Lists containing this project

README

        



cairo-lint

[![Check Workflow Status](https://github.com/keep-starknet-strange/snos/actions/workflows/check.yml/badge.svg)](https://github.com/keep-starknet-strange/snos/actions/workflows/check.yml)
[![Telegram](https://img.shields.io/badge/telegram-cairolint-blue.svg?logo=telegram)](https://t.me/cairolint)

[![Exploration_Team](https://img.shields.io/badge/Exploration_Team-29296E.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJhIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxODEgMTgxIj48ZGVmcz48c3R5bGU+LmJ7ZmlsbDojZmZmO308L3N0eWxlPjwvZGVmcz48cGF0aCBjbGFzcz0iYiIgZD0iTTE3Ni43Niw4OC4xOGwtMzYtMzcuNDNjLTEuMzMtMS40OC0zLjQxLTIuMDQtNS4zMS0xLjQybC0xMC42MiwyLjk4LTEyLjk1LDMuNjNoLjc4YzUuMTQtNC41Nyw5LjktOS41NSwxNC4yNS0xNC44OSwxLjY4LTEuNjgsMS44MS0yLjcyLDAtNC4yN0w5Mi40NSwuNzZxLTEuOTQtMS4wNC00LjAxLC4xM2MtMTIuMDQsMTIuNDMtMjMuODMsMjQuNzQtMzYsMzcuNjktMS4yLDEuNDUtMS41LDMuNDQtLjc4LDUuMThsNC4yNywxNi41OGMwLDIuNzIsMS40Miw1LjU3LDIuMDcsOC4yOS00LjczLTUuNjEtOS43NC0xMC45Ny0xNS4wMi0xNi4wNi0xLjY4LTEuODEtMi41OS0xLjgxLTQuNCwwTDQuMzksODguMDVjLTEuNjgsM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My42M1oiLz48L3N2Zz4=)](https://github.com/keep-starknet-strange)


A collection of lints to catch common mistakes and improve your [Cairo](https://github.com/starkware-libs/cairo) code.

## Usage

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:

```sh
cargo install scarb-cairo-lint --git https://github.com/keep-starknet-strange/cairo-lint
```

and then either run:

```sh
# Checks for bad patterns
scarb cairo-lint
```

```sh
# Checks and fixes what it can
scarb cairo-lint --fix
```

Note: You can also include test files with the `--test` flag

## Contributors



0xLucqs
0xLucqs

💻
Marco Araya Jiménez
Marco Araya Jiménez

💻 ⚠️
Mathieu
Mathieu

💻 ⚠️ 📖
Lau Chaves
Lau Chaves

💻 ⚠️
Renzo Banegas
Renzo Banegas

💻 ⚠️
Steven
Steven

💻 ⚠️
Lindsay Morales
Lindsay Morales

💻 ⚠️


Bernal Hidalgo
Bernal Hidalgo

💻 ⚠️
Charlotte
Charlotte

💻 ⚠️
Bruno Ambricca
Bruno Ambricca

💻 ⚠️
guha-rahul
guha-rahul

💻 ⚠️
Yusuf Habib
Yusuf Habib

💻 ⚠️
Tuan Tran
Tuan Tran

💻 ⚠️
BlockyJ
BlockyJ

💻 ⚠️


Luis Jiménez
Luis Jiménez

💻 ⚠️
Mariángela N.
Mariángela N.

💻 ⚠️
Gianfranco99
Gianfranco99

💻 ⚠️

## Contributing

**[Join the telegram group](t.me/cairo-lint)**

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).

```sh
CORELIB_PATH="/path/to/corelib/src" cargo test
```

### Cli instructions

To add a new test you can use the dev cli with:

```bash
cargo run --bin create_test
```

### Manual instructions

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](./crates/cairo-lint-core/tests/test_files/) and should be named as your lint. The file should
have this format:

```txt
//! > Test name

//! > cairo_code
fn main() {
let a: Option = Option::Some(1);
}
```

Then in the [test file](crates/cairo-lint-core/tests/tests.rs) declare your lint like so:

```rs
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
```

This will generate the expected values in your test file. Make sure it is correct.