mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Rename rules containing PEP reference in name
This commit is contained in:
parent
42924c0d9a
commit
7db6a2d6d4
18 changed files with 67 additions and 70 deletions
|
@ -2062,7 +2062,7 @@ where
|
|||
// Ex) Optional[...]
|
||||
if !self.in_deferred_string_type_definition
|
||||
&& !self.settings.pyupgrade.keep_runtime_typing
|
||||
&& self.settings.rules.enabled(&Rule::UsePEP604Annotation)
|
||||
&& self.settings.rules.enabled(&Rule::TypingUnion)
|
||||
&& (self.settings.target_version >= PythonVersion::Py310
|
||||
|| (self.settings.target_version >= PythonVersion::Py37
|
||||
&& self.annotations_future_enabled
|
||||
|
@ -2117,7 +2117,7 @@ where
|
|||
// Ex) List[...]
|
||||
if !self.in_deferred_string_type_definition
|
||||
&& !self.settings.pyupgrade.keep_runtime_typing
|
||||
&& self.settings.rules.enabled(&Rule::UsePEP585Annotation)
|
||||
&& self.settings.rules.enabled(&Rule::DeprecatedCollectionType)
|
||||
&& (self.settings.target_version >= PythonVersion::Py39
|
||||
|| (self.settings.target_version >= PythonVersion::Py37
|
||||
&& self.annotations_future_enabled
|
||||
|
@ -2162,7 +2162,7 @@ where
|
|||
// Ex) typing.List[...]
|
||||
if !self.in_deferred_string_type_definition
|
||||
&& !self.settings.pyupgrade.keep_runtime_typing
|
||||
&& self.settings.rules.enabled(&Rule::UsePEP585Annotation)
|
||||
&& self.settings.rules.enabled(&Rule::DeprecatedCollectionType)
|
||||
&& (self.settings.target_version >= PythonVersion::Py39
|
||||
|| (self.settings.target_version >= PythonVersion::Py37
|
||||
&& self.annotations_future_enabled
|
||||
|
|
|
@ -38,16 +38,12 @@ pub fn check_physical_lines(
|
|||
let enforce_doc_line_too_long = settings.rules.enabled(&Rule::DocLineTooLong);
|
||||
let enforce_line_too_long = settings.rules.enabled(&Rule::LineTooLong);
|
||||
let enforce_no_newline_at_end_of_file = settings.rules.enabled(&Rule::NoNewLineAtEndOfFile);
|
||||
let enforce_unnecessary_coding_comment = settings
|
||||
.rules
|
||||
.enabled(&Rule::PEP3120UnnecessaryCodingComment);
|
||||
let enforce_unnecessary_coding_comment = settings.rules.enabled(&Rule::UTF8EncodingDeclaration);
|
||||
let enforce_mixed_spaces_and_tabs = settings.rules.enabled(&Rule::MixedSpacesAndTabs);
|
||||
let enforce_bidirectional_unicode = settings.rules.enabled(&Rule::BidirectionalUnicode);
|
||||
|
||||
let fix_unnecessary_coding_comment = matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings
|
||||
.rules
|
||||
.should_fix(&Rule::PEP3120UnnecessaryCodingComment);
|
||||
&& settings.rules.should_fix(&Rule::UTF8EncodingDeclaration);
|
||||
let fix_shebang_whitespace = matches!(autofix, flags::Autofix::Enabled)
|
||||
&& settings.rules.should_fix(&Rule::ShebangWhitespace);
|
||||
|
||||
|
|
|
@ -282,10 +282,10 @@ ruff_macros::define_rule_mapping!(
|
|||
UP003 => rules::pyupgrade::rules::TypeOfPrimitive,
|
||||
UP004 => rules::pyupgrade::rules::UselessObjectInheritance,
|
||||
UP005 => rules::pyupgrade::rules::DeprecatedUnittestAlias,
|
||||
UP006 => rules::pyupgrade::rules::UsePEP585Annotation,
|
||||
UP007 => rules::pyupgrade::rules::UsePEP604Annotation,
|
||||
UP006 => rules::pyupgrade::rules::DeprecatedCollectionType,
|
||||
UP007 => rules::pyupgrade::rules::TypingUnion,
|
||||
UP008 => rules::pyupgrade::rules::SuperCallWithParameters,
|
||||
UP009 => rules::pyupgrade::rules::PEP3120UnnecessaryCodingComment,
|
||||
UP009 => rules::pyupgrade::rules::UTF8EncodingDeclaration,
|
||||
UP010 => rules::pyupgrade::rules::UnnecessaryFutureImport,
|
||||
UP011 => rules::pyupgrade::rules::LRUCacheWithoutParameters,
|
||||
UP012 => rules::pyupgrade::rules::UnnecessaryEncodeUTF8,
|
||||
|
@ -751,7 +751,7 @@ impl Rule {
|
|||
| Rule::LineTooLong
|
||||
| Rule::MixedSpacesAndTabs
|
||||
| Rule::NoNewLineAtEndOfFile
|
||||
| Rule::PEP3120UnnecessaryCodingComment
|
||||
| Rule::UTF8EncodingDeclaration
|
||||
| Rule::ShebangMissingExecutableFile
|
||||
| Rule::ShebangNotExecutable
|
||||
| Rule::ShebangNewline
|
||||
|
|
|
@ -21,14 +21,14 @@ mod tests {
|
|||
#[test_case(Rule::TypeOfPrimitive, Path::new("UP003.py"); "UP003")]
|
||||
#[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"); "UP004")]
|
||||
#[test_case(Rule::DeprecatedUnittestAlias, Path::new("UP005.py"); "UP005")]
|
||||
#[test_case(Rule::UsePEP585Annotation, Path::new("UP006.py"); "UP006")]
|
||||
#[test_case(Rule::UsePEP604Annotation, Path::new("UP007.py"); "UP007")]
|
||||
#[test_case(Rule::DeprecatedCollectionType, Path::new("UP006.py"); "UP006")]
|
||||
#[test_case(Rule::TypingUnion, Path::new("UP007.py"); "UP007")]
|
||||
#[test_case(Rule::SuperCallWithParameters, Path::new("UP008.py"); "UP008")]
|
||||
#[test_case(Rule::PEP3120UnnecessaryCodingComment, Path::new("UP009_0.py"); "UP009_0")]
|
||||
#[test_case(Rule::PEP3120UnnecessaryCodingComment, Path::new("UP009_1.py"); "UP009_1")]
|
||||
#[test_case(Rule::PEP3120UnnecessaryCodingComment, Path::new("UP009_2.py"); "UP009_2")]
|
||||
#[test_case(Rule::PEP3120UnnecessaryCodingComment, Path::new("UP009_3.py"); "UP009_3")]
|
||||
#[test_case(Rule::PEP3120UnnecessaryCodingComment, Path::new("UP009_4.py"); "UP009_4")]
|
||||
#[test_case(Rule::UTF8EncodingDeclaration, Path::new("UP009_0.py"); "UP009_0")]
|
||||
#[test_case(Rule::UTF8EncodingDeclaration, Path::new("UP009_1.py"); "UP009_1")]
|
||||
#[test_case(Rule::UTF8EncodingDeclaration, Path::new("UP009_2.py"); "UP009_2")]
|
||||
#[test_case(Rule::UTF8EncodingDeclaration, Path::new("UP009_3.py"); "UP009_3")]
|
||||
#[test_case(Rule::UTF8EncodingDeclaration, Path::new("UP009_4.py"); "UP009_4")]
|
||||
#[test_case(Rule::UnnecessaryFutureImport, Path::new("UP010.py"); "UP010")]
|
||||
#[test_case(Rule::LRUCacheWithoutParameters, Path::new("UP011.py"); "UP011")]
|
||||
#[test_case(Rule::UnnecessaryEncodeUTF8, Path::new("UP012.py"); "UP012")]
|
||||
|
@ -81,7 +81,7 @@ mod tests {
|
|||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::UsePEP585Annotation)
|
||||
..settings::Settings::for_rule(Rule::DeprecatedCollectionType)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!(diagnostics);
|
||||
|
@ -94,7 +94,7 @@ mod tests {
|
|||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
target_version: PythonVersion::Py310,
|
||||
..settings::Settings::for_rule(Rule::UsePEP585Annotation)
|
||||
..settings::Settings::for_rule(Rule::DeprecatedCollectionType)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!(diagnostics);
|
||||
|
@ -107,7 +107,7 @@ mod tests {
|
|||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
target_version: PythonVersion::Py37,
|
||||
..settings::Settings::for_rule(Rule::UsePEP604Annotation)
|
||||
..settings::Settings::for_rule(Rule::TypingUnion)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!(diagnostics);
|
||||
|
@ -120,7 +120,7 @@ mod tests {
|
|||
Path::new("pyupgrade/future_annotations.py"),
|
||||
&settings::Settings {
|
||||
target_version: PythonVersion::Py310,
|
||||
..settings::Settings::for_rule(Rule::UsePEP604Annotation)
|
||||
..settings::Settings::for_rule(Rule::TypingUnion)
|
||||
},
|
||||
)?;
|
||||
assert_yaml_snapshot!(diagnostics);
|
||||
|
|
|
@ -33,14 +33,12 @@ pub(crate) use super_call_with_parameters::{super_call_with_parameters, SuperCal
|
|||
pub(crate) use type_of_primitive::{type_of_primitive, TypeOfPrimitive};
|
||||
pub(crate) use typing_text_str_alias::{typing_text_str_alias, TypingTextStrAlias};
|
||||
pub(crate) use unnecessary_builtin_import::{unnecessary_builtin_import, UnnecessaryBuiltinImport};
|
||||
pub(crate) use unnecessary_coding_comment::{
|
||||
unnecessary_coding_comment, PEP3120UnnecessaryCodingComment,
|
||||
};
|
||||
pub(crate) use unnecessary_coding_comment::{unnecessary_coding_comment, UTF8EncodingDeclaration};
|
||||
pub(crate) use unnecessary_encode_utf8::{unnecessary_encode_utf8, UnnecessaryEncodeUTF8};
|
||||
pub(crate) use unnecessary_future_import::{unnecessary_future_import, UnnecessaryFutureImport};
|
||||
pub(crate) use unpack_list_comprehension::{unpack_list_comprehension, RewriteListComprehension};
|
||||
pub(crate) use use_pep585_annotation::{use_pep585_annotation, UsePEP585Annotation};
|
||||
pub(crate) use use_pep604_annotation::{use_pep604_annotation, UsePEP604Annotation};
|
||||
pub(crate) use use_pep585_annotation::{use_pep585_annotation, DeprecatedCollectionType};
|
||||
pub(crate) use use_pep604_annotation::{use_pep604_annotation, TypingUnion};
|
||||
pub(crate) use useless_metaclass_type::{useless_metaclass_type, UselessMetaclassType};
|
||||
pub(crate) use useless_object_inheritance::{useless_object_inheritance, UselessObjectInheritance};
|
||||
|
||||
|
|
|
@ -9,9 +9,10 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
pub struct PEP3120UnnecessaryCodingComment;
|
||||
// TODO: document referencing [PEP 3120]: https://peps.python.org/pep-3120/
|
||||
pub struct UTF8EncodingDeclaration;
|
||||
);
|
||||
impl AlwaysAutofixableViolation for PEP3120UnnecessaryCodingComment {
|
||||
impl AlwaysAutofixableViolation for UTF8EncodingDeclaration {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("UTF-8 encoding declaration is unnecessary")
|
||||
|
@ -31,7 +32,7 @@ pub fn unnecessary_coding_comment(lineno: usize, line: &str, autofix: bool) -> O
|
|||
// PEP3120 makes utf-8 the default encoding.
|
||||
if CODING_COMMENT_REGEX.is_match(line) {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
PEP3120UnnecessaryCodingComment,
|
||||
UTF8EncodingDeclaration,
|
||||
Range::new(Location::new(lineno + 1, 0), Location::new(lineno + 2, 0)),
|
||||
);
|
||||
if autofix {
|
||||
|
|
|
@ -8,14 +8,15 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
pub struct UsePEP585Annotation {
|
||||
// TODO: document referencing [PEP 585]: https://peps.python.org/pep-0585/
|
||||
pub struct DeprecatedCollectionType {
|
||||
pub name: String,
|
||||
}
|
||||
);
|
||||
impl AlwaysAutofixableViolation for UsePEP585Annotation {
|
||||
impl AlwaysAutofixableViolation for DeprecatedCollectionType {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UsePEP585Annotation { name } = self;
|
||||
let DeprecatedCollectionType { name } = self;
|
||||
format!(
|
||||
"Use `{}` instead of `{}` for type annotations",
|
||||
name.to_lowercase(),
|
||||
|
@ -24,7 +25,7 @@ impl AlwaysAutofixableViolation for UsePEP585Annotation {
|
|||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
let UsePEP585Annotation { name } = self;
|
||||
let DeprecatedCollectionType { name } = self;
|
||||
format!("Replace `{name}` with `{}`", name.to_lowercase(),)
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +37,7 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr) {
|
|||
.and_then(|call_path| call_path.last().copied())
|
||||
{
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
UsePEP585Annotation {
|
||||
DeprecatedCollectionType {
|
||||
name: binding.to_string(),
|
||||
},
|
||||
Range::from_located(expr),
|
||||
|
|
|
@ -9,9 +9,10 @@ use crate::registry::Diagnostic;
|
|||
use crate::violation::AlwaysAutofixableViolation;
|
||||
|
||||
define_violation!(
|
||||
pub struct UsePEP604Annotation;
|
||||
// TODO: document referencing [PEP 604]: https://peps.python.org/pep-0604/
|
||||
pub struct TypingUnion;
|
||||
);
|
||||
impl AlwaysAutofixableViolation for UsePEP604Annotation {
|
||||
impl AlwaysAutofixableViolation for TypingUnion {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use `X | Y` for type annotations")
|
||||
|
@ -95,7 +96,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
|
||||
match typing_member {
|
||||
TypingMember::Optional => {
|
||||
let mut diagnostic = Diagnostic::new(UsePEP604Annotation, Range::from_located(expr));
|
||||
let mut diagnostic = Diagnostic::new(TypingUnion, Range::from_located(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
diagnostic.amend(Fix::replacement(
|
||||
unparse_expr(&optional(slice), checker.stylist),
|
||||
|
@ -106,7 +107,7 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
|
|||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
TypingMember::Union => {
|
||||
let mut diagnostic = Diagnostic::new(UsePEP604Annotation, Range::from_located(expr));
|
||||
let mut diagnostic = Diagnostic::new(TypingUnion, Range::from_located(expr));
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
match &slice.node {
|
||||
ExprKind::Slice { .. } => {
|
||||
|
|
|
@ -3,7 +3,7 @@ source: crates/ruff/src/rules/pyupgrade/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 4
|
||||
|
@ -22,7 +22,7 @@ expression: diagnostics
|
|||
column: 20
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 11
|
||||
|
@ -41,7 +41,7 @@ expression: diagnostics
|
|||
column: 13
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 18
|
||||
|
@ -60,7 +60,7 @@ expression: diagnostics
|
|||
column: 15
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 25
|
||||
|
|
|
@ -3,7 +3,7 @@ source: crates/ruff/src/rules/pyupgrade/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 6
|
||||
column: 9
|
||||
|
@ -21,7 +21,7 @@ expression: diagnostics
|
|||
column: 22
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 10
|
||||
column: 9
|
||||
|
@ -39,7 +39,7 @@ expression: diagnostics
|
|||
column: 29
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 14
|
||||
column: 9
|
||||
|
@ -57,7 +57,7 @@ expression: diagnostics
|
|||
column: 45
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 14
|
||||
column: 25
|
||||
|
@ -75,7 +75,7 @@ expression: diagnostics
|
|||
column: 44
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 18
|
||||
column: 9
|
||||
|
@ -93,7 +93,7 @@ expression: diagnostics
|
|||
column: 31
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 22
|
||||
column: 9
|
||||
|
@ -111,7 +111,7 @@ expression: diagnostics
|
|||
column: 33
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 26
|
||||
column: 9
|
||||
|
|
|
@ -3,7 +3,7 @@ source: crates/ruff/src/rules/pyupgrade/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
PEP3120UnnecessaryCodingComment: ~
|
||||
UTF8EncodingDeclaration: ~
|
||||
location:
|
||||
row: 1
|
||||
column: 0
|
||||
|
|
|
@ -3,7 +3,7 @@ source: crates/ruff/src/rules/pyupgrade/mod.rs
|
|||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
PEP3120UnnecessaryCodingComment: ~
|
||||
UTF8EncodingDeclaration: ~
|
||||
location:
|
||||
row: 2
|
||||
column: 0
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/pyupgrade/mod.rs
|
||||
source: crates/ruff/src/rules/pyupgrade/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 34
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/pyupgrade/mod.rs
|
||||
source: crates/ruff/src/rules/pyupgrade/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 34
|
||||
|
@ -22,7 +22,7 @@ expression: diagnostics
|
|||
column: 21
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 35
|
||||
|
@ -41,7 +41,7 @@ expression: diagnostics
|
|||
column: 12
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 42
|
||||
|
@ -60,7 +60,7 @@ expression: diagnostics
|
|||
column: 30
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP585Annotation:
|
||||
DeprecatedCollectionType:
|
||||
name: List
|
||||
location:
|
||||
row: 42
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/pyupgrade/mod.rs
|
||||
source: crates/ruff/src/rules/pyupgrade/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 40
|
||||
column: 3
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
---
|
||||
source: src/rules/pyupgrade/mod.rs
|
||||
source: crates/ruff/src/rules/pyupgrade/mod.rs
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 40
|
||||
column: 3
|
||||
|
@ -21,7 +21,7 @@ expression: diagnostics
|
|||
column: 16
|
||||
parent: ~
|
||||
- kind:
|
||||
UsePEP604Annotation: ~
|
||||
TypingUnion: ~
|
||||
location:
|
||||
row: 42
|
||||
column: 20
|
||||
|
|
|
@ -111,7 +111,7 @@ mod tests {
|
|||
fn redirects() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/redirects.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UsePEP604Annotation]),
|
||||
&settings::Settings::for_rules(vec![Rule::TypingUnion]),
|
||||
)?;
|
||||
assert_yaml_snapshot!(diagnostics);
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue