mirror of https://github.com/astral-sh/ruff
Move flake8-builtins violations to rules file (#2478)
This commit is contained in:
parent
aa0fc0f9c2
commit
ebfa55cea3
|
|
@ -95,9 +95,9 @@ ruff_macros::define_rule_mapping!(
|
|||
PLR0913 => rules::pylint::rules::TooManyArgs,
|
||||
PLR0915 => rules::pylint::rules::TooManyStatements,
|
||||
// flake8-builtins
|
||||
A001 => violations::BuiltinVariableShadowing,
|
||||
A002 => violations::BuiltinArgumentShadowing,
|
||||
A003 => violations::BuiltinAttributeShadowing,
|
||||
A001 => rules::flake8_builtins::rules::BuiltinVariableShadowing,
|
||||
A002 => rules::flake8_builtins::rules::BuiltinArgumentShadowing,
|
||||
A003 => rules::flake8_builtins::rules::BuiltinAttributeShadowing,
|
||||
// flake8-bugbear
|
||||
B002 => rules::flake8_bugbear::rules::UnaryPrefixIncrement,
|
||||
B003 => rules::flake8_bugbear::rules::AssignmentToOsEnviron,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,50 @@
|
|||
use rustpython_ast::Located;
|
||||
|
||||
use super::types::ShadowingType;
|
||||
use crate::ast::types::Range;
|
||||
use crate::define_violation;
|
||||
use crate::python::builtins::BUILTINS;
|
||||
use crate::registry::{Diagnostic, DiagnosticKind};
|
||||
use crate::violations;
|
||||
use crate::violation::Violation;
|
||||
use ruff_macros::derive_message_formats;
|
||||
use rustpython_ast::Located;
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinVariableShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinVariableShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinVariableShadowing { name } = self;
|
||||
format!("Variable `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinArgumentShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinArgumentShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinArgumentShadowing { name } = self;
|
||||
format!("Argument `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinAttributeShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinAttributeShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinAttributeShadowing { name } = self;
|
||||
format!("Class attribute `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
/// Check builtin name shadowing.
|
||||
pub fn builtin_shadowing<T>(
|
||||
|
|
@ -16,15 +56,15 @@ pub fn builtin_shadowing<T>(
|
|||
if BUILTINS.contains(&name) && !ignorelist.contains(&name.to_string()) {
|
||||
Some(Diagnostic::new::<DiagnosticKind>(
|
||||
match node_type {
|
||||
ShadowingType::Variable => violations::BuiltinVariableShadowing {
|
||||
ShadowingType::Variable => BuiltinVariableShadowing {
|
||||
name: name.to_string(),
|
||||
}
|
||||
.into(),
|
||||
ShadowingType::Argument => violations::BuiltinArgumentShadowing {
|
||||
ShadowingType::Argument => BuiltinArgumentShadowing {
|
||||
name: name.to_string(),
|
||||
}
|
||||
.into(),
|
||||
ShadowingType::Attribute => violations::BuiltinAttributeShadowing {
|
||||
ShadowingType::Attribute => BuiltinAttributeShadowing {
|
||||
name: name.to_string(),
|
||||
}
|
||||
.into(),
|
||||
|
|
|
|||
|
|
@ -947,47 +947,6 @@ impl Violation for GlobalVariableNotAssigned {
|
|||
}
|
||||
}
|
||||
|
||||
// flake8-builtins
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinVariableShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinVariableShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinVariableShadowing { name } = self;
|
||||
format!("Variable `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinArgumentShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinArgumentShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinArgumentShadowing { name } = self;
|
||||
format!("Argument `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
define_violation!(
|
||||
pub struct BuiltinAttributeShadowing {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl Violation for BuiltinAttributeShadowing {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BuiltinAttributeShadowing { name } = self;
|
||||
format!("Class attribute `{name}` is shadowing a python builtin")
|
||||
}
|
||||
}
|
||||
|
||||
// flake8-blind-except
|
||||
|
||||
define_violation!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue