mirror of https://github.com/astral-sh/ruff
Ignore unittest methods and functions in N802 (#502)
This commit is contained in:
parent
3fc257f71b
commit
343d931ddb
|
|
@ -1,3 +1,6 @@
|
|||
import unittest
|
||||
|
||||
|
||||
def Bad():
|
||||
pass
|
||||
|
||||
|
|
@ -24,3 +27,15 @@ def _good():
|
|||
|
||||
def good_func():
|
||||
pass
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
pass
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
return super().tearDown()
|
||||
|
||||
def testTest(self):
|
||||
assert True
|
||||
|
|
|
|||
|
|
@ -21,8 +21,23 @@ pub fn invalid_class_name(class_def: &Stmt, name: &str) -> Option<Check> {
|
|||
None
|
||||
}
|
||||
|
||||
const IGNORE_NAMES: &[&str] = &[
|
||||
"setUp",
|
||||
"tearDown",
|
||||
"setUpClass",
|
||||
"tearDownClass",
|
||||
"setUpModule",
|
||||
"tearDownModule",
|
||||
"asyncSetUp",
|
||||
"asyncTearDown",
|
||||
"setUpTestData",
|
||||
"failureException",
|
||||
"longMessage",
|
||||
"maxDiff",
|
||||
];
|
||||
|
||||
pub fn invalid_function_name(func_def: &Stmt, name: &str) -> Option<Check> {
|
||||
if name.chars().any(|c| c.is_uppercase()) {
|
||||
if !is_lower(name) && !IGNORE_NAMES.contains(&name) {
|
||||
return Some(Check::new(
|
||||
CheckKind::InvalidFunctionName(name.to_string()),
|
||||
Range::from_located(func_def),
|
||||
|
|
@ -32,7 +47,7 @@ pub fn invalid_function_name(func_def: &Stmt, name: &str) -> Option<Check> {
|
|||
}
|
||||
|
||||
pub fn invalid_argument_name(location: Range, name: &str) -> Option<Check> {
|
||||
if name.chars().any(|c| c.is_uppercase()) {
|
||||
if !is_lower(name) {
|
||||
return Some(Check::new(
|
||||
CheckKind::InvalidArgumentName(name.to_string()),
|
||||
location,
|
||||
|
|
|
|||
|
|
@ -5,37 +5,46 @@ expression: checks
|
|||
- kind:
|
||||
InvalidFunctionName: Bad
|
||||
location:
|
||||
row: 1
|
||||
row: 4
|
||||
column: 1
|
||||
end_location:
|
||||
row: 5
|
||||
row: 8
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind:
|
||||
InvalidFunctionName: _Bad
|
||||
location:
|
||||
row: 5
|
||||
row: 8
|
||||
column: 1
|
||||
end_location:
|
||||
row: 9
|
||||
row: 12
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind:
|
||||
InvalidFunctionName: BAD
|
||||
location:
|
||||
row: 9
|
||||
row: 12
|
||||
column: 1
|
||||
end_location:
|
||||
row: 13
|
||||
row: 16
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind:
|
||||
InvalidFunctionName: BAD_FUNC
|
||||
location:
|
||||
row: 13
|
||||
row: 16
|
||||
column: 1
|
||||
end_location:
|
||||
row: 17
|
||||
row: 20
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind:
|
||||
InvalidFunctionName: testTest
|
||||
location:
|
||||
row: 40
|
||||
column: 5
|
||||
end_location:
|
||||
row: 42
|
||||
column: 1
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue