Rename refactor checks to upgrade checks (#354)

This commit is contained in:
Charlie Marsh
2022-10-07 16:54:55 -04:00
committed by GitHub
parent 04ade6a2f3
commit 99c66d513a
8 changed files with 40 additions and 49 deletions

View File

@@ -287,8 +287,8 @@ The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` com
| U001 | UselessMetaclassType | `__metaclass__ = type` is implied | | 🛠 |
| U002 | UnnecessaryAbspath | `abspath(__file__)` is unnecessary in Python 3.9 and later | | 🛠 |
| U003 | TypeOfPrimitive | Use `str` instead of `type(...)` | | 🛠 |
| R001 | UselessObjectInheritance | Class `...` inherits from object | | 🛠 |
| R002 | NoAssertEquals | `assertEquals` is deprecated, use `assertEqual` instead | | 🛠 |
| U004 | UselessObjectInheritance | Class `...` inherits from object | | 🛠 |
| U005 | NoAssertEquals | `assertEquals` is deprecated, use `assertEqual` instead | | 🛠 |
| M001 | UnusedNOQA | Unused `noqa` directive | | 🛠 |
## Integrations

View File

@@ -388,7 +388,7 @@ where
decorator_list,
..
} => {
if self.settings.enabled.contains(&CheckCode::R001) {
if self.settings.enabled.contains(&CheckCode::U004) {
plugins::useless_object_inheritance(self, stmt, name, bases, keywords);
}
@@ -749,7 +749,7 @@ where
ExprContext::Del => self.handle_node_delete(expr),
},
ExprKind::Call { func, args, .. } => {
if self.settings.enabled.contains(&CheckCode::R002) {
if self.settings.enabled.contains(&CheckCode::U005) {
plugins::assert_equals(self, func);
}

View File

@@ -118,9 +118,8 @@ pub const ALL_CHECK_CODES: [CheckCode; 58] = [
CheckCode::U001,
CheckCode::U002,
CheckCode::U003,
// Refactor
CheckCode::R001,
CheckCode::R002,
CheckCode::U004,
CheckCode::U005,
// Meta
CheckCode::M001,
];
@@ -189,9 +188,8 @@ pub enum CheckCode {
U001,
U002,
U003,
// Refactor
R001,
R002,
U004,
U005,
// Meta
M001,
}
@@ -261,9 +259,8 @@ impl FromStr for CheckCode {
"U001" => Ok(CheckCode::U001),
"U002" => Ok(CheckCode::U002),
"U003" => Ok(CheckCode::U003),
// Refactor
"R001" => Ok(CheckCode::R001),
"R002" => Ok(CheckCode::R002),
"U004" => Ok(CheckCode::U004),
"U005" => Ok(CheckCode::U005),
// Meta
"M001" => Ok(CheckCode::M001),
_ => Err(anyhow::anyhow!("Unknown check code: {s}")),
@@ -336,9 +333,8 @@ impl CheckCode {
CheckCode::U001 => "U001",
CheckCode::U002 => "U002",
CheckCode::U003 => "U003",
// Refactor
CheckCode::R001 => "R001",
CheckCode::R002 => "R002",
CheckCode::U004 => "U004",
CheckCode::U005 => "U005",
// Meta
CheckCode::M001 => "M001",
}
@@ -420,9 +416,8 @@ impl CheckCode {
CheckCode::U001 => CheckKind::UselessMetaclassType,
CheckCode::U002 => CheckKind::UnnecessaryAbspath,
CheckCode::U003 => CheckKind::TypeOfPrimitive(Primitive::Str),
// Refactor
CheckCode::R001 => CheckKind::UselessObjectInheritance("...".to_string()),
CheckCode::R002 => CheckKind::NoAssertEquals,
CheckCode::U004 => CheckKind::UselessObjectInheritance("...".to_string()),
CheckCode::U005 => CheckKind::NoAssertEquals,
// Meta
CheckCode::M001 => CheckKind::UnusedNOQA(None),
}
@@ -504,7 +499,6 @@ pub enum CheckKind {
TypeOfPrimitive(Primitive),
UnnecessaryAbspath,
UselessMetaclassType,
// Refactor
NoAssertEquals,
UselessObjectInheritance(String),
// Meta
@@ -575,7 +569,6 @@ impl CheckKind {
CheckKind::TypeOfPrimitive(_) => "TypeOfPrimitive",
CheckKind::UnnecessaryAbspath => "UnnecessaryAbspath",
CheckKind::UselessMetaclassType => "UselessMetaclassType",
// Refactor
CheckKind::NoAssertEquals => "NoAssertEquals",
CheckKind::UselessObjectInheritance(_) => "UselessObjectInheritance",
// Meta
@@ -646,9 +639,8 @@ impl CheckKind {
CheckKind::TypeOfPrimitive(_) => &CheckCode::U003,
CheckKind::UnnecessaryAbspath => &CheckCode::U002,
CheckKind::UselessMetaclassType => &CheckCode::U001,
// Refactor
CheckKind::NoAssertEquals => &CheckCode::R002,
CheckKind::UselessObjectInheritance(_) => &CheckCode::R001,
CheckKind::NoAssertEquals => &CheckCode::U005,
CheckKind::UselessObjectInheritance(_) => &CheckCode::U004,
// Meta
CheckKind::UnusedNOQA(_) => &CheckCode::M001,
}
@@ -823,7 +815,6 @@ impl CheckKind {
"`abspath(__file__)` is unnecessary in Python 3.9 and later".to_string()
}
CheckKind::UselessMetaclassType => "`__metaclass__ = type` is implied".to_string(),
// Refactor
CheckKind::NoAssertEquals => {
"`assertEquals` is deprecated, use `assertEqual` instead".to_string()
}

View File

@@ -690,30 +690,6 @@ mod tests {
Ok(())
}
#[test]
fn r001() -> Result<()> {
let mut checks = check_path(
Path::new("./resources/test/fixtures/R001.py"),
&settings::Settings::for_rule(CheckCode::R001),
&fixer::Mode::Generate,
)?;
checks.sort_by_key(|check| check.location);
insta::assert_yaml_snapshot!(checks);
Ok(())
}
#[test]
fn r002() -> Result<()> {
let mut checks = check_path(
Path::new("./resources/test/fixtures/R002.py"),
&settings::Settings::for_rule(CheckCode::R002),
&fixer::Mode::Generate,
)?;
checks.sort_by_key(|check| check.location);
insta::assert_yaml_snapshot!(checks);
Ok(())
}
#[test]
fn init() -> Result<()> {
let mut checks = check_path(
@@ -905,4 +881,28 @@ mod tests {
insta::assert_yaml_snapshot!(checks);
Ok(())
}
#[test]
fn u004() -> Result<()> {
let mut checks = check_path(
Path::new("./resources/test/fixtures/U004.py"),
&settings::Settings::for_rule(CheckCode::U004),
&fixer::Mode::Generate,
)?;
checks.sort_by_key(|check| check.location);
insta::assert_yaml_snapshot!(checks);
Ok(())
}
#[test]
fn u005() -> Result<()> {
let mut checks = check_path(
Path::new("./resources/test/fixtures/U005.py"),
&settings::Settings::for_rule(CheckCode::U005),
&fixer::Mode::Generate,
)?;
checks.sort_by_key(|check| check.location);
insta::assert_yaml_snapshot!(checks);
Ok(())
}
}