Skip to content

Commit 8d9fadf

Browse files
[flake8-builtins] Remove builtins- prefix from option names (#16092)
## Summary Resolves #15368. The following options have been renamed: * `builtins-allowed-modules` &rarr; `allowed-modules` * `builtins-ignorelist` &rarr; `ignorelist` * `builtins-strict-checking` &rarr; `strict-checking` To preserve compatibility, the old names are kept as Serde aliases. ## Test Plan `cargo nextest run` and `cargo insta test`. --------- Co-authored-by: Micha Reiser <[email protected]>
1 parent dbde8d8 commit 8d9fadf

13 files changed

+196
-60
lines changed

crates/ruff/tests/lint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ fn create_a005_module_structure(tempdir: &TempDir) -> Result<()> {
24702470
Ok(())
24712471
}
24722472

2473-
/// Test A005 with `builtins-strict-checking = true`
2473+
/// Test A005 with `strict-checking = true`
24742474
#[test]
24752475
fn a005_module_shadowing_strict() -> Result<()> {
24762476
let tempdir = TempDir::new()?;
@@ -2482,7 +2482,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
24822482
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
24832483
.args(STDIN_BASE_OPTIONS)
24842484
.arg("--config")
2485-
.arg(r#"lint.flake8-builtins.builtins-strict-checking = true"#)
2485+
.arg(r#"lint.flake8-builtins.strict-checking = true"#)
24862486
.args(["--select", "A005"])
24872487
.current_dir(tempdir.path()),
24882488
@r"
@@ -2504,7 +2504,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
25042504
Ok(())
25052505
}
25062506

2507-
/// Test A005 with `builtins-strict-checking = false`
2507+
/// Test A005 with `strict-checking = false`
25082508
#[test]
25092509
fn a005_module_shadowing_non_strict() -> Result<()> {
25102510
let tempdir = TempDir::new()?;
@@ -2516,7 +2516,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
25162516
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
25172517
.args(STDIN_BASE_OPTIONS)
25182518
.arg("--config")
2519-
.arg(r#"lint.flake8-builtins.builtins-strict-checking = false"#)
2519+
.arg(r#"lint.flake8-builtins.strict-checking = false"#)
25202520
.args(["--select", "A005"])
25212521
.current_dir(tempdir.path()),
25222522
@r"
@@ -2535,7 +2535,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
25352535
Ok(())
25362536
}
25372537

2538-
/// Test A005 with `builtins-strict-checking` unset
2538+
/// Test A005 with `strict-checking` unset
25392539
/// TODO(brent) This should currently match the strict version, but after the next minor
25402540
/// release it will match the non-strict version directly above
25412541
#[test]

crates/ruff/tests/snapshots/show_settings__display_default_settings.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ linter.flake8_bandit.check_typed_exception = false
229229
linter.flake8_bandit.extend_markup_names = []
230230
linter.flake8_bandit.allowed_markup_calls = []
231231
linter.flake8_bugbear.extend_immutable_calls = []
232-
linter.flake8_builtins.builtins_allowed_modules = []
233-
linter.flake8_builtins.builtins_ignorelist = []
234-
linter.flake8_builtins.builtins_strict_checking = true
232+
linter.flake8_builtins.allowed_modules = []
233+
linter.flake8_builtins.ignorelist = []
234+
linter.flake8_builtins.strict_checking = true
235235
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false
236236
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
237237
linter.flake8_copyright.author = none

crates/ruff_linter/src/rules/flake8_builtins/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod tests {
5353
Path::new("flake8_builtins").join(path).as_path(),
5454
&LinterSettings {
5555
flake8_builtins: flake8_builtins::settings::Settings {
56-
builtins_strict_checking: true,
56+
strict_checking: true,
5757
..Default::default()
5858
},
5959
..LinterSettings::for_rule(rule_code)
@@ -83,7 +83,7 @@ mod tests {
8383
Path::new("flake8_builtins").join(path).as_path(),
8484
&LinterSettings {
8585
flake8_builtins: flake8_builtins::settings::Settings {
86-
builtins_strict_checking: strict,
86+
strict_checking: strict,
8787
..Default::default()
8888
},
8989
..LinterSettings::for_rule(rule_code)
@@ -106,7 +106,7 @@ mod tests {
106106
&LinterSettings {
107107
src: vec![test_resource_path(src.join(path.parent().unwrap()))],
108108
flake8_builtins: flake8_builtins::settings::Settings {
109-
builtins_strict_checking: false,
109+
strict_checking: false,
110110
..Default::default()
111111
},
112112
..LinterSettings::for_rule(rule_code)
@@ -130,7 +130,7 @@ mod tests {
130130
&LinterSettings {
131131
project_root: test_resource_path(src.join(path.parent().unwrap())),
132132
flake8_builtins: flake8_builtins::settings::Settings {
133-
builtins_strict_checking: false,
133+
strict_checking: false,
134134
..Default::default()
135135
},
136136
..LinterSettings::for_rule(rule_code)
@@ -156,7 +156,7 @@ mod tests {
156156
Path::new("flake8_builtins").join(path).as_path(),
157157
&LinterSettings {
158158
flake8_builtins: super::settings::Settings {
159-
builtins_ignorelist: vec!["id".to_string(), "dir".to_string()],
159+
ignorelist: vec!["id".to_string(), "dir".to_string()],
160160
..Default::default()
161161
},
162162
..LinterSettings::for_rules(vec![rule_code])
@@ -199,8 +199,8 @@ mod tests {
199199
Path::new("flake8_builtins").join(path).as_path(),
200200
&LinterSettings {
201201
flake8_builtins: super::settings::Settings {
202-
builtins_allowed_modules: vec!["xml".to_string(), "logging".to_string()],
203-
builtins_strict_checking: true,
202+
allowed_modules: vec!["xml".to_string(), "logging".to_string()],
203+
strict_checking: true,
204204
..Default::default()
205205
},
206206
..LinterSettings::for_rules(vec![rule_code])

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_argument_shadowing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::super::helpers::shadows_builtin;
1919
/// builtin and vice versa.
2020
///
2121
/// Builtins can be marked as exceptions to this rule via the
22-
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
22+
/// [`lint.flake8-builtins.ignorelist`] configuration option.
2323
///
2424
/// ## Example
2525
/// ```python
@@ -44,7 +44,7 @@ use super::super::helpers::shadows_builtin;
4444
/// ```
4545
///
4646
/// ## Options
47-
/// - `lint.flake8-builtins.builtins-ignorelist`
47+
/// - `lint.flake8-builtins.ignorelist`
4848
///
4949
/// ## References
5050
/// - [_Is it bad practice to use a built-in function name as an attribute or method identifier?_](https://stackoverflow.com/questions/9109333/is-it-bad-practice-to-use-a-built-in-function-name-as-an-attribute-or-method-ide)
@@ -67,7 +67,7 @@ pub(crate) fn builtin_argument_shadowing(checker: &Checker, parameter: &Paramete
6767
if shadows_builtin(
6868
parameter.name(),
6969
checker.source_type,
70-
&checker.settings.flake8_builtins.builtins_ignorelist,
70+
&checker.settings.flake8_builtins.ignorelist,
7171
checker.target_version(),
7272
) {
7373
// Ignore parameters in lambda expressions.

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
3737
/// ```
3838
///
3939
/// Builtins can be marked as exceptions to this rule via the
40-
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option, or
40+
/// [`lint.flake8-builtins.ignorelist`] configuration option, or
4141
/// converted to the appropriate dunder method. Methods decorated with
4242
/// `@typing.override` or `@typing_extensions.override` are also
4343
/// ignored.
@@ -55,7 +55,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
5555
/// ```
5656
///
5757
/// ## Options
58-
/// - `lint.flake8-builtins.builtins-ignorelist`
58+
/// - `lint.flake8-builtins.ignorelist`
5959
#[derive(ViolationMetadata)]
6060
pub(crate) struct BuiltinAttributeShadowing {
6161
kind: Kind,
@@ -98,7 +98,7 @@ pub(crate) fn builtin_attribute_shadowing(
9898
if shadows_builtin(
9999
name,
100100
checker.source_type,
101-
&checker.settings.flake8_builtins.builtins_ignorelist,
101+
&checker.settings.flake8_builtins.ignorelist,
102102
checker.target_version(),
103103
) {
104104
// Ignore explicit overrides.

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_import_shadowing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
1414
/// as readers may mistake the variable for the builtin and vice versa.
1515
///
1616
/// Builtins can be marked as exceptions to this rule via the
17-
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
17+
/// [`lint.flake8-builtins.ignorelist`] configuration option.
1818
///
1919
/// ## Example
2020
/// ```python
@@ -38,7 +38,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
3838
/// ```
3939
///
4040
/// ## Options
41-
/// - `lint.flake8-builtins.builtins-ignorelist`
41+
/// - `lint.flake8-builtins.ignorelist`
4242
/// - `target-version`
4343
///
4444
#[derive(ViolationMetadata)]
@@ -60,7 +60,7 @@ pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) {
6060
if shadows_builtin(
6161
name.as_str(),
6262
checker.source_type,
63-
&checker.settings.flake8_builtins.builtins_ignorelist,
63+
&checker.settings.flake8_builtins.ignorelist,
6464
checker.target_version(),
6565
) {
6666
checker.report_diagnostic(Diagnostic::new(

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_lambda_argument_shadowing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
1616
/// builtin, and vice versa.
1717
///
1818
/// Builtins can be marked as exceptions to this rule via the
19-
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
19+
/// [`lint.flake8-builtins.ignorelist`] configuration option.
2020
///
2121
/// ## Options
22-
/// - `lint.flake8-builtins.builtins-ignorelist`
22+
/// - `lint.flake8-builtins.ignorelist`
2323
#[derive(ViolationMetadata)]
2424
pub(crate) struct BuiltinLambdaArgumentShadowing {
2525
name: String,
@@ -43,7 +43,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &Expr
4343
if shadows_builtin(
4444
name,
4545
checker.source_type,
46-
&checker.settings.flake8_builtins.builtins_ignorelist,
46+
&checker.settings.flake8_builtins.ignorelist,
4747
checker.target_version(),
4848
) {
4949
checker.report_diagnostic(Diagnostic::new(

crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_variable_shadowing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
1717
/// builtin and vice versa.
1818
///
1919
/// Builtins can be marked as exceptions to this rule via the
20-
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
20+
/// [`lint.flake8-builtins.ignorelist`] configuration option.
2121
///
2222
/// ## Example
2323
/// ```python
@@ -40,7 +40,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
4040
/// ```
4141
///
4242
/// ## Options
43-
/// - `lint.flake8-builtins.builtins-ignorelist`
43+
/// - `lint.flake8-builtins.ignorelist`
4444
///
4545
/// ## References
4646
/// - [_Why is it a bad idea to name a variable `id` in Python?_](https://stackoverflow.com/questions/77552/id-is-a-bad-variable-name-in-python)
@@ -71,7 +71,7 @@ pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: T
7171
if shadows_builtin(
7272
name,
7373
checker.source_type,
74-
&checker.settings.flake8_builtins.builtins_ignorelist,
74+
&checker.settings.flake8_builtins.ignorelist,
7575
checker.target_version(),
7676
) {
7777
checker.report_diagnostic(Diagnostic::new(

crates/ruff_linter/src/rules/flake8_builtins/rules/stdlib_module_shadowing.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ use crate::settings::LinterSettings;
2121
/// standard-library module and vice versa.
2222
///
2323
/// Standard-library modules can be marked as exceptions to this rule via the
24-
/// [`lint.flake8-builtins.builtins-allowed-modules`] configuration option.
24+
/// [`lint.flake8-builtins.allowed-modules`] configuration option.
2525
///
2626
/// By default, only the last component of the module name is considered, so `logging.py`,
2727
/// `utils/logging.py`, and `utils/logging/__init__.py` would all clash with the builtin `logging`
28-
/// module. With the [`lint.flake8-builtins.builtins-strict-checking`] option set to `false`, the
29-
/// module path is considered, so only a top-level `logging.py` or `logging/__init__.py` will
30-
/// trigger the rule and `utils/logging.py`, for example, would not. In preview mode, the default
31-
/// value of [`lint.flake8-builtins.builtins-strict-checking`] is `false` rather than `true` in
32-
/// stable mode.
28+
/// module. With the [`lint.flake8-builtins.strict-checking`] option set to `false`, the module
29+
/// path is considered, so only a top-level `logging.py` or `logging/__init__.py` will trigger the
30+
/// rule and `utils/logging.py`, for example, would not. In preview mode, the default value of
31+
/// [`lint.flake8-builtins.strict-checking`] is `false` rather than `true` in stable mode.
3332
///
3433
/// This rule is not applied to stub files, as the name of a stub module is out
3534
/// of the control of the author of the stub file. Instead, a stub should aim to
@@ -50,8 +49,8 @@ use crate::settings::LinterSettings;
5049
/// ```
5150
///
5251
/// ## Options
53-
/// - `lint.flake8-builtins.builtins-allowed-modules`
54-
/// - `lint.flake8-builtins.builtins-strict-checking`
52+
/// - `lint.flake8-builtins.allowed-modules`
53+
/// - `lint.flake8-builtins.strict-checking`
5554
#[derive(ViolationMetadata)]
5655
pub(crate) struct StdlibModuleShadowing {
5756
name: String,
@@ -104,7 +103,7 @@ pub(crate) fn stdlib_module_shadowing(
104103
}
105104

106105
// not allowed generally, but check for a parent in non-strict mode
107-
if !settings.flake8_builtins.builtins_strict_checking && components.next().is_some() {
106+
if !settings.flake8_builtins.strict_checking && components.next().is_some() {
108107
return None;
109108
}
110109

@@ -136,7 +135,7 @@ fn is_allowed_module(settings: &LinterSettings, version: PythonVersion, module:
136135

137136
if settings
138137
.flake8_builtins
139-
.builtins_allowed_modules
138+
.allowed_modules
140139
.iter()
141140
.any(|allowed_module| allowed_module == module)
142141
{

crates/ruff_linter/src/rules/flake8_builtins/settings.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ use std::fmt::{Display, Formatter};
66

77
#[derive(Debug, Clone, Default, CacheKey)]
88
pub struct Settings {
9-
pub builtins_ignorelist: Vec<String>,
10-
pub builtins_allowed_modules: Vec<String>,
11-
pub builtins_strict_checking: bool,
9+
pub ignorelist: Vec<String>,
10+
pub allowed_modules: Vec<String>,
11+
pub strict_checking: bool,
1212
}
1313

1414
impl Settings {
1515
pub fn new(preview: PreviewMode) -> Self {
1616
Self {
17-
builtins_ignorelist: Vec::new(),
18-
builtins_allowed_modules: Vec::new(),
19-
builtins_strict_checking: preview.is_disabled(),
17+
ignorelist: Vec::new(),
18+
allowed_modules: Vec::new(),
19+
strict_checking: preview.is_disabled(),
2020
}
2121
}
2222
}
@@ -27,9 +27,9 @@ impl Display for Settings {
2727
formatter = f,
2828
namespace = "linter.flake8_builtins",
2929
fields = [
30-
self.builtins_allowed_modules | array,
31-
self.builtins_ignorelist | array,
32-
self.builtins_strict_checking,
30+
self.allowed_modules | array,
31+
self.ignorelist | array,
32+
self.strict_checking,
3333
]
3434
}
3535
Ok(())

0 commit comments

Comments
 (0)