mirror of https://github.com/astral-sh/ruff
Add autofix and default status to README (#322)
This commit is contained in:
parent
2449771d2f
commit
295ff8eb1a
110
README.md
110
README.md
|
|
@ -222,59 +222,63 @@ Beyond rule-set parity, ruff suffers from the following limitations vis-à-vis F
|
||||||
|
|
||||||
## Rules
|
## Rules
|
||||||
|
|
||||||
| Code | Name | Message |
|
The ✅ emoji indicates a rule is enabled by default.
|
||||||
| ---- | ----- | ------- |
|
|
||||||
| E402 | ModuleImportNotAtTopOfFile | Module level import not at top of file |
|
The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` command-line option.
|
||||||
| E501 | LineTooLong | Line too long (89 > 88 characters) |
|
|
||||||
| E711 | NoneComparison | Comparison to `None` should be `cond is None` |
|
| Code | Name | Message | | |
|
||||||
| E712 | TrueFalseComparison | Comparison to `True` should be `cond is True` |
|
| ---- | ---- | ------- | --- | --- |
|
||||||
| E713 | NotInTest | Test for membership should be `not in` |
|
| E402 | ModuleImportNotAtTopOfFile | Module level import not at top of file | ✅ | |
|
||||||
| E714 | NotIsTest | Test for object identity should be `is not` |
|
| E501 | LineTooLong | Line too long (89 > 88 characters) | ✅ | |
|
||||||
| E721 | TypeComparison | do not compare types, use `isinstance()` |
|
| E711 | NoneComparison | Comparison to `None` should be `cond is None` | ✅ | |
|
||||||
| E722 | DoNotUseBareExcept | Do not use bare `except` |
|
| E712 | TrueFalseComparison | Comparison to `True` should be `cond is True` | ✅ | |
|
||||||
| E731 | DoNotAssignLambda | Do not assign a lambda expression, use a def |
|
| E713 | NotInTest | Test for membership should be `not in` | ✅ | |
|
||||||
| E741 | AmbiguousVariableName | ambiguous variable name '...' |
|
| E714 | NotIsTest | Test for object identity should be `is not` | ✅ | |
|
||||||
| E742 | AmbiguousClassName | ambiguous class name '...' |
|
| E721 | TypeComparison | Do not compare types, use `isinstance()` | ✅ | |
|
||||||
| E743 | AmbiguousFunctionName | ambiguous function name '...' |
|
| E722 | DoNotUseBareExcept | Do not use bare `except` | ✅ | |
|
||||||
| E902 | IOError | ... |
|
| E731 | DoNotAssignLambda | Do not assign a lambda expression, use a def | ✅ | |
|
||||||
| E999 | SyntaxError | SyntaxError: ... |
|
| E741 | AmbiguousVariableName | Ambiguous variable name: `...` | ✅ | |
|
||||||
| F401 | UnusedImport | `...` imported but unused |
|
| E742 | AmbiguousClassName | Ambiguous class name: `...` | ✅ | |
|
||||||
| F402 | ImportShadowedByLoopVar | import '...' from line 1 shadowed by loop variable |
|
| E743 | AmbiguousFunctionName | Ambiguous function name: `...` | ✅ | |
|
||||||
| F403 | ImportStarUsed | `from ... import *` used; unable to detect undefined names |
|
| E902 | IOError | IOError: `...` | ✅ | |
|
||||||
| F404 | LateFutureImport | from __future__ imports must occur at the beginning of the file |
|
| E999 | SyntaxError | SyntaxError: `...` | ✅ | |
|
||||||
| F405 | ImportStarUsage | '...' may be undefined, or defined from star imports: ... |
|
| F401 | UnusedImport | `...` imported but unused | ✅ | 🛠 |
|
||||||
| F406 | ImportStarNotPermitted | `from ... import *` only allowed at module level |
|
| F402 | ImportShadowedByLoopVar | Import `...` from line 1 shadowed by loop variable | ✅ | |
|
||||||
| F407 | FutureFeatureNotDefined | future feature '...' is not defined |
|
| F403 | ImportStarUsed | `from ... import *` used; unable to detect undefined names | ✅ | |
|
||||||
| F541 | FStringMissingPlaceholders | f-string without any placeholders |
|
| F404 | LateFutureImport | `from __future__` imports must occur at the beginning of the file | ✅ | |
|
||||||
| F601 | MultiValueRepeatedKeyLiteral | Dictionary key literal repeated |
|
| F405 | ImportStarUsage | `...` may be undefined, or defined from star imports: `...` | ✅ | |
|
||||||
| F602 | MultiValueRepeatedKeyVariable | Dictionary key `...` repeated |
|
| F406 | ImportStarNotPermitted | `from ... import *` only allowed at module level | ✅ | |
|
||||||
| F621 | TooManyExpressionsInStarredAssignment | too many expressions in star-unpacking assignment |
|
| F407 | FutureFeatureNotDefined | Future feature `...` is not defined | ✅ | |
|
||||||
| F622 | TwoStarredExpressions | two starred expressions in assignment |
|
| F541 | FStringMissingPlaceholders | f-string without any placeholders | ✅ | |
|
||||||
| F631 | AssertTuple | Assert test is a non-empty tuple, which is always `True` |
|
| F601 | MultiValueRepeatedKeyLiteral | Dictionary key literal repeated | ✅ | |
|
||||||
| F632 | IsLiteral | use ==/!= to compare constant literals |
|
| F602 | MultiValueRepeatedKeyVariable | Dictionary key `...` repeated | ✅ | |
|
||||||
| F633 | InvalidPrintSyntax | use of >> is invalid with print function |
|
| F621 | ExpressionsInStarAssignment | Too many expressions in star-unpacking assignment | ✅ | |
|
||||||
| F634 | IfTuple | If test is a tuple, which is always `True` |
|
| F622 | TwoStarredExpressions | Two starred expressions in assignment | ✅ | |
|
||||||
| F701 | BreakOutsideLoop | `break` outside loop |
|
| F631 | AssertTuple | Assert test is a non-empty tuple, which is always `True` | ✅ | |
|
||||||
| F702 | ContinueOutsideLoop | `continue` not properly in loop |
|
| F632 | IsLiteral | Use `==` and `!=` to compare constant literals | ✅ | |
|
||||||
| F704 | YieldOutsideFunction | a `yield` or `yield from` statement outside of a function/method |
|
| F633 | InvalidPrintSyntax | Use of `>>` is invalid with `print` function | ✅ | |
|
||||||
| F706 | ReturnOutsideFunction | a `return` statement outside of a function/method |
|
| F634 | IfTuple | If test is a tuple, which is always `True` | ✅ | |
|
||||||
| F707 | DefaultExceptNotLast | an `except:` block as not the last exception handler |
|
| F701 | BreakOutsideLoop | `break` outside loop | ✅ | |
|
||||||
| F722 | ForwardAnnotationSyntaxError | syntax error in forward annotation '...' |
|
| F702 | ContinueOutsideLoop | `continue` not properly in loop | ✅ | |
|
||||||
| F821 | UndefinedName | Undefined name `...` |
|
| F704 | YieldOutsideFunction | `yield` or `yield from` statement outside of a function/method | ✅ | |
|
||||||
| F822 | UndefinedExport | Undefined name `...` in `__all__` |
|
| F706 | ReturnOutsideFunction | `return` statement outside of a function/method | ✅ | |
|
||||||
| F823 | UndefinedLocal | Local variable `...` referenced before assignment |
|
| F707 | DefaultExceptNotLast | An `except:` block as not the last exception handler | ✅ | |
|
||||||
| F831 | DuplicateArgumentName | Duplicate argument name in function definition |
|
| F722 | ForwardAnnotationSyntaxError | Syntax error in forward annotation: `...` | ✅ | |
|
||||||
| F841 | UnusedVariable | Local variable `...` is assigned to but never used |
|
| F821 | UndefinedName | Undefined name `...` | ✅ | |
|
||||||
| F901 | RaiseNotImplemented | `raise NotImplemented` should be `raise NotImplementedError` |
|
| F822 | UndefinedExport | Undefined name `...` in `__all__` | ✅ | |
|
||||||
| A001 | BuiltinVariableShadowing | Variable `...` is shadowing a python builtin |
|
| F823 | UndefinedLocal | Local variable `...` referenced before assignment | ✅ | |
|
||||||
| A002 | BuiltinArgumentShadowing | Argument `...` is shadowing a python builtin |
|
| F831 | DuplicateArgumentName | Duplicate argument name in function definition | ✅ | |
|
||||||
| A003 | BuiltinAttributeShadowing | class attribute `...` is shadowing a python builtin |
|
| F841 | UnusedVariable | Local variable `...` is assigned to but never used | ✅ | |
|
||||||
| SPR001 | SuperCallWithParameters | Use `super()` instead of `super(__class__, self)` |
|
| F901 | RaiseNotImplemented | `raise NotImplemented` should be `raise NotImplementedError` | ✅ | |
|
||||||
| T201 | PrintFound | `print` found |
|
| A001 | BuiltinVariableShadowing | Variable `...` is shadowing a python builtin | | |
|
||||||
| T203 | PPrintFound | `pprint` found` |
|
| A002 | BuiltinArgumentShadowing | Argument `...` is shadowing a python builtin | | |
|
||||||
| R001 | UselessObjectInheritance | Class `...` inherits from object |
|
| A003 | BuiltinAttributeShadowing | Class attribute `...` is shadowing a python builtin | | |
|
||||||
| R002 | NoAssertEquals | `assertEquals` is deprecated, use `assertEqual` instead |
|
| SPR001 | SuperCallWithParameters | Use `super()` instead of `super(__class__, self)` | | 🛠 |
|
||||||
| M001 | UnusedNOQA | Unused `noqa` directive |
|
| T201 | PrintFound | `print` found | | 🛠 |
|
||||||
|
| T203 | PPrintFound | `pprint` found | | 🛠 |
|
||||||
|
| R001 | UselessObjectInheritance | Class `...` inherits from object | | 🛠 |
|
||||||
|
| R002 | NoAssertEquals | `assertEquals` is deprecated, use `assertEqual` instead | | 🛠 |
|
||||||
|
| M001 | UnusedNOQA | Unused `noqa` directive | | 🛠 |
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,27 @@
|
||||||
/// Generate a Markdown-compatible table of supported lint rules.
|
/// Generate a Markdown-compatible table of supported lint rules.
|
||||||
use ruff::checks::{CheckCode, ALL_CHECK_CODES};
|
use ruff::checks::{CheckCode, ALL_CHECK_CODES, DEFAULT_CHECK_CODES};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut check_codes: Vec<CheckCode> = ALL_CHECK_CODES.to_vec();
|
let mut check_codes: Vec<CheckCode> = ALL_CHECK_CODES.to_vec();
|
||||||
check_codes.sort();
|
check_codes.sort();
|
||||||
|
|
||||||
println!("| Code | Name | Message |");
|
println!("| Code | Name | Message | | |");
|
||||||
println!("| ---- | ----- | ------- |");
|
println!("| ---- | ---- | ------- | --- | --- |");
|
||||||
for check_code in check_codes {
|
for check_code in check_codes {
|
||||||
let check_kind = check_code.kind();
|
let check_kind = check_code.kind();
|
||||||
|
let default_token = if DEFAULT_CHECK_CODES.contains(&check_code) {
|
||||||
|
"✅"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
let fix_token = if check_kind.fixable() { "🛠" } else { "" };
|
||||||
println!(
|
println!(
|
||||||
"| {} | {} | {} |",
|
"| {} | {} | {} | {} | {} |",
|
||||||
check_kind.code().as_str(),
|
check_kind.code().as_str(),
|
||||||
check_kind.name(),
|
check_kind.name(),
|
||||||
check_kind.body()
|
check_kind.body(),
|
||||||
|
default_token,
|
||||||
|
fix_token
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -576,10 +576,7 @@ pub fn check_starred_expressions(
|
||||||
if check_too_many_expressions {
|
if check_too_many_expressions {
|
||||||
if let Some(starred_index) = starred_index {
|
if let Some(starred_index) = starred_index {
|
||||||
if starred_index >= 1 << 8 || elts.len() - starred_index > 1 << 24 {
|
if starred_index >= 1 << 8 || elts.len() - starred_index > 1 << 24 {
|
||||||
return Some(Check::new(
|
return Some(Check::new(CheckKind::ExpressionsInStarAssignment, location));
|
||||||
CheckKind::TooManyExpressionsInStarredAssignment,
|
|
||||||
location,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1380,14 +1380,14 @@ impl<'a> Checker<'a> {
|
||||||
let scope = &self.scopes[*scope_index];
|
let scope = &self.scopes[*scope_index];
|
||||||
for (name, binding) in scope.values.iter() {
|
for (name, binding) in scope.values.iter() {
|
||||||
if matches!(binding.kind, BindingKind::StarImportation) {
|
if matches!(binding.kind, BindingKind::StarImportation) {
|
||||||
from_list.push(name.as_str());
|
from_list.push(name.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
from_list.sort();
|
from_list.sort();
|
||||||
|
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportStarUsage(id.clone(), from_list.join(", ")),
|
CheckKind::ImportStarUsage(id.clone(), from_list),
|
||||||
self.locate_check(Range::from_located(expr)),
|
self.locate_check(Range::from_located(expr)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
@ -1645,7 +1645,7 @@ impl<'a> Checker<'a> {
|
||||||
let mut from_list = vec![];
|
let mut from_list = vec![];
|
||||||
for (name, binding) in scope.values.iter() {
|
for (name, binding) in scope.values.iter() {
|
||||||
if matches!(binding.kind, BindingKind::StarImportation) {
|
if matches!(binding.kind, BindingKind::StarImportation) {
|
||||||
from_list.push(name.as_str());
|
from_list.push(name.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
from_list.sort();
|
from_list.sort();
|
||||||
|
|
@ -1653,7 +1653,7 @@ impl<'a> Checker<'a> {
|
||||||
for name in names {
|
for name in names {
|
||||||
if !scope.values.contains_key(name) {
|
if !scope.values.contains_key(name) {
|
||||||
self.checks.push(Check::new(
|
self.checks.push(Check::new(
|
||||||
CheckKind::ImportStarUsage(name.clone(), from_list.join(", ")),
|
CheckKind::ImportStarUsage(name.clone(), from_list.clone()),
|
||||||
self.locate_check(all_binding.range),
|
self.locate_check(all_binding.range),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use std::str::FromStr;
|
||||||
|
|
||||||
use crate::ast::types::Range;
|
use crate::ast::types::Range;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use itertools::Itertools;
|
||||||
use rustpython_parser::ast::Location;
|
use rustpython_parser::ast::Location;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
@ -329,20 +330,22 @@ impl CheckCode {
|
||||||
CheckCode::E741 => CheckKind::AmbiguousVariableName("...".to_string()),
|
CheckCode::E741 => CheckKind::AmbiguousVariableName("...".to_string()),
|
||||||
CheckCode::E742 => CheckKind::AmbiguousClassName("...".to_string()),
|
CheckCode::E742 => CheckKind::AmbiguousClassName("...".to_string()),
|
||||||
CheckCode::E743 => CheckKind::AmbiguousFunctionName("...".to_string()),
|
CheckCode::E743 => CheckKind::AmbiguousFunctionName("...".to_string()),
|
||||||
CheckCode::E902 => CheckKind::IOError("...".to_string()),
|
CheckCode::E902 => CheckKind::IOError("IOError: `...`".to_string()),
|
||||||
CheckCode::E999 => CheckKind::SyntaxError("...".to_string()),
|
CheckCode::E999 => CheckKind::SyntaxError("`...`".to_string()),
|
||||||
// pyflakes
|
// pyflakes
|
||||||
CheckCode::F401 => CheckKind::UnusedImport("...".to_string()),
|
CheckCode::F401 => CheckKind::UnusedImport("...".to_string()),
|
||||||
CheckCode::F402 => CheckKind::ImportShadowedByLoopVar("...".to_string(), 1),
|
CheckCode::F402 => CheckKind::ImportShadowedByLoopVar("...".to_string(), 1),
|
||||||
CheckCode::F403 => CheckKind::ImportStarUsed("...".to_string()),
|
CheckCode::F403 => CheckKind::ImportStarUsed("...".to_string()),
|
||||||
CheckCode::F404 => CheckKind::LateFutureImport,
|
CheckCode::F404 => CheckKind::LateFutureImport,
|
||||||
CheckCode::F405 => CheckKind::ImportStarUsage("...".to_string(), "...".to_string()),
|
CheckCode::F405 => {
|
||||||
|
CheckKind::ImportStarUsage("...".to_string(), vec!["...".to_string()])
|
||||||
|
}
|
||||||
CheckCode::F406 => CheckKind::ImportStarNotPermitted("...".to_string()),
|
CheckCode::F406 => CheckKind::ImportStarNotPermitted("...".to_string()),
|
||||||
CheckCode::F407 => CheckKind::FutureFeatureNotDefined("...".to_string()),
|
CheckCode::F407 => CheckKind::FutureFeatureNotDefined("...".to_string()),
|
||||||
CheckCode::F541 => CheckKind::FStringMissingPlaceholders,
|
CheckCode::F541 => CheckKind::FStringMissingPlaceholders,
|
||||||
CheckCode::F601 => CheckKind::MultiValueRepeatedKeyLiteral,
|
CheckCode::F601 => CheckKind::MultiValueRepeatedKeyLiteral,
|
||||||
CheckCode::F602 => CheckKind::MultiValueRepeatedKeyVariable("...".to_string()),
|
CheckCode::F602 => CheckKind::MultiValueRepeatedKeyVariable("...".to_string()),
|
||||||
CheckCode::F621 => CheckKind::TooManyExpressionsInStarredAssignment,
|
CheckCode::F621 => CheckKind::ExpressionsInStarAssignment,
|
||||||
CheckCode::F622 => CheckKind::TwoStarredExpressions,
|
CheckCode::F622 => CheckKind::TwoStarredExpressions,
|
||||||
CheckCode::F631 => CheckKind::AssertTuple,
|
CheckCode::F631 => CheckKind::AssertTuple,
|
||||||
CheckCode::F632 => CheckKind::IsLiteral,
|
CheckCode::F632 => CheckKind::IsLiteral,
|
||||||
|
|
@ -393,7 +396,6 @@ pub enum RejectedCmpop {
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum CheckKind {
|
pub enum CheckKind {
|
||||||
UnusedNOQA(Option<String>),
|
|
||||||
AmbiguousClassName(String),
|
AmbiguousClassName(String),
|
||||||
AmbiguousFunctionName(String),
|
AmbiguousFunctionName(String),
|
||||||
AmbiguousVariableName(String),
|
AmbiguousVariableName(String),
|
||||||
|
|
@ -404,14 +406,15 @@ pub enum CheckKind {
|
||||||
DoNotAssignLambda,
|
DoNotAssignLambda,
|
||||||
DoNotUseBareExcept,
|
DoNotUseBareExcept,
|
||||||
DuplicateArgumentName,
|
DuplicateArgumentName,
|
||||||
ForwardAnnotationSyntaxError(String),
|
ExpressionsInStarAssignment,
|
||||||
FStringMissingPlaceholders,
|
FStringMissingPlaceholders,
|
||||||
|
ForwardAnnotationSyntaxError(String),
|
||||||
FutureFeatureNotDefined(String),
|
FutureFeatureNotDefined(String),
|
||||||
IOError(String),
|
IOError(String),
|
||||||
IfTuple,
|
IfTuple,
|
||||||
ImportShadowedByLoopVar(String, usize),
|
ImportShadowedByLoopVar(String, usize),
|
||||||
ImportStarNotPermitted(String),
|
ImportStarNotPermitted(String),
|
||||||
ImportStarUsage(String, String),
|
ImportStarUsage(String, Vec<String>),
|
||||||
ImportStarUsed(String),
|
ImportStarUsed(String),
|
||||||
InvalidPrintSyntax,
|
InvalidPrintSyntax,
|
||||||
IsLiteral,
|
IsLiteral,
|
||||||
|
|
@ -427,7 +430,6 @@ pub enum CheckKind {
|
||||||
RaiseNotImplemented,
|
RaiseNotImplemented,
|
||||||
ReturnOutsideFunction,
|
ReturnOutsideFunction,
|
||||||
SyntaxError(String),
|
SyntaxError(String),
|
||||||
TooManyExpressionsInStarredAssignment,
|
|
||||||
TrueFalseComparison(bool, RejectedCmpop),
|
TrueFalseComparison(bool, RejectedCmpop),
|
||||||
TwoStarredExpressions,
|
TwoStarredExpressions,
|
||||||
TypeComparison,
|
TypeComparison,
|
||||||
|
|
@ -435,6 +437,7 @@ pub enum CheckKind {
|
||||||
UndefinedLocal(String),
|
UndefinedLocal(String),
|
||||||
UndefinedName(String),
|
UndefinedName(String),
|
||||||
UnusedImport(String),
|
UnusedImport(String),
|
||||||
|
UnusedNOQA(Option<String>),
|
||||||
UnusedVariable(String),
|
UnusedVariable(String),
|
||||||
UselessObjectInheritance(String),
|
UselessObjectInheritance(String),
|
||||||
YieldOutsideFunction,
|
YieldOutsideFunction,
|
||||||
|
|
@ -463,6 +466,7 @@ impl CheckKind {
|
||||||
CheckKind::DoNotAssignLambda => "DoNotAssignLambda",
|
CheckKind::DoNotAssignLambda => "DoNotAssignLambda",
|
||||||
CheckKind::DoNotUseBareExcept => "DoNotUseBareExcept",
|
CheckKind::DoNotUseBareExcept => "DoNotUseBareExcept",
|
||||||
CheckKind::DuplicateArgumentName => "DuplicateArgumentName",
|
CheckKind::DuplicateArgumentName => "DuplicateArgumentName",
|
||||||
|
CheckKind::ExpressionsInStarAssignment => "ExpressionsInStarAssignment",
|
||||||
CheckKind::FStringMissingPlaceholders => "FStringMissingPlaceholders",
|
CheckKind::FStringMissingPlaceholders => "FStringMissingPlaceholders",
|
||||||
CheckKind::ForwardAnnotationSyntaxError(_) => "ForwardAnnotationSyntaxError",
|
CheckKind::ForwardAnnotationSyntaxError(_) => "ForwardAnnotationSyntaxError",
|
||||||
CheckKind::FutureFeatureNotDefined(_) => "FutureFeatureNotDefined",
|
CheckKind::FutureFeatureNotDefined(_) => "FutureFeatureNotDefined",
|
||||||
|
|
@ -486,9 +490,6 @@ impl CheckKind {
|
||||||
CheckKind::RaiseNotImplemented => "RaiseNotImplemented",
|
CheckKind::RaiseNotImplemented => "RaiseNotImplemented",
|
||||||
CheckKind::ReturnOutsideFunction => "ReturnOutsideFunction",
|
CheckKind::ReturnOutsideFunction => "ReturnOutsideFunction",
|
||||||
CheckKind::SyntaxError(_) => "SyntaxError",
|
CheckKind::SyntaxError(_) => "SyntaxError",
|
||||||
CheckKind::TooManyExpressionsInStarredAssignment => {
|
|
||||||
"TooManyExpressionsInStarredAssignment"
|
|
||||||
}
|
|
||||||
CheckKind::TrueFalseComparison(_, _) => "TrueFalseComparison",
|
CheckKind::TrueFalseComparison(_, _) => "TrueFalseComparison",
|
||||||
CheckKind::TwoStarredExpressions => "TwoStarredExpressions",
|
CheckKind::TwoStarredExpressions => "TwoStarredExpressions",
|
||||||
CheckKind::TypeComparison => "TypeComparison",
|
CheckKind::TypeComparison => "TypeComparison",
|
||||||
|
|
@ -496,10 +497,10 @@ impl CheckKind {
|
||||||
CheckKind::UndefinedLocal(_) => "UndefinedLocal",
|
CheckKind::UndefinedLocal(_) => "UndefinedLocal",
|
||||||
CheckKind::UndefinedName(_) => "UndefinedName",
|
CheckKind::UndefinedName(_) => "UndefinedName",
|
||||||
CheckKind::UnusedImport(_) => "UnusedImport",
|
CheckKind::UnusedImport(_) => "UnusedImport",
|
||||||
|
CheckKind::UnusedNOQA(_) => "UnusedNOQA",
|
||||||
CheckKind::UnusedVariable(_) => "UnusedVariable",
|
CheckKind::UnusedVariable(_) => "UnusedVariable",
|
||||||
CheckKind::UselessObjectInheritance(_) => "UselessObjectInheritance",
|
CheckKind::UselessObjectInheritance(_) => "UselessObjectInheritance",
|
||||||
CheckKind::YieldOutsideFunction => "YieldOutsideFunction",
|
CheckKind::YieldOutsideFunction => "YieldOutsideFunction",
|
||||||
CheckKind::UnusedNOQA(_) => "UnusedNOQA",
|
|
||||||
// flake8-builtins
|
// flake8-builtins
|
||||||
CheckKind::BuiltinVariableShadowing(_) => "BuiltinVariableShadowing",
|
CheckKind::BuiltinVariableShadowing(_) => "BuiltinVariableShadowing",
|
||||||
CheckKind::BuiltinArgumentShadowing(_) => "BuiltinArgumentShadowing",
|
CheckKind::BuiltinArgumentShadowing(_) => "BuiltinArgumentShadowing",
|
||||||
|
|
@ -548,7 +549,7 @@ impl CheckKind {
|
||||||
CheckKind::RaiseNotImplemented => &CheckCode::F901,
|
CheckKind::RaiseNotImplemented => &CheckCode::F901,
|
||||||
CheckKind::ReturnOutsideFunction => &CheckCode::F706,
|
CheckKind::ReturnOutsideFunction => &CheckCode::F706,
|
||||||
CheckKind::SyntaxError(_) => &CheckCode::E999,
|
CheckKind::SyntaxError(_) => &CheckCode::E999,
|
||||||
CheckKind::TooManyExpressionsInStarredAssignment => &CheckCode::F621,
|
CheckKind::ExpressionsInStarAssignment => &CheckCode::F621,
|
||||||
CheckKind::TrueFalseComparison(_, _) => &CheckCode::E712,
|
CheckKind::TrueFalseComparison(_, _) => &CheckCode::E712,
|
||||||
CheckKind::TwoStarredExpressions => &CheckCode::F622,
|
CheckKind::TwoStarredExpressions => &CheckCode::F622,
|
||||||
CheckKind::TypeComparison => &CheckCode::E721,
|
CheckKind::TypeComparison => &CheckCode::E721,
|
||||||
|
|
@ -576,13 +577,13 @@ impl CheckKind {
|
||||||
pub fn body(&self) -> String {
|
pub fn body(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
CheckKind::AmbiguousClassName(name) => {
|
CheckKind::AmbiguousClassName(name) => {
|
||||||
format!("ambiguous class name '{}'", name)
|
format!("Ambiguous class name: `{}`", name)
|
||||||
}
|
}
|
||||||
CheckKind::AmbiguousFunctionName(name) => {
|
CheckKind::AmbiguousFunctionName(name) => {
|
||||||
format!("ambiguous function name '{}'", name)
|
format!("Ambiguous function name: `{}`", name)
|
||||||
}
|
}
|
||||||
CheckKind::AmbiguousVariableName(name) => {
|
CheckKind::AmbiguousVariableName(name) => {
|
||||||
format!("ambiguous variable name '{}'", name)
|
format!("Ambiguous variable name: `{}`", name)
|
||||||
}
|
}
|
||||||
CheckKind::AssertTuple => {
|
CheckKind::AssertTuple => {
|
||||||
"Assert test is a non-empty tuple, which is always `True`".to_string()
|
"Assert test is a non-empty tuple, which is always `True`".to_string()
|
||||||
|
|
@ -590,7 +591,7 @@ impl CheckKind {
|
||||||
CheckKind::BreakOutsideLoop => "`break` outside loop".to_string(),
|
CheckKind::BreakOutsideLoop => "`break` outside loop".to_string(),
|
||||||
CheckKind::ContinueOutsideLoop => "`continue` not properly in loop".to_string(),
|
CheckKind::ContinueOutsideLoop => "`continue` not properly in loop".to_string(),
|
||||||
CheckKind::DefaultExceptNotLast => {
|
CheckKind::DefaultExceptNotLast => {
|
||||||
"an `except:` block as not the last exception handler".to_string()
|
"An `except:` block as not the last exception handler".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::DoNotAssignLambda => {
|
CheckKind::DoNotAssignLambda => {
|
||||||
"Do not assign a lambda expression, use a def".to_string()
|
"Do not assign a lambda expression, use a def".to_string()
|
||||||
|
|
@ -600,19 +601,21 @@ impl CheckKind {
|
||||||
"Duplicate argument name in function definition".to_string()
|
"Duplicate argument name in function definition".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::ForwardAnnotationSyntaxError(body) => {
|
CheckKind::ForwardAnnotationSyntaxError(body) => {
|
||||||
format!("syntax error in forward annotation '{body}'")
|
format!("Syntax error in forward annotation: `{body}`")
|
||||||
}
|
}
|
||||||
CheckKind::FStringMissingPlaceholders => {
|
CheckKind::FStringMissingPlaceholders => {
|
||||||
"f-string without any placeholders".to_string()
|
"f-string without any placeholders".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::FutureFeatureNotDefined(name) => {
|
CheckKind::FutureFeatureNotDefined(name) => {
|
||||||
format!("future feature '{name}' is not defined")
|
format!("Future feature `{name}` is not defined")
|
||||||
}
|
}
|
||||||
CheckKind::IOError(message) => message.clone(),
|
CheckKind::IOError(message) => message.clone(),
|
||||||
CheckKind::IfTuple => "If test is a tuple, which is always `True`".to_string(),
|
CheckKind::IfTuple => "If test is a tuple, which is always `True`".to_string(),
|
||||||
CheckKind::InvalidPrintSyntax => "use of >> is invalid with print function".to_string(),
|
CheckKind::InvalidPrintSyntax => {
|
||||||
|
"Use of `>>` is invalid with `print` function".to_string()
|
||||||
|
}
|
||||||
CheckKind::ImportShadowedByLoopVar(name, line) => {
|
CheckKind::ImportShadowedByLoopVar(name, line) => {
|
||||||
format!("import '{name}' from line {line} shadowed by loop variable")
|
format!("Import `{name}` from line {line} shadowed by loop variable")
|
||||||
}
|
}
|
||||||
CheckKind::ImportStarNotPermitted(name) => {
|
CheckKind::ImportStarNotPermitted(name) => {
|
||||||
format!("`from {name} import *` only allowed at module level")
|
format!("`from {name} import *` only allowed at module level")
|
||||||
|
|
@ -621,11 +624,15 @@ impl CheckKind {
|
||||||
format!("`from {name} import *` used; unable to detect undefined names")
|
format!("`from {name} import *` used; unable to detect undefined names")
|
||||||
}
|
}
|
||||||
CheckKind::ImportStarUsage(name, sources) => {
|
CheckKind::ImportStarUsage(name, sources) => {
|
||||||
format!("'{name}' may be undefined, or defined from star imports: {sources}")
|
let sources = sources
|
||||||
|
.iter()
|
||||||
|
.map(|source| format!("`{}`", source))
|
||||||
|
.join(", ");
|
||||||
|
format!("`{name}` may be undefined, or defined from star imports: {sources}")
|
||||||
}
|
}
|
||||||
CheckKind::IsLiteral => "use ==/!= to compare constant literals".to_string(),
|
CheckKind::IsLiteral => "Use `==` and `!=` to compare constant literals".to_string(),
|
||||||
CheckKind::LateFutureImport => {
|
CheckKind::LateFutureImport => {
|
||||||
"from __future__ imports must occur at the beginning of the file".to_string()
|
"`from __future__` imports must occur at the beginning of the file".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::LineTooLong(length, limit) => {
|
CheckKind::LineTooLong(length, limit) => {
|
||||||
format!("Line too long ({length} > {limit} characters)")
|
format!("Line too long ({length} > {limit} characters)")
|
||||||
|
|
@ -654,11 +661,11 @@ impl CheckKind {
|
||||||
"`raise NotImplemented` should be `raise NotImplementedError`".to_string()
|
"`raise NotImplemented` should be `raise NotImplementedError`".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::ReturnOutsideFunction => {
|
CheckKind::ReturnOutsideFunction => {
|
||||||
"a `return` statement outside of a function/method".to_string()
|
"`return` statement outside of a function/method".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::SyntaxError(message) => format!("SyntaxError: {message}"),
|
CheckKind::SyntaxError(message) => format!("SyntaxError: {message}"),
|
||||||
CheckKind::TooManyExpressionsInStarredAssignment => {
|
CheckKind::ExpressionsInStarAssignment => {
|
||||||
"too many expressions in star-unpacking assignment".to_string()
|
"Too many expressions in star-unpacking assignment".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::TrueFalseComparison(value, op) => match *value {
|
CheckKind::TrueFalseComparison(value, op) => match *value {
|
||||||
true => match op {
|
true => match op {
|
||||||
|
|
@ -678,8 +685,8 @@ impl CheckKind {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CheckKind::TwoStarredExpressions => "two starred expressions in assignment".to_string(),
|
CheckKind::TwoStarredExpressions => "Two starred expressions in assignment".to_string(),
|
||||||
CheckKind::TypeComparison => "do not compare types, use `isinstance()`".to_string(),
|
CheckKind::TypeComparison => "Do not compare types, use `isinstance()`".to_string(),
|
||||||
CheckKind::UndefinedExport(name) => {
|
CheckKind::UndefinedExport(name) => {
|
||||||
format!("Undefined name `{name}` in `__all__`")
|
format!("Undefined name `{name}` in `__all__`")
|
||||||
}
|
}
|
||||||
|
|
@ -697,7 +704,7 @@ impl CheckKind {
|
||||||
format!("Class `{name}` inherits from object")
|
format!("Class `{name}` inherits from object")
|
||||||
}
|
}
|
||||||
CheckKind::YieldOutsideFunction => {
|
CheckKind::YieldOutsideFunction => {
|
||||||
"a `yield` or `yield from` statement outside of a function/method".to_string()
|
"`yield` or `yield from` statement outside of a function/method".to_string()
|
||||||
}
|
}
|
||||||
CheckKind::UnusedNOQA(code) => match code {
|
CheckKind::UnusedNOQA(code) => match code {
|
||||||
None => "Unused `noqa` directive".to_string(),
|
None => "Unused `noqa` directive".to_string(),
|
||||||
|
|
@ -711,7 +718,7 @@ impl CheckKind {
|
||||||
format!("Argument `{name}` is shadowing a python builtin")
|
format!("Argument `{name}` is shadowing a python builtin")
|
||||||
}
|
}
|
||||||
CheckKind::BuiltinAttributeShadowing(name) => {
|
CheckKind::BuiltinAttributeShadowing(name) => {
|
||||||
format!("class attribute `{name}` is shadowing a python builtin")
|
format!("Class attribute `{name}` is shadowing a python builtin")
|
||||||
}
|
}
|
||||||
// flake8-super
|
// flake8-super
|
||||||
CheckKind::SuperCallWithParameters => {
|
CheckKind::SuperCallWithParameters => {
|
||||||
|
|
@ -719,7 +726,7 @@ impl CheckKind {
|
||||||
}
|
}
|
||||||
// flake8-print
|
// flake8-print
|
||||||
CheckKind::PrintFound => "`print` found".to_string(),
|
CheckKind::PrintFound => "`print` found".to_string(),
|
||||||
CheckKind::PPrintFound => "`pprint` found`".to_string(),
|
CheckKind::PPrintFound => "`pprint` found".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ expression: checks
|
||||||
- kind:
|
- kind:
|
||||||
ImportStarUsage:
|
ImportStarUsage:
|
||||||
- name
|
- name
|
||||||
- mymodule
|
- - mymodule
|
||||||
location:
|
location:
|
||||||
row: 5
|
row: 5
|
||||||
column: 11
|
column: 11
|
||||||
|
|
@ -16,7 +16,7 @@ expression: checks
|
||||||
- kind:
|
- kind:
|
||||||
ImportStarUsage:
|
ImportStarUsage:
|
||||||
- a
|
- a
|
||||||
- mymodule
|
- - mymodule
|
||||||
location:
|
location:
|
||||||
row: 11
|
row: 11
|
||||||
column: 1
|
column: 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue