Describe rule naming convention in CONTRIBUTING.md

This commit is contained in:
Martin Fischer 2023-02-10 06:56:50 +01:00 committed by Charlie Marsh
parent bd09a1819f
commit 0bab642f5a
1 changed files with 18 additions and 6 deletions

View File

@ -94,15 +94,16 @@ At time of writing, the repository includes the following crates:
At a high level, the steps involved in adding a new lint rule are as follows: At a high level, the steps involved in adding a new lint rule are as follows:
1. Create a file for your rule (e.g., `crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs`). 1. Determine a name for the new rule as per our [rule naming convention](#rule-naming-convention).
2. In that file, define a violation struct. You can grep for `define_violation!` to see examples. 2. Create a file for your rule (e.g., `crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs`).
3. Map the violation struct to a rule code in `crates/ruff/src/registry.rs` (e.g., `E402`). 3. In that file, define a violation struct. You can grep for `define_violation!` to see examples.
4. Define the logic for triggering the violation in `crates/ruff/src/checkers/ast.rs` (for AST-based 4. Map the violation struct to a rule code in `crates/ruff/src/registry.rs` (e.g., `E402`).
5. Define the logic for triggering the violation in `crates/ruff/src/checkers/ast.rs` (for AST-based
checks), `crates/ruff/src/checkers/tokens.rs` (for token-based checks), `crates/ruff/src/checkers/lines.rs` checks), `crates/ruff/src/checkers/tokens.rs` (for token-based checks), `crates/ruff/src/checkers/lines.rs`
(for text-based checks), or `crates/ruff/src/checkers/filesystem.rs` (for filesystem-based (for text-based checks), or `crates/ruff/src/checkers/filesystem.rs` (for filesystem-based
checks). checks).
5. Add a test fixture. 6. Add a test fixture.
6. Update the generated files (documentation and generated code). 7. Update the generated files (documentation and generated code).
To define the violation, start by creating a dedicated file for your rule under the appropriate To define the violation, start by creating a dedicated file for your rule under the appropriate
rule linter (e.g., `crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs`). That file should rule linter (e.g., `crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs`). That file should
@ -132,6 +133,17 @@ generated snapshot, then commit the snapshot file alongside the rest of your cha
Finally, regenerate the documentation and generated code with `cargo dev generate-all`. Finally, regenerate the documentation and generated code with `cargo dev generate-all`.
#### Rule naming convention
The rule name should make sense when read as "allow *rule-name*" or "allow *rule-name* items".
This implies that rule names:
* should state the bad thing being checked for
* should not contain instructions on what you what you should use instead
(these belong in the rule documentation and the `autofix_title` for rules that have autofix)
### Example: Adding a new configuration option ### Example: Adding a new configuration option
Ruff's user-facing settings live in a few different places. Ruff's user-facing settings live in a few different places.