Skip to content

Commit e9412c9

Browse files
Generate a list of supported lint rules (#93)
1 parent 94faa7f commit e9412c9

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ OPTIONS:
106106
-w, --watch Run in watch mode by re-running whenever files change
107107
```
108108

109+
## Rules
110+
111+
| Code | Name | Message |
112+
| ---- | ----- | ------- |
113+
| E501 | LineTooLong | Line too long |
114+
| F401 | UnusedImport | `...` imported but unused |
115+
| F403 | ImportStarUsage | Unable to detect undefined names |
116+
| F541 | FStringMissingPlaceholders | f-string without any placeholders |
117+
| F634 | IfTuple | If test is a tuple, which is always `True` |
118+
| F704 | YieldOutsideFunction | a `yield` or `yield from` statement outside of a function/method |
119+
| F706 | ReturnOutsideFunction | a `return` statement outside of a function/method |
120+
| F821 | UndefinedName | Undefined name `...` |
121+
| F823 | UndefinedLocal | Local variable `...` referenced before assignment |
122+
| F831 | DuplicateArgumentName | Duplicate argument name in function definition |
123+
| F841 | UnusedVariable | Local variable `...` is assigned to but never used |
124+
| F901 | RaiseNotImplemented | 'raise NotImplemented' should be 'raise NotImplementedError |
125+
| R0205 | UselessObjectInheritance | Class ... inherits from object |
126+
109127
## Development
110128

111129
ruff is written in Rust (1.63.0). You'll need to install the [Rust toolchain](https://www.rust-lang.org/tools/install)

examples/generate_rules_table.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// Generate a Markdown-compatible table of supported lint rules.
2+
use ruff::checks::CheckKind;
3+
4+
fn main() {
5+
let mut check_kinds: Vec<CheckKind> = vec![
6+
CheckKind::DuplicateArgumentName,
7+
CheckKind::FStringMissingPlaceholders,
8+
CheckKind::IfTuple,
9+
CheckKind::ImportStarUsage,
10+
CheckKind::LineTooLong,
11+
CheckKind::RaiseNotImplemented,
12+
CheckKind::ReturnOutsideFunction,
13+
CheckKind::UndefinedLocal("...".to_string()),
14+
CheckKind::UndefinedName("...".to_string()),
15+
CheckKind::UnusedImport("...".to_string()),
16+
CheckKind::UnusedVariable("...".to_string()),
17+
CheckKind::UselessObjectInheritance("...".to_string()),
18+
CheckKind::YieldOutsideFunction,
19+
];
20+
check_kinds.sort_by_key(|check_kind| check_kind.code());
21+
22+
println!("| Code | Name | Message |");
23+
println!("| ---- | ----- | ------- |");
24+
for check_kind in check_kinds {
25+
println!(
26+
"| {} | {} | {} |",
27+
check_kind.code().as_str(),
28+
check_kind.name(),
29+
check_kind.body()
30+
);
31+
}
32+
}

src/checks.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ pub enum CheckKind {
109109
}
110110

111111
impl CheckKind {
112+
/// The name of the check.
113+
pub fn name(&self) -> &'static str {
114+
match self {
115+
CheckKind::DuplicateArgumentName => "DuplicateArgumentName",
116+
CheckKind::FStringMissingPlaceholders => "FStringMissingPlaceholders",
117+
CheckKind::IfTuple => "IfTuple",
118+
CheckKind::ImportStarUsage => "ImportStarUsage",
119+
CheckKind::LineTooLong => "LineTooLong",
120+
CheckKind::RaiseNotImplemented => "RaiseNotImplemented",
121+
CheckKind::ReturnOutsideFunction => "ReturnOutsideFunction",
122+
CheckKind::UndefinedLocal(_) => "UndefinedLocal",
123+
CheckKind::UndefinedName(_) => "UndefinedName",
124+
CheckKind::UnusedImport(_) => "UnusedImport",
125+
CheckKind::UnusedVariable(_) => "UnusedVariable",
126+
CheckKind::UselessObjectInheritance(_) => "UselessObjectInheritance",
127+
CheckKind::YieldOutsideFunction => "YieldOutsideFunction",
128+
}
129+
}
130+
112131
/// A four-letter shorthand code for the check.
113132
pub fn code(&self) -> &'static CheckCode {
114133
match self {

0 commit comments

Comments
 (0)