mirror of https://github.com/astral-sh/ruff
Deprecate define violation (#3358)
* Add `#[violation]` proc macro as a replacement for `define_violation!` * Switch all rules to #[violation]
This commit is contained in:
parent
22e6778e17
commit
348a38d261
|
|
@ -104,7 +104,7 @@ At a high level, the steps involved in adding a new lint rule are as follows:
|
|||
|
||||
1. Determine a name for the new rule as per our [rule naming convention](#rule-naming-convention).
|
||||
1. Create a file for your rule (e.g., `crates/ruff/src/rules/flake8_bugbear/rules/abstract_base_class.rs`).
|
||||
1. In that file, define a violation struct. You can grep for `define_violation!` to see examples.
|
||||
1. In that file, define a violation struct. You can grep for `#[violation]` to see examples.
|
||||
1. Map the violation struct to a rule code in `crates/ruff/src/registry.rs` (e.g., `E402`).
|
||||
1. 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`
|
||||
|
|
@ -115,7 +115,7 @@ At a high level, the steps involved in adding a new lint rule are as follows:
|
|||
|
||||
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
|
||||
contain a struct defined via `define_violation!`, along with a function that creates the violation
|
||||
contain a struct defined via `#[violation]`, along with a function that creates the violation
|
||||
based on any required inputs. (Many of the existing examples live in `crates/ruff/src/violations.rs`,
|
||||
but we're looking to place new rules in their own files.)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use super::detection::comment_contains_code;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::settings::{flags, Settings};
|
|||
use crate::source_code::Locator;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for commented-out Python code.
|
||||
///
|
||||
|
|
@ -21,8 +20,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// # print('foo')
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct CommentedOutCode;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for CommentedOutCode {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use num_bigint::BigInt;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Cmpop, Constant, Expr, ExprKind, Located};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -7,9 +7,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::{Diagnostic, Rule};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionSlice3Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionSlice3Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -17,9 +17,9 @@ impl Violation for SysVersionSlice3Referenced {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersion2Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SysVersion2Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -27,9 +27,9 @@ impl Violation for SysVersion2Referenced {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionCmpStr3;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionCmpStr3 {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -37,9 +37,9 @@ impl Violation for SysVersionCmpStr3 {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionInfo0Eq3Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionInfo0Eq3Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -47,9 +47,9 @@ impl Violation for SysVersionInfo0Eq3Referenced {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SixPY3Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SixPY3Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -57,9 +57,9 @@ impl Violation for SixPY3Referenced {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionInfo1CmpInt;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionInfo1CmpInt {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -70,9 +70,9 @@ impl Violation for SysVersionInfo1CmpInt {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionInfoMinorCmpInt;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionInfoMinorCmpInt {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -83,9 +83,9 @@ impl Violation for SysVersionInfoMinorCmpInt {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersion0Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SysVersion0Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -93,9 +93,9 @@ impl Violation for SysVersion0Referenced {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionCmpStr10;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionCmpStr10 {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -103,9 +103,9 @@ impl Violation for SysVersionCmpStr10 {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SysVersionSlice1Referenced;
|
||||
);
|
||||
|
||||
impl Violation for SysVersionSlice1Referenced {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Stmt};
|
||||
|
||||
use super::fixes;
|
||||
|
|
@ -15,7 +15,6 @@ use crate::violation::{AlwaysAutofixableViolation, Violation};
|
|||
use crate::visibility;
|
||||
use crate::visibility::Visibility;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that function arguments have type annotations.
|
||||
///
|
||||
|
|
@ -35,10 +34,11 @@ define_violation!(
|
|||
/// def foo(x: int):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingTypeFunctionArgument {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingTypeFunctionArgument {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -47,7 +47,6 @@ impl Violation for MissingTypeFunctionArgument {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that function `*args` arguments have type annotations.
|
||||
///
|
||||
|
|
@ -67,10 +66,11 @@ define_violation!(
|
|||
/// def foo(*args: int):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingTypeArgs {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingTypeArgs {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -79,7 +79,6 @@ impl Violation for MissingTypeArgs {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that function `**kwargs` arguments have type annotations.
|
||||
///
|
||||
|
|
@ -99,10 +98,11 @@ define_violation!(
|
|||
/// def foo(**kwargs: int):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingTypeKwargs {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingTypeKwargs {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -111,7 +111,6 @@ impl Violation for MissingTypeKwargs {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that instance method `self` arguments have type annotations.
|
||||
///
|
||||
|
|
@ -136,10 +135,11 @@ define_violation!(
|
|||
/// def bar(self: "Foo"):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingTypeSelf {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingTypeSelf {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -148,7 +148,6 @@ impl Violation for MissingTypeSelf {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that class method `cls` arguments have type annotations.
|
||||
///
|
||||
|
|
@ -175,10 +174,11 @@ define_violation!(
|
|||
/// def bar(cls: Type["Foo"]):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingTypeCls {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingTypeCls {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -187,7 +187,6 @@ impl Violation for MissingTypeCls {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that public functions and methods have return type annotations.
|
||||
///
|
||||
|
|
@ -207,10 +206,11 @@ define_violation!(
|
|||
/// def add(a: int, b: int) -> int:
|
||||
/// return a + b
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingReturnTypePublicFunction {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingReturnTypePublicFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -219,7 +219,6 @@ impl Violation for MissingReturnTypePublicFunction {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that private functions and methods have return type annotations.
|
||||
///
|
||||
|
|
@ -239,10 +238,11 @@ define_violation!(
|
|||
/// def _add(a: int, b: int) -> int:
|
||||
/// return a + b
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingReturnTypePrivateFunction {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingReturnTypePrivateFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -251,7 +251,6 @@ impl Violation for MissingReturnTypePrivateFunction {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that "special" methods, like `__init__`, `__new__`, and `__call__`, have
|
||||
/// return type annotations.
|
||||
|
|
@ -284,10 +283,11 @@ define_violation!(
|
|||
/// def __init__(self, x: int) -> None:
|
||||
/// self.x = x
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingReturnTypeSpecialMethod {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for MissingReturnTypeSpecialMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -300,7 +300,6 @@ impl AlwaysAutofixableViolation for MissingReturnTypeSpecialMethod {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that static methods have return type annotations.
|
||||
///
|
||||
|
|
@ -324,10 +323,11 @@ define_violation!(
|
|||
/// def bar() -> int:
|
||||
/// return 1
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingReturnTypeStaticMethod {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingReturnTypeStaticMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -336,7 +336,6 @@ impl Violation for MissingReturnTypeStaticMethod {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that class methods have return type annotations.
|
||||
///
|
||||
|
|
@ -360,10 +359,11 @@ define_violation!(
|
|||
/// def bar(cls) -> int:
|
||||
/// return 1
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct MissingReturnTypeClassMethod {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for MissingReturnTypeClassMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -372,7 +372,6 @@ impl Violation for MissingReturnTypeClassMethod {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that an expression is annotated with a more specific type than
|
||||
/// `Any`.
|
||||
|
|
@ -401,10 +400,11 @@ define_violation!(
|
|||
/// - [PEP 484](https://www.python.org/dev/peps/pep-0484/#the-any-type)
|
||||
/// - [`typing.Any`](https://docs.python.org/3/library/typing.html#typing.Any)
|
||||
/// - [Mypy: The Any type](https://mypy.readthedocs.io/en/stable/kinds_of_types.html#the-any-type)
|
||||
#[violation]
|
||||
pub struct AnyType {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for AnyType {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct Assert;
|
||||
);
|
||||
|
||||
impl Violation for Assert {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use num_traits::ToPrimitive;
|
||||
use once_cell::sync::Lazy;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword, Operator};
|
||||
|
||||
|
|
@ -10,11 +10,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct BadFilePermissions {
|
||||
pub mask: u16,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for BadFilePermissions {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ExecBuiltin;
|
||||
);
|
||||
|
||||
impl Violation for ExecBuiltin {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HardcodedBindAllInterfaces;
|
||||
);
|
||||
|
||||
impl Violation for HardcodedBindAllInterfaces {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Arg, Arguments, Expr};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
|
|
@ -8,11 +8,11 @@ use crate::violation::Violation;
|
|||
|
||||
use super::super::helpers::{matches_password_name, string_literal};
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HardcodedPasswordDefault {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for HardcodedPasswordDefault {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Keyword;
|
||||
|
||||
use super::super::helpers::{matches_password_name, string_literal};
|
||||
|
|
@ -6,11 +6,11 @@ use crate::ast::types::Range;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HardcodedPasswordFuncArg {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for HardcodedPasswordFuncArg {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
||||
|
||||
use super::super::helpers::{matches_password_name, string_literal};
|
||||
|
|
@ -6,11 +6,11 @@ use crate::ast::types::Range;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HardcodedPasswordString {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for HardcodedPasswordString {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Operator};
|
||||
|
||||
use super::super::helpers::string_literal;
|
||||
|
|
@ -15,7 +15,6 @@ static SQL_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||
.unwrap()
|
||||
});
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for strings that resemble SQL statements involved in some form
|
||||
/// string building operation.
|
||||
|
|
@ -35,8 +34,9 @@ define_violation!(
|
|||
/// ## References
|
||||
/// - [B608: Test for SQL injection](https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html)
|
||||
/// - [psycopg3: Server-side binding](https://www.psycopg.org/psycopg3/docs/basic/from_pg2.html#server-side-binding)
|
||||
#[violation]
|
||||
pub struct HardcodedSQLExpression;
|
||||
);
|
||||
|
||||
impl Violation for HardcodedSQLExpression {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Expr;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HardcodedTempFile {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for HardcodedTempFile {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use super::super::helpers::string_literal;
|
||||
|
|
@ -8,11 +8,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct HashlibInsecureHashFunction {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for HashlibInsecureHashFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -7,11 +7,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct Jinja2AutoescapeFalse {
|
||||
pub value: bool,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for Jinja2AutoescapeFalse {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -7,9 +7,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingConfigInsecureListen;
|
||||
);
|
||||
|
||||
impl Violation for LoggingConfigInsecureListen {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -7,11 +7,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct RequestWithNoCertValidation {
|
||||
pub string: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for RequestWithNoCertValidation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::{unparse_constant, SimpleCallArgs};
|
||||
|
|
@ -7,11 +7,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct RequestWithoutTimeout {
|
||||
pub timeout: Option<String>,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for RequestWithoutTimeout {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use num_traits::{One, Zero};
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SnmpInsecureVersion;
|
||||
);
|
||||
|
||||
impl Violation for SnmpInsecureVersion {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -7,9 +7,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SnmpWeakCryptography;
|
||||
);
|
||||
|
||||
impl Violation for SnmpWeakCryptography {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Excepthandler, Expr, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_bandit::helpers::is_untyped_exception;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TryExceptContinue;
|
||||
);
|
||||
|
||||
impl Violation for TryExceptContinue {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Excepthandler, Expr, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_bandit::helpers::is_untyped_exception;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TryExceptPass;
|
||||
);
|
||||
|
||||
impl Violation for TryExceptPass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::SimpleCallArgs;
|
||||
|
|
@ -7,11 +7,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnsafeYAMLLoad {
|
||||
pub loader: Option<String>,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnsafeYAMLLoad {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::helpers;
|
||||
|
|
@ -8,11 +8,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct BlindExcept {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for BlindExcept {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Arguments, Constant, Expr, ExprKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::helpers::collect_call_path;
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::{Diagnostic, DiagnosticKind};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct BooleanPositionalArgInFunctionDefinition;
|
||||
);
|
||||
|
||||
impl Violation for BooleanPositionalArgInFunctionDefinition {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -18,9 +18,9 @@ impl Violation for BooleanPositionalArgInFunctionDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct BooleanDefaultValueInFunctionDefinition;
|
||||
);
|
||||
|
||||
impl Violation for BooleanDefaultValueInFunctionDefinition {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -28,9 +28,9 @@ impl Violation for BooleanDefaultValueInFunctionDefinition {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct BooleanPositionalValueInFunctionCall;
|
||||
);
|
||||
|
||||
impl Violation for BooleanPositionalValueInFunctionCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -7,11 +7,11 @@ use crate::registry::{Diagnostic, Rule};
|
|||
use crate::violation::Violation;
|
||||
use crate::visibility::{is_abstract, is_overload};
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct AbstractBaseClassWithoutAbstractMethod {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for AbstractBaseClassWithoutAbstractMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -19,11 +19,11 @@ impl Violation for AbstractBaseClassWithoutAbstractMethod {
|
|||
format!("`{name}` is an abstract base class, but it has no abstract methods")
|
||||
}
|
||||
}
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct EmptyMethodWithoutAbstractDecorator {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for EmptyMethodWithoutAbstractDecorator {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::helpers::unparse_stmt;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::fix::Fix;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct AssertFalse;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for AssertFalse {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{ExprKind, Stmt, Withitem};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,7 +6,6 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for `self.assertRaises(Exception)`.
|
||||
///
|
||||
|
|
@ -26,8 +25,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// self.assertRaises(SomeSpecificException, foo)
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct AssertRaisesException;
|
||||
);
|
||||
|
||||
impl Violation for AssertRaisesException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct AssignmentToOsEnviron;
|
||||
);
|
||||
|
||||
impl Violation for AssignmentToOsEnviron {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::{Range, ScopeKind};
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CachedInstanceMethod;
|
||||
);
|
||||
|
||||
impl Violation for CachedInstanceMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CannotRaiseLiteral;
|
||||
);
|
||||
|
||||
impl Violation for CannotRaiseLiteral {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use rustpython_parser::ast::{
|
||||
Excepthandler, ExcepthandlerKind, Expr, ExprContext, ExprKind, Location,
|
||||
|
|
@ -13,11 +13,11 @@ use crate::fix::Fix;
|
|||
use crate::registry::{Diagnostic, Rule};
|
||||
use crate::violation::{AlwaysAutofixableViolation, Violation};
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct DuplicateTryBlockException {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for DuplicateTryBlockException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -25,11 +25,11 @@ impl Violation for DuplicateTryBlockException {
|
|||
format!("try-except block with duplicate exception `{name}`")
|
||||
}
|
||||
}
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct DuplicateHandlerException {
|
||||
pub names: Vec<String>,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for DuplicateHandlerException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Excepthandler;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::violation::Violation;
|
|||
|
||||
use rustpython_parser::ast::{ExcepthandlerKind, ExprKind};
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ExceptWithEmptyTuple;
|
||||
);
|
||||
|
||||
impl Violation for ExceptWithEmptyTuple {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{ExprKind, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::helpers;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct FStringDocstring;
|
||||
);
|
||||
|
||||
impl Violation for FStringDocstring {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Arguments, Constant, Expr, ExprKind};
|
||||
|
||||
use super::mutable_argument_default::is_mutable_func;
|
||||
|
|
@ -10,11 +10,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::{Diagnostic, DiagnosticKind};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct FunctionCallArgumentDefault {
|
||||
pub name: Option<String>,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for FunctionCallArgumentDefault {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::FxHashSet;
|
||||
use rustpython_parser::ast::{Comprehension, Expr, ExprContext, ExprKind, Stmt, StmtKind};
|
||||
|
||||
|
|
@ -10,11 +10,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct FunctionUsesLoopVariable {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for FunctionUsesLoopVariable {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Location};
|
||||
|
|
@ -10,9 +10,9 @@ use crate::fix::Fix;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct GetAttrWithConstant;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for GetAttrWithConstant {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Stmt, StmtKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,11 +6,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct JumpStatementInFinally {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for JumpStatementInFinally {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
|
|
@ -9,11 +9,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoopVariableOverridesIterator {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for LoopVariableOverridesIterator {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Arguments, Constant, Expr, ExprKind, Operator};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct MutableArgumentDefault;
|
||||
);
|
||||
|
||||
impl Violation for MutableArgumentDefault {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{ExprKind, Stmt};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::is_lower;
|
||||
|
||||
use crate::ast::helpers::RaiseStatementVisitor;
|
||||
|
|
@ -9,9 +9,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct RaiseWithoutFromInsideExcept;
|
||||
);
|
||||
|
||||
impl Violation for RaiseWithoutFromInsideExcept {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Excepthandler, ExcepthandlerKind, ExprKind};
|
||||
|
||||
use crate::ast::helpers::unparse_expr;
|
||||
|
|
@ -8,11 +8,11 @@ use crate::fix::Fix;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct RedundantTupleInExceptionHandler {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for RedundantTupleInExceptionHandler {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
|
||||
|
|
@ -11,9 +11,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::source_code::Stylist;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SetAttrWithConstant;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for SetAttrWithConstant {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
//! by the unpacked sequence, and this change of ordering can surprise and
|
||||
//! mislead readers.
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -15,9 +15,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct StarArgUnpackingAfterKeywordArg;
|
||||
);
|
||||
|
||||
impl Violation for StarArgUnpackingAfterKeywordArg {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -7,9 +7,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct StripWithMultiCharacters;
|
||||
);
|
||||
|
||||
impl Violation for StripWithMultiCharacters {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
//! n += 1
|
||||
//! ```
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Unaryop};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -25,9 +25,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnaryPrefixIncrement;
|
||||
);
|
||||
|
||||
impl Violation for UnaryPrefixIncrement {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use rustpython_parser::ast::{Expr, ExprKind, Stmt};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the unintentional use of type annotations.
|
||||
///
|
||||
|
|
@ -24,8 +23,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// a["b"] = 1
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnintentionalTypeAnnotation;
|
||||
);
|
||||
|
||||
impl Violation for UnintentionalTypeAnnotation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnreliableCallableCheck;
|
||||
);
|
||||
|
||||
impl Violation for UnreliableCallableCheck {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
//! method()
|
||||
//! ```
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Stmt};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -37,7 +37,7 @@ pub enum Certainty {
|
|||
Uncertain,
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnusedLoopControlVariable {
|
||||
/// The name of the loop control variable.
|
||||
pub name: String,
|
||||
|
|
@ -50,7 +50,7 @@ define_violation!(
|
|||
/// `locals()`).
|
||||
pub certainty: Certainty,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnusedLoopControlVariable {
|
||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UselessComparison;
|
||||
);
|
||||
|
||||
impl Violation for UselessComparison {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Expr;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UselessContextlibSuppress;
|
||||
);
|
||||
|
||||
impl Violation for UselessContextlibSuppress {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UselessExpression;
|
||||
);
|
||||
|
||||
impl Violation for UselessExpression {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ZipWithoutExplicitStrict;
|
||||
);
|
||||
|
||||
impl Violation for ZipWithoutExplicitStrict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::builtins::BUILTINS;
|
||||
use rustpython_parser::ast::Located;
|
||||
|
||||
|
|
@ -7,7 +7,6 @@ use crate::ast::types::Range;
|
|||
use crate::registry::{Diagnostic, DiagnosticKind};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for variable (and function) assignments that use the same name
|
||||
/// as a builtin.
|
||||
|
|
@ -46,10 +45,11 @@ define_violation!(
|
|||
/// ```
|
||||
///
|
||||
/// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python)
|
||||
#[violation]
|
||||
pub struct BuiltinVariableShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for BuiltinVariableShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -58,7 +58,6 @@ impl Violation for BuiltinVariableShadowing {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for any function arguments that use the same name as a builtin.
|
||||
///
|
||||
|
|
@ -100,10 +99,11 @@ define_violation!(
|
|||
/// ## References
|
||||
/// - [_Is it bad practice to use a built-in function name as an attribute or method identifier?_](https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide)
|
||||
/// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python)
|
||||
#[violation]
|
||||
pub struct BuiltinArgumentShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for BuiltinArgumentShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -112,7 +112,6 @@ impl Violation for BuiltinArgumentShadowing {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for any class attributes that use the same name as a builtin.
|
||||
///
|
||||
|
|
@ -155,10 +154,11 @@ define_violation!(
|
|||
/// ## References
|
||||
/// - [_Is it bad practice to use a built-in function name as an attribute or method identifier?_](https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide)
|
||||
/// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python)
|
||||
#[violation]
|
||||
pub struct BuiltinAttributeShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for BuiltinAttributeShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::lexer::{LexResult, Spanned};
|
||||
use rustpython_parser::Tok;
|
||||
|
||||
|
|
@ -109,9 +109,9 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TrailingCommaMissing;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for TrailingCommaMissing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -123,9 +123,9 @@ impl AlwaysAutofixableViolation for TrailingCommaMissing {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TrailingCommaOnBareTupleProhibited;
|
||||
);
|
||||
|
||||
impl Violation for TrailingCommaOnBareTupleProhibited {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -133,9 +133,9 @@ impl Violation for TrailingCommaOnBareTupleProhibited {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TrailingCommaProhibited;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for TrailingCommaProhibited {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary `list` or `reversed` calls around `sorted`
|
||||
/// calls.
|
||||
|
|
@ -33,10 +32,11 @@ define_violation!(
|
|||
/// ```python
|
||||
/// sorted(iterable, reverse=True)
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnnecessaryCallAroundSorted {
|
||||
pub func: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryCallAroundSorted {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -10,11 +10,11 @@ use crate::rules::flake8_comprehensions::fixes;
|
|||
use crate::rules::flake8_comprehensions::settings::Settings;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryCollectionCall {
|
||||
pub obj_type: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryCollectionCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Comprehension, Expr, ExprKind};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,11 +9,11 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryComprehension {
|
||||
pub obj_type: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryComprehension {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -10,7 +10,6 @@ use crate::violation::AlwaysAutofixableViolation;
|
|||
|
||||
use super::helpers;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary `list`, `reversed`, `set`, `sorted`, and `tuple`
|
||||
/// call within `list`, `set`, `sorted`, and `tuple` calls.
|
||||
|
|
@ -45,11 +44,12 @@ define_violation!(
|
|||
/// - Instead of `sorted(tuple(iterable))`, use `sorted(iterable)`.
|
||||
/// - Instead of `sorted(sorted(iterable))`, use `sorted(iterable)`.
|
||||
/// - Instead of `sorted(reversed(iterable))`, use `sorted(iterable)`.
|
||||
#[violation]
|
||||
pub struct UnnecessaryDoubleCastOrProcess {
|
||||
pub inner: String,
|
||||
pub outer: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryDoubleCastOrProcess {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary generators that can be rewritten as `dict`
|
||||
/// comprehensions.
|
||||
|
|
@ -28,8 +27,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// {x: f(x) for x in foo}
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnnecessaryGeneratorDict;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary generators that can be rewritten as `list`
|
||||
/// comprehensions.
|
||||
|
|
@ -28,8 +27,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// [f(x) for x in foo]
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnnecessaryGeneratorList;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorList {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary generators that can be rewritten as `set`
|
||||
/// comprehensions.
|
||||
|
|
@ -28,8 +27,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// {f(x) for x in foo}
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnnecessaryGeneratorSet;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,9 +9,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryListCall;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,9 +9,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryListComprehensionDict;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListComprehensionDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,9 +9,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryListComprehensionSet;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListComprehensionSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,11 +9,11 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryLiteralDict {
|
||||
pub obj_type: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,11 +9,11 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryLiteralSet {
|
||||
pub obj_type: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,11 +9,11 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryLiteralWithinListCall {
|
||||
pub literal: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinListCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -9,11 +9,11 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_comprehensions::fixes;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryLiteralWithinTupleCall {
|
||||
pub literal: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinTupleCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use log::error;
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -11,7 +11,6 @@ use crate::violation::{AutofixKind, Availability, Violation};
|
|||
|
||||
use super::helpers;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary `map` calls with `lambda` functions.
|
||||
///
|
||||
|
|
@ -38,10 +37,11 @@ define_violation!(
|
|||
/// `{num % 2 == 0 for num in nums}`.
|
||||
/// - Instead of `dict(map(lambda v: (v, v ** 2), values))`, use
|
||||
/// `{v: v ** 2 for v in values}`.
|
||||
#[violation]
|
||||
pub struct UnnecessaryMap {
|
||||
pub obj_type: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnnecessaryMap {
|
||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use num_bigint::BigInt;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Unaryop};
|
||||
|
||||
use super::helpers;
|
||||
|
|
@ -8,11 +8,11 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessarySubscriptReversal {
|
||||
pub func: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnnecessarySubscriptReversal {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Keyword};
|
||||
|
||||
use crate::ast::helpers::{has_non_none_keyword, is_const_none};
|
||||
|
|
@ -7,9 +7,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeWithoutTzinfo;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeWithoutTzinfo {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -17,9 +17,9 @@ impl Violation for CallDatetimeWithoutTzinfo {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeToday;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeToday {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -30,9 +30,9 @@ impl Violation for CallDatetimeToday {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeUtcnow;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeUtcnow {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -43,9 +43,9 @@ impl Violation for CallDatetimeUtcnow {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeUtcfromtimestamp;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeUtcfromtimestamp {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -56,9 +56,9 @@ impl Violation for CallDatetimeUtcfromtimestamp {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeNowWithoutTzinfo;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeNowWithoutTzinfo {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -66,9 +66,9 @@ impl Violation for CallDatetimeNowWithoutTzinfo {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeFromtimestamp;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeFromtimestamp {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -78,9 +78,9 @@ impl Violation for CallDatetimeFromtimestamp {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDatetimeStrptimeWithoutZone;
|
||||
);
|
||||
|
||||
impl Violation for CallDatetimeStrptimeWithoutZone {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -91,9 +91,9 @@ impl Violation for CallDatetimeStrptimeWithoutZone {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDateToday;
|
||||
);
|
||||
|
||||
impl Violation for CallDateToday {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -104,9 +104,9 @@ impl Violation for CallDateToday {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct CallDateFromtimestamp;
|
||||
);
|
||||
|
||||
impl Violation for CallDateFromtimestamp {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, Stmt};
|
||||
|
||||
use super::types::DebuggerUsingType;
|
||||
|
|
@ -10,11 +10,11 @@ use crate::violation::Violation;
|
|||
|
||||
// flake8-debugger
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct Debugger {
|
||||
pub using_type: DebuggerUsingType,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for Debugger {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::rules::flake8_django::rules::helpers::is_model_form;
|
||||
use crate::violation::Violation;
|
||||
use crate::{checkers::ast::Checker, registry::Diagnostic, Range};
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of `fields = "__all__"` in Django `ModelForm`
|
||||
/// classes.
|
||||
|
|
@ -37,8 +36,9 @@ define_violation!(
|
|||
/// model = Post
|
||||
/// fields = ["title", "content"]
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct AllWithModelForm;
|
||||
);
|
||||
|
||||
impl Violation for AllWithModelForm {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use rustpython_parser::ast::{Expr, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::rules::flake8_django::rules::helpers::is_model_form;
|
||||
use crate::violation::Violation;
|
||||
use crate::{checkers::ast::Checker, registry::Diagnostic, Range};
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of `exclude` in Django `ModelForm` classes.
|
||||
///
|
||||
|
|
@ -33,8 +32,9 @@ define_violation!(
|
|||
/// model = Post
|
||||
/// fields = ["title", "content"]
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct ExcludeWithModelForm;
|
||||
);
|
||||
|
||||
impl Violation for ExcludeWithModelForm {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use rustpython_parser::ast::{Expr, ExprKind, Keyword};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::{checkers::ast::Checker, registry::Diagnostic, violation::Violation, Range};
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of `locals()` in `render` functions.
|
||||
///
|
||||
|
|
@ -30,8 +29,9 @@ define_violation!(
|
|||
/// context = {"posts": posts}
|
||||
/// return render(request, "app/index.html", context)
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct LocalsInRenderFunction;
|
||||
);
|
||||
|
||||
impl Violation for LocalsInRenderFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use rustpython_parser::ast::{Constant, Expr, StmtKind};
|
||||
use rustpython_parser::ast::{ExprKind, Stmt};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -10,7 +10,6 @@ use crate::violation::Violation;
|
|||
|
||||
use super::helpers;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that `__str__` method is defined in Django models.
|
||||
///
|
||||
|
|
@ -42,8 +41,9 @@ define_violation!(
|
|||
/// def __str__(self):
|
||||
/// return f"{self.field}"
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct ModelWithoutDunderStr;
|
||||
);
|
||||
|
||||
impl Violation for ModelWithoutDunderStr {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::{CallPath, Range};
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that Django's `@receiver` decorator is listed first, prior to
|
||||
/// any other decorators.
|
||||
|
|
@ -40,8 +39,9 @@ define_violation!(
|
|||
/// def my_handler(sender, instance, created, **kwargs):
|
||||
/// pass
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct NonLeadingReceiverDecorator;
|
||||
);
|
||||
|
||||
impl Violation for NonLeadingReceiverDecorator {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use rustpython_parser::ast::Constant::Bool;
|
||||
use rustpython_parser::ast::{Expr, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
@ -10,7 +10,6 @@ use crate::violation::Violation;
|
|||
|
||||
use super::helpers;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks nullable string-based fields (like `CharField` and `TextField`)
|
||||
/// in Django models.
|
||||
|
|
@ -41,10 +40,11 @@ define_violation!(
|
|||
/// class MyModel(models.Model):
|
||||
/// field = models.CharField(max_length=255, default="")
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct NullableModelStringField {
|
||||
pub field_name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for NullableModelStringField {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,7 +6,6 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::{Diagnostic, Rule};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of string literals in exception constructors.
|
||||
///
|
||||
|
|
@ -44,8 +43,9 @@ define_violation!(
|
|||
/// raise RuntimeError(msg)
|
||||
/// RuntimeError: 'Some value' is incorrect
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct RawStringInException;
|
||||
);
|
||||
|
||||
impl Violation for RawStringInException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -53,7 +53,6 @@ impl Violation for RawStringInException {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of f-strings in exception constructors.
|
||||
///
|
||||
|
|
@ -92,8 +91,9 @@ define_violation!(
|
|||
/// raise RuntimeError(msg)
|
||||
/// RuntimeError: 'Some value' is incorrect
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct FStringInException;
|
||||
);
|
||||
|
||||
impl Violation for FStringInException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -101,7 +101,6 @@ impl Violation for FStringInException {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for the use of `.format` calls on string literals in exception
|
||||
/// constructors.
|
||||
|
|
@ -142,8 +141,9 @@ define_violation!(
|
|||
/// raise RuntimeError(msg)
|
||||
/// RuntimeError: 'Some value' is incorrect
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct DotFormatInException;
|
||||
);
|
||||
|
||||
impl Violation for DotFormatInException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
|
|
@ -10,9 +10,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_executable::helpers::is_executable;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ShebangMissingExecutableFile;
|
||||
);
|
||||
|
||||
impl Violation for ShebangMissingExecutableFile {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_executable::helpers::ShebangDirective;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ShebangNewline;
|
||||
);
|
||||
|
||||
impl Violation for ShebangNewline {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use std::path::Path;
|
|||
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
|
|
@ -13,9 +13,9 @@ use crate::rules::flake8_executable::helpers::is_executable;
|
|||
use crate::rules::flake8_executable::helpers::ShebangDirective;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ShebangNotExecutable;
|
||||
);
|
||||
|
||||
impl Violation for ShebangNotExecutable {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -6,9 +6,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_executable::helpers::ShebangDirective;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ShebangPython;
|
||||
);
|
||||
|
||||
impl Violation for ShebangPython {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::Location;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -7,9 +7,9 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_executable::helpers::ShebangDirective;
|
||||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ShebangWhitespace;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for ShebangWhitespace {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Operator};
|
||||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::Tok;
|
||||
|
|
@ -9,7 +9,6 @@ use crate::registry::Diagnostic;
|
|||
use crate::rules::flake8_implicit_str_concat::settings::Settings;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for implicitly concatenated strings on a single line.
|
||||
///
|
||||
|
|
@ -31,8 +30,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// z = "The quick brown fox."
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct SingleLineImplicitStringConcatenation;
|
||||
);
|
||||
|
||||
impl Violation for SingleLineImplicitStringConcatenation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -40,7 +40,6 @@ impl Violation for SingleLineImplicitStringConcatenation {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for implicitly concatenated strings that span multiple lines.
|
||||
///
|
||||
|
|
@ -74,8 +73,9 @@ define_violation!(
|
|||
///
|
||||
/// ## References
|
||||
/// - [PEP 8](https://peps.python.org/pep-0008/#maximum-line-length)
|
||||
#[violation]
|
||||
pub struct MultiLineImplicitStringConcatenation;
|
||||
);
|
||||
|
||||
impl Violation for MultiLineImplicitStringConcatenation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -83,7 +83,6 @@ impl Violation for MultiLineImplicitStringConcatenation {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for string literals that are explicitly concatenated (using the
|
||||
/// `+` operator).
|
||||
|
|
@ -108,8 +107,9 @@ define_violation!(
|
|||
/// "dog"
|
||||
/// )
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct ExplicitStringConcatenation;
|
||||
);
|
||||
|
||||
impl Violation for ExplicitStringConcatenation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustc_hash::FxHashMap;
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
|
|
@ -6,7 +6,6 @@ use crate::ast::types::Range;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for imports that are typically imported using a common convention,
|
||||
/// like `import pandas as pd`, and enforces that convention.
|
||||
|
|
@ -28,8 +27,9 @@ define_violation!(
|
|||
/// ```python
|
||||
/// import pandas as pd
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnconventionalImportAlias(pub String, pub String);
|
||||
);
|
||||
|
||||
impl Violation for UnconventionalImportAlias {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::violation::{AlwaysAutofixableViolation, Violation};
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingStringFormat;
|
||||
);
|
||||
|
||||
impl Violation for LoggingStringFormat {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -12,9 +12,9 @@ impl Violation for LoggingStringFormat {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingPercentFormat;
|
||||
);
|
||||
|
||||
impl Violation for LoggingPercentFormat {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -22,9 +22,9 @@ impl Violation for LoggingPercentFormat {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingStringConcat;
|
||||
);
|
||||
|
||||
impl Violation for LoggingStringConcat {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -32,9 +32,9 @@ impl Violation for LoggingStringConcat {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingFString;
|
||||
);
|
||||
|
||||
impl Violation for LoggingFString {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -42,9 +42,9 @@ impl Violation for LoggingFString {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingWarn;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for LoggingWarn {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -56,9 +56,9 @@ impl AlwaysAutofixableViolation for LoggingWarn {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingExtraAttrClash(pub String);
|
||||
);
|
||||
|
||||
impl Violation for LoggingExtraAttrClash {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -69,9 +69,9 @@ impl Violation for LoggingExtraAttrClash {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingExcInfo;
|
||||
);
|
||||
|
||||
impl Violation for LoggingExcInfo {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -79,9 +79,9 @@ impl Violation for LoggingExcInfo {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct LoggingRedundantExcInfo;
|
||||
);
|
||||
|
||||
impl Violation for LoggingRedundantExcInfo {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::fs;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for packages that are missing an `__init__.py` file.
|
||||
///
|
||||
|
|
@ -26,10 +25,11 @@ define_violation!(
|
|||
///
|
||||
/// ## Options
|
||||
/// - `namespace-packages`
|
||||
#[violation]
|
||||
pub struct ImplicitNamespacePackage {
|
||||
pub filename: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for ImplicitNamespacePackage {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use log::error;
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_identifier;
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
|
@ -17,9 +17,9 @@ use crate::violation::{AlwaysAutofixableViolation, Violation};
|
|||
|
||||
use super::fixes;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryPass;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryPass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -31,9 +31,9 @@ impl AlwaysAutofixableViolation for UnnecessaryPass {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct DupeClassFieldDefinitions(pub String);
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for DupeClassFieldDefinitions {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -47,11 +47,11 @@ impl AlwaysAutofixableViolation for DupeClassFieldDefinitions {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct PreferUniqueEnums {
|
||||
pub value: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for PreferUniqueEnums {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -60,7 +60,6 @@ impl Violation for PreferUniqueEnums {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for unnecessary list comprehensions passed to `any` and `all`.
|
||||
///
|
||||
|
|
@ -91,8 +90,9 @@ define_violation!(
|
|||
/// any(x.id for x in bar)
|
||||
/// all(x.id for x in bar)
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct UnnecessaryComprehensionAnyAll;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryComprehensionAnyAll {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -104,9 +104,9 @@ impl AlwaysAutofixableViolation for UnnecessaryComprehensionAnyAll {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessarySpread;
|
||||
);
|
||||
|
||||
impl Violation for UnnecessarySpread {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -114,11 +114,11 @@ impl Violation for UnnecessarySpread {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct SingleStartsEndsWith {
|
||||
pub attr: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for SingleStartsEndsWith {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -127,9 +127,9 @@ impl Violation for SingleStartsEndsWith {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnnecessaryDictKwargs;
|
||||
);
|
||||
|
||||
impl Violation for UnnecessaryDictKwargs {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -137,9 +137,9 @@ impl Violation for UnnecessaryDictKwargs {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct PreferListBuiltin;
|
||||
);
|
||||
|
||||
impl AlwaysAutofixableViolation for PreferListBuiltin {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use rustpython_parser::ast::{Expr, Keyword};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::helpers::is_const_none;
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -8,9 +8,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct PrintFound;
|
||||
);
|
||||
|
||||
impl Violation for PrintFound {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -18,9 +18,9 @@ impl Violation for PrintFound {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct PPrintFound;
|
||||
);
|
||||
|
||||
impl Violation for PPrintFound {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use rustpython_parser::ast::{Cmpop, Expr};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
use crate::Range;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for usages of comparators other than `<` and `>=` for
|
||||
/// `sys.version_info` checks in `.pyi` files. All other comparators, such
|
||||
|
|
@ -49,8 +48,9 @@ define_violation!(
|
|||
/// if sys.version_info >= (3, 9):
|
||||
/// ...
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct BadVersionInfoComparison;
|
||||
);
|
||||
|
||||
impl Violation for BadVersionInfoComparison {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use rustpython_parser::ast::Expr;
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct DocstringInStub;
|
||||
);
|
||||
|
||||
impl Violation for DocstringInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use rustpython_parser::ast::{Constant, ExprKind, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct NonEmptyStubBody;
|
||||
);
|
||||
|
||||
impl Violation for NonEmptyStubBody {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use rustpython_parser::ast::{Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct PassStatementStubBody;
|
||||
);
|
||||
|
||||
impl Violation for PassStatementStubBody {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
|
@ -25,7 +25,6 @@ impl fmt::Display for VarKind {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks that type `TypeVar`, `ParamSpec`, and `TypeVarTuple` definitions in
|
||||
/// stubs are prefixed with `_`.
|
||||
|
|
@ -47,10 +46,11 @@ define_violation!(
|
|||
///
|
||||
/// _T = TypeVar("_T")
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct PrefixTypeParams {
|
||||
pub kind: VarKind,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for PrefixTypeParams {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
use rustpython_parser::ast::{Arguments, Constant, Expr, ExprKind, Operator, Unaryop};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct TypedArgumentSimpleDefaults;
|
||||
);
|
||||
|
||||
/// PYI011
|
||||
impl Violation for TypedArgumentSimpleDefaults {
|
||||
#[derive_message_formats]
|
||||
|
|
@ -18,9 +18,9 @@ impl Violation for TypedArgumentSimpleDefaults {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct ArgumentSimpleDefaults;
|
||||
);
|
||||
|
||||
/// PYI014
|
||||
impl Violation for ArgumentSimpleDefaults {
|
||||
#[derive_message_formats]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use rustpython_parser::ast::{Cmpop, Constant, Expr, ExprKind};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::{Diagnostic, Rule};
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Check for unrecognized `sys.platform` checks. Platform checks should be
|
||||
/// simple string comparisons.
|
||||
|
|
@ -41,8 +40,9 @@ define_violation!(
|
|||
///
|
||||
/// ## References
|
||||
/// - [PEP 484](https://peps.python.org/pep-0484/#version-and-platform-checking)
|
||||
#[violation]
|
||||
pub struct UnrecognizedPlatformCheck;
|
||||
);
|
||||
|
||||
impl Violation for UnrecognizedPlatformCheck {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -50,7 +50,6 @@ impl Violation for UnrecognizedPlatformCheck {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Check for unrecognized platform names in `sys.platform` checks.
|
||||
///
|
||||
|
|
@ -77,10 +76,11 @@ define_violation!(
|
|||
///
|
||||
/// ## References
|
||||
/// - [PEP 484](https://peps.python.org/pep-0484/#version-and-platform-checking)
|
||||
#[violation]
|
||||
pub struct UnrecognizedPlatformName {
|
||||
pub platform: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnrecognizedPlatformName {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use rustpython_parser::ast::{
|
|||
Unaryop,
|
||||
};
|
||||
|
||||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::ast::helpers::{has_comments_in, unparse_stmt};
|
||||
use crate::ast::types::Range;
|
||||
|
|
@ -26,7 +26,6 @@ use crate::violation::{AutofixKind, Availability, Violation};
|
|||
use super::helpers::is_falsy_constant;
|
||||
use super::unittest_assert::UnittestAssert;
|
||||
|
||||
define_violation!(
|
||||
/// ## What it does
|
||||
/// Checks for assertions that combine multiple independent conditions.
|
||||
///
|
||||
|
|
@ -55,10 +54,11 @@ define_violation!(
|
|||
/// assert not something
|
||||
/// assert not something_else
|
||||
/// ```
|
||||
#[violation]
|
||||
pub struct CompositeAssertion {
|
||||
pub fixable: bool,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for CompositeAssertion {
|
||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
||||
|
||||
|
|
@ -73,11 +73,11 @@ impl Violation for CompositeAssertion {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct AssertInExcept {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for AssertInExcept {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -88,9 +88,9 @@ impl Violation for AssertInExcept {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct AssertAlwaysFalse;
|
||||
);
|
||||
|
||||
impl Violation for AssertAlwaysFalse {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
@ -98,12 +98,12 @@ impl Violation for AssertAlwaysFalse {
|
|||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct UnittestAssertion {
|
||||
pub assertion: String,
|
||||
pub fixable: bool,
|
||||
}
|
||||
);
|
||||
|
||||
impl Violation for UnittestAssertion {
|
||||
const AUTOFIX: Option<AutofixKind> = Some(AutofixKind::new(Availability::Sometimes));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_macros::{define_violation, derive_message_formats};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use rustpython_parser::ast::{Expr, Keyword};
|
||||
|
||||
use super::helpers::{is_empty_or_null_string, is_pytest_fail};
|
||||
|
|
@ -8,9 +8,9 @@ use crate::checkers::ast::Checker;
|
|||
use crate::registry::Diagnostic;
|
||||
use crate::violation::Violation;
|
||||
|
||||
define_violation!(
|
||||
#[violation]
|
||||
pub struct FailWithoutMessage;
|
||||
);
|
||||
|
||||
impl Violation for FailWithoutMessage {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue