diff --git a/README.md b/README.md index 327ba93cd2..91ea5cbebf 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,24 @@ OPTIONS: -w, --watch Run in watch mode by re-running whenever files change ``` +## Rules + +| Code | Name | Message | +| ---- | ----- | ------- | +| E501 | LineTooLong | Line too long | +| F401 | UnusedImport | `...` imported but unused | +| F403 | ImportStarUsage | Unable to detect undefined names | +| F541 | FStringMissingPlaceholders | f-string without any placeholders | +| F634 | IfTuple | If test is a tuple, which is always `True` | +| F704 | YieldOutsideFunction | a `yield` or `yield from` statement outside of a function/method | +| F706 | ReturnOutsideFunction | a `return` statement outside of a function/method | +| F821 | UndefinedName | Undefined name `...` | +| F823 | UndefinedLocal | Local variable `...` referenced before assignment | +| F831 | DuplicateArgumentName | Duplicate argument name in function definition | +| F841 | UnusedVariable | Local variable `...` is assigned to but never used | +| F901 | RaiseNotImplemented | 'raise NotImplemented' should be 'raise NotImplementedError | +| R0205 | UselessObjectInheritance | Class ... inherits from object | + ## Development ruff is written in Rust (1.63.0). You'll need to install the [Rust toolchain](https://www.rust-lang.org/tools/install) diff --git a/examples/generate_rules_table.rs b/examples/generate_rules_table.rs new file mode 100644 index 0000000000..5f920d2217 --- /dev/null +++ b/examples/generate_rules_table.rs @@ -0,0 +1,32 @@ +/// Generate a Markdown-compatible table of supported lint rules. +use ruff::checks::CheckKind; + +fn main() { + let mut check_kinds: Vec = vec![ + CheckKind::DuplicateArgumentName, + CheckKind::FStringMissingPlaceholders, + CheckKind::IfTuple, + CheckKind::ImportStarUsage, + CheckKind::LineTooLong, + CheckKind::RaiseNotImplemented, + CheckKind::ReturnOutsideFunction, + CheckKind::UndefinedLocal("...".to_string()), + CheckKind::UndefinedName("...".to_string()), + CheckKind::UnusedImport("...".to_string()), + CheckKind::UnusedVariable("...".to_string()), + CheckKind::UselessObjectInheritance("...".to_string()), + CheckKind::YieldOutsideFunction, + ]; + check_kinds.sort_by_key(|check_kind| check_kind.code()); + + println!("| Code | Name | Message |"); + println!("| ---- | ----- | ------- |"); + for check_kind in check_kinds { + println!( + "| {} | {} | {} |", + check_kind.code().as_str(), + check_kind.name(), + check_kind.body() + ); + } +} diff --git a/src/checks.rs b/src/checks.rs index 2007a6b1cb..0c35052e38 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -109,6 +109,25 @@ pub enum CheckKind { } impl CheckKind { + /// The name of the check. + pub fn name(&self) -> &'static str { + match self { + CheckKind::DuplicateArgumentName => "DuplicateArgumentName", + CheckKind::FStringMissingPlaceholders => "FStringMissingPlaceholders", + CheckKind::IfTuple => "IfTuple", + CheckKind::ImportStarUsage => "ImportStarUsage", + CheckKind::LineTooLong => "LineTooLong", + CheckKind::RaiseNotImplemented => "RaiseNotImplemented", + CheckKind::ReturnOutsideFunction => "ReturnOutsideFunction", + CheckKind::UndefinedLocal(_) => "UndefinedLocal", + CheckKind::UndefinedName(_) => "UndefinedName", + CheckKind::UnusedImport(_) => "UnusedImport", + CheckKind::UnusedVariable(_) => "UnusedVariable", + CheckKind::UselessObjectInheritance(_) => "UselessObjectInheritance", + CheckKind::YieldOutsideFunction => "YieldOutsideFunction", + } + } + /// A four-letter shorthand code for the check. pub fn code(&self) -> &'static CheckCode { match self {