mirror of https://github.com/astral-sh/ruff
Disallow rule names ending in *-used
This commit is contained in:
parent
bfbde537af
commit
1cbe48522e
|
|
@ -664,7 +664,7 @@ For more, see [Pyflakes](https://pypi.org/project/pyflakes/) on PyPI.
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| F401 | unused-import | `{name}` imported but unused; consider adding to `__all__` or using a redundant alias | 🛠 |
|
| F401 | unused-import | `{name}` imported but unused; consider adding to `__all__` or using a redundant alias | 🛠 |
|
||||||
| F402 | import-shadowed-by-loop-var | Import `{name}` from line {line} shadowed by loop variable | |
|
| F402 | import-shadowed-by-loop-var | Import `{name}` from line {line} shadowed by loop variable | |
|
||||||
| F403 | import-star-used | `from {name} import *` used; unable to detect undefined names | |
|
| F403 | import-star | `from {name} import *` used; unable to detect undefined names | |
|
||||||
| F404 | late-future-import | `from __future__` imports must occur at the beginning of the file | |
|
| F404 | late-future-import | `from __future__` imports must occur at the beginning of the file | |
|
||||||
| F405 | import-star-usage | `{name}` may be undefined, or defined from star imports: {sources} | |
|
| F405 | import-star-usage | `{name}` may be undefined, or defined from star imports: {sources} | |
|
||||||
| F406 | import-star-not-permitted | `from {name} import *` only allowed at module level | |
|
| F406 | import-star-not-permitted | `from {name} import *` only allowed at module level | |
|
||||||
|
|
@ -918,8 +918,8 @@ For more, see [flake8-bandit](https://pypi.org/project/flake8-bandit/) on PyPI.
|
||||||
|
|
||||||
| Code | Name | Message | Fix |
|
| Code | Name | Message | Fix |
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| S101 | assert-used | Use of `assert` detected | |
|
| S101 | assert | Use of `assert` detected | |
|
||||||
| S102 | exec-used | Use of `exec` detected | |
|
| S102 | exec-builtin | Use of `exec` detected | |
|
||||||
| S103 | bad-file-permissions | `os.chmod` setting a permissive mask `{mask:#o}` on file or directory | |
|
| S103 | bad-file-permissions | `os.chmod` setting a permissive mask `{mask:#o}` on file or directory | |
|
||||||
| S104 | hardcoded-bind-all-interfaces | Possible binding to all interfaces | |
|
| S104 | hardcoded-bind-all-interfaces | Possible binding to all interfaces | |
|
||||||
| S105 | hardcoded-password-string | Possible hardcoded password: "{}" | |
|
| S105 | hardcoded-password-string | Possible hardcoded password: "{}" | |
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
do-not-*
|
do-not-*
|
||||||
|
*-used
|
||||||
|
|
|
||||||
|
|
@ -1226,9 +1226,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.settings.rules.enabled(&Rule::ImportStarUsed) {
|
if self.settings.rules.enabled(&Rule::ImportStar) {
|
||||||
self.diagnostics.push(Diagnostic::new(
|
self.diagnostics.push(Diagnostic::new(
|
||||||
pyflakes::rules::ImportStarUsed {
|
pyflakes::rules::ImportStar {
|
||||||
name: helpers::format_import_from(
|
name: helpers::format_import_from(
|
||||||
level.as_ref(),
|
level.as_ref(),
|
||||||
module.as_deref(),
|
module.as_deref(),
|
||||||
|
|
@ -1536,7 +1536,7 @@ where
|
||||||
msg.as_ref().map(|expr| &**expr),
|
msg.as_ref().map(|expr| &**expr),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.settings.rules.enabled(&Rule::AssertUsed) {
|
if self.settings.rules.enabled(&Rule::Assert) {
|
||||||
self.diagnostics
|
self.diagnostics
|
||||||
.push(flake8_bandit::rules::assert_used(stmt));
|
.push(flake8_bandit::rules::assert_used(stmt));
|
||||||
}
|
}
|
||||||
|
|
@ -2369,7 +2369,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// flake8-bandit
|
// flake8-bandit
|
||||||
if self.settings.rules.enabled(&Rule::ExecUsed) {
|
if self.settings.rules.enabled(&Rule::ExecBuiltin) {
|
||||||
if let Some(diagnostic) = flake8_bandit::rules::exec_used(expr, func) {
|
if let Some(diagnostic) = flake8_bandit::rules::exec_used(expr, func) {
|
||||||
self.diagnostics.push(diagnostic);
|
self.diagnostics.push(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ ruff_macros::define_rule_mapping!(
|
||||||
// pyflakes
|
// pyflakes
|
||||||
F401 => rules::pyflakes::rules::UnusedImport,
|
F401 => rules::pyflakes::rules::UnusedImport,
|
||||||
F402 => rules::pyflakes::rules::ImportShadowedByLoopVar,
|
F402 => rules::pyflakes::rules::ImportShadowedByLoopVar,
|
||||||
F403 => rules::pyflakes::rules::ImportStarUsed,
|
F403 => rules::pyflakes::rules::ImportStar,
|
||||||
F404 => rules::pyflakes::rules::LateFutureImport,
|
F404 => rules::pyflakes::rules::LateFutureImport,
|
||||||
F405 => rules::pyflakes::rules::ImportStarUsage,
|
F405 => rules::pyflakes::rules::ImportStarUsage,
|
||||||
F406 => rules::pyflakes::rules::ImportStarNotPermitted,
|
F406 => rules::pyflakes::rules::ImportStarNotPermitted,
|
||||||
|
|
@ -381,8 +381,8 @@ ruff_macros::define_rule_mapping!(
|
||||||
// eradicate
|
// eradicate
|
||||||
ERA001 => rules::eradicate::rules::CommentedOutCode,
|
ERA001 => rules::eradicate::rules::CommentedOutCode,
|
||||||
// flake8-bandit
|
// flake8-bandit
|
||||||
S101 => rules::flake8_bandit::rules::AssertUsed,
|
S101 => rules::flake8_bandit::rules::Assert,
|
||||||
S102 => rules::flake8_bandit::rules::ExecUsed,
|
S102 => rules::flake8_bandit::rules::ExecBuiltin,
|
||||||
S103 => rules::flake8_bandit::rules::BadFilePermissions,
|
S103 => rules::flake8_bandit::rules::BadFilePermissions,
|
||||||
S104 => rules::flake8_bandit::rules::HardcodedBindAllInterfaces,
|
S104 => rules::flake8_bandit::rules::HardcodedBindAllInterfaces,
|
||||||
S105 => rules::flake8_bandit::rules::HardcodedPasswordString,
|
S105 => rules::flake8_bandit::rules::HardcodedPasswordString,
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ mod tests {
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use crate::test::test_path;
|
use crate::test::test_path;
|
||||||
|
|
||||||
#[test_case(Rule::AssertUsed, Path::new("S101.py"); "S101")]
|
#[test_case(Rule::Assert, Path::new("S101.py"); "S101")]
|
||||||
#[test_case(Rule::ExecUsed, Path::new("S102.py"); "S102")]
|
#[test_case(Rule::ExecBuiltin, Path::new("S102.py"); "S102")]
|
||||||
#[test_case(Rule::BadFilePermissions, Path::new("S103.py"); "S103")]
|
#[test_case(Rule::BadFilePermissions, Path::new("S103.py"); "S103")]
|
||||||
#[test_case(Rule::HardcodedBindAllInterfaces, Path::new("S104.py"); "S104")]
|
#[test_case(Rule::HardcodedBindAllInterfaces, Path::new("S104.py"); "S104")]
|
||||||
#[test_case(Rule::HardcodedPasswordString, Path::new("S105.py"); "S105")]
|
#[test_case(Rule::HardcodedPasswordString, Path::new("S105.py"); "S105")]
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use crate::registry::Diagnostic;
|
||||||
use crate::violation::Violation;
|
use crate::violation::Violation;
|
||||||
|
|
||||||
define_violation!(
|
define_violation!(
|
||||||
pub struct AssertUsed;
|
pub struct Assert;
|
||||||
);
|
);
|
||||||
impl Violation for AssertUsed {
|
impl Violation for Assert {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
format!("Use of `assert` detected")
|
format!("Use of `assert` detected")
|
||||||
|
|
@ -18,7 +18,7 @@ impl Violation for AssertUsed {
|
||||||
/// S101
|
/// S101
|
||||||
pub fn assert_used(stmt: &Located<StmtKind>) -> Diagnostic {
|
pub fn assert_used(stmt: &Located<StmtKind>) -> Diagnostic {
|
||||||
Diagnostic::new(
|
Diagnostic::new(
|
||||||
AssertUsed,
|
Assert,
|
||||||
Range::new(stmt.location, stmt.location.with_col_offset("assert".len())),
|
Range::new(stmt.location, stmt.location.with_col_offset("assert".len())),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ use crate::registry::Diagnostic;
|
||||||
use crate::violation::Violation;
|
use crate::violation::Violation;
|
||||||
|
|
||||||
define_violation!(
|
define_violation!(
|
||||||
pub struct ExecUsed;
|
pub struct ExecBuiltin;
|
||||||
);
|
);
|
||||||
impl Violation for ExecUsed {
|
impl Violation for ExecBuiltin {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
format!("Use of `exec` detected")
|
format!("Use of `exec` detected")
|
||||||
|
|
@ -23,5 +23,5 @@ pub fn exec_used(expr: &Expr, func: &Expr) -> Option<Diagnostic> {
|
||||||
if id != "exec" {
|
if id != "exec" {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Diagnostic::new(ExecUsed, Range::from_located(expr)))
|
Some(Diagnostic::new(ExecBuiltin, Range::from_located(expr)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
pub use assert_used::{assert_used, AssertUsed};
|
pub use assert_used::{assert_used, Assert};
|
||||||
pub use bad_file_permissions::{bad_file_permissions, BadFilePermissions};
|
pub use bad_file_permissions::{bad_file_permissions, BadFilePermissions};
|
||||||
pub use exec_used::{exec_used, ExecUsed};
|
pub use exec_used::{exec_used, ExecBuiltin};
|
||||||
pub use hardcoded_bind_all_interfaces::{
|
pub use hardcoded_bind_all_interfaces::{
|
||||||
hardcoded_bind_all_interfaces, HardcodedBindAllInterfaces,
|
hardcoded_bind_all_interfaces, HardcodedBindAllInterfaces,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_bandit/mod.rs
|
source: crates/ruff/src/rules/flake8_bandit/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
AssertUsed: ~
|
Assert: ~
|
||||||
location:
|
location:
|
||||||
row: 2
|
row: 2
|
||||||
column: 0
|
column: 0
|
||||||
|
|
@ -13,7 +13,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
AssertUsed: ~
|
Assert: ~
|
||||||
location:
|
location:
|
||||||
row: 8
|
row: 8
|
||||||
column: 4
|
column: 4
|
||||||
|
|
@ -23,7 +23,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
AssertUsed: ~
|
Assert: ~
|
||||||
location:
|
location:
|
||||||
row: 11
|
row: 11
|
||||||
column: 4
|
column: 4
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/rules/flake8_bandit/mod.rs
|
source: crates/ruff/src/rules/flake8_bandit/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
ExecUsed: ~
|
ExecBuiltin: ~
|
||||||
location:
|
location:
|
||||||
row: 3
|
row: 3
|
||||||
column: 4
|
column: 4
|
||||||
|
|
@ -13,7 +13,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ExecUsed: ~
|
ExecBuiltin: ~
|
||||||
location:
|
location:
|
||||||
row: 5
|
row: 5
|
||||||
column: 0
|
column: 0
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ mod tests {
|
||||||
#[test_case(Rule::UnusedImport, Path::new("F401_7.py"); "F401_7")]
|
#[test_case(Rule::UnusedImport, Path::new("F401_7.py"); "F401_7")]
|
||||||
#[test_case(Rule::UnusedImport, Path::new("F401_8.py"); "F401_8")]
|
#[test_case(Rule::UnusedImport, Path::new("F401_8.py"); "F401_8")]
|
||||||
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.py"); "F402")]
|
#[test_case(Rule::ImportShadowedByLoopVar, Path::new("F402.py"); "F402")]
|
||||||
#[test_case(Rule::ImportStarUsed, Path::new("F403.py"); "F403")]
|
#[test_case(Rule::ImportStar, Path::new("F403.py"); "F403")]
|
||||||
#[test_case(Rule::LateFutureImport, Path::new("F404.py"); "F404")]
|
#[test_case(Rule::LateFutureImport, Path::new("F404.py"); "F404")]
|
||||||
#[test_case(Rule::ImportStarUsage, Path::new("F405.py"); "F405")]
|
#[test_case(Rule::ImportStarUsage, Path::new("F405.py"); "F405")]
|
||||||
#[test_case(Rule::ImportStarNotPermitted, Path::new("F406.py"); "F406")]
|
#[test_case(Rule::ImportStarNotPermitted, Path::new("F406.py"); "F406")]
|
||||||
|
|
@ -460,7 +460,7 @@ mod tests {
|
||||||
// Can't find undefined names with import *.
|
// Can't find undefined names with import *.
|
||||||
flakes(
|
flakes(
|
||||||
"from fu import *; bar",
|
"from fu import *; bar",
|
||||||
&[Rule::ImportStarUsed, Rule::ImportStarUsage],
|
&[Rule::ImportStar, Rule::ImportStarUsage],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2476,7 +2476,7 @@ mod tests {
|
||||||
csc(1)
|
csc(1)
|
||||||
"#,
|
"#,
|
||||||
&[
|
&[
|
||||||
Rule::ImportStarUsed,
|
Rule::ImportStar,
|
||||||
Rule::ImportStarUsage,
|
Rule::ImportStarUsage,
|
||||||
Rule::ImportStarUsage,
|
Rule::ImportStarUsage,
|
||||||
Rule::ImportStarUsage,
|
Rule::ImportStarUsage,
|
||||||
|
|
@ -2494,7 +2494,7 @@ mod tests {
|
||||||
a = 1
|
a = 1
|
||||||
__all__ = ['a']
|
__all__ = ['a']
|
||||||
"#,
|
"#,
|
||||||
&[Rule::ImportStarUsed, Rule::UnusedImport],
|
&[Rule::ImportStar, Rule::UnusedImport],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,14 +65,14 @@ impl Violation for ImportShadowedByLoopVar {
|
||||||
}
|
}
|
||||||
|
|
||||||
define_violation!(
|
define_violation!(
|
||||||
pub struct ImportStarUsed {
|
pub struct ImportStar {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
impl Violation for ImportStarUsed {
|
impl Violation for ImportStar {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
let ImportStarUsed { name } = self;
|
let ImportStar { name } = self;
|
||||||
format!("`from {name} import *` used; unable to detect undefined names")
|
format!("`from {name} import *` used; unable to detect undefined names")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ pub use f_string_missing_placeholders::{
|
||||||
pub use forward_annotation_syntax_error::ForwardAnnotationSyntaxError;
|
pub use forward_annotation_syntax_error::ForwardAnnotationSyntaxError;
|
||||||
pub use if_tuple::{if_tuple, IfTuple};
|
pub use if_tuple::{if_tuple, IfTuple};
|
||||||
pub use imports::{
|
pub use imports::{
|
||||||
future_feature_not_defined, FutureFeatureNotDefined, ImportShadowedByLoopVar,
|
future_feature_not_defined, FutureFeatureNotDefined, ImportShadowedByLoopVar, ImportStar,
|
||||||
ImportStarNotPermitted, ImportStarUsage, ImportStarUsed, LateFutureImport, UnusedImport,
|
ImportStarNotPermitted, ImportStarUsage, LateFutureImport, UnusedImport,
|
||||||
};
|
};
|
||||||
pub use invalid_literal_comparisons::{invalid_literal_comparison, IsLiteral};
|
pub use invalid_literal_comparisons::{invalid_literal_comparison, IsLiteral};
|
||||||
pub use invalid_print_syntax::{invalid_print_syntax, InvalidPrintSyntax};
|
pub use invalid_print_syntax::{invalid_print_syntax, InvalidPrintSyntax};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
---
|
---
|
||||||
source: src/rules/pyflakes/mod.rs
|
source: crates/ruff/src/rules/pyflakes/mod.rs
|
||||||
expression: diagnostics
|
expression: diagnostics
|
||||||
---
|
---
|
||||||
- kind:
|
- kind:
|
||||||
ImportStarUsed:
|
ImportStar:
|
||||||
name: F634
|
name: F634
|
||||||
location:
|
location:
|
||||||
row: 1
|
row: 1
|
||||||
|
|
@ -14,7 +14,7 @@ expression: diagnostics
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ImportStarUsed:
|
ImportStar:
|
||||||
name: F634
|
name: F634
|
||||||
location:
|
location:
|
||||||
row: 2
|
row: 2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue