Skip to content

Commit

Permalink
[flake8-builtins] Remove builtins- prefix from option names
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Feb 11, 2025
1 parent df1d430 commit 56895d5
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 52 deletions.
10 changes: 5 additions & 5 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ fn create_a005_module_structure(tempdir: &TempDir) -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking = true`
/// Test A005 with `strict-checking = true`
#[test]
fn a005_module_shadowing_strict() -> Result<()> {
let tempdir = TempDir::new()?;
Expand All @@ -2330,7 +2330,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = true"#)
.arg(r#"lint.flake8-builtins.strict-checking = true"#)
.args(["--select", "A005"])
.current_dir(tempdir.path()),
@r"
Expand All @@ -2352,7 +2352,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking = false`
/// Test A005 with `strict-checking = false`
#[test]
fn a005_module_shadowing_non_strict() -> Result<()> {
let tempdir = TempDir::new()?;
Expand All @@ -2364,7 +2364,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = false"#)
.arg(r#"lint.flake8-builtins.strict-checking = false"#)
.args(["--select", "A005"])
.current_dir(tempdir.path()),
@r"
Expand All @@ -2383,7 +2383,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
Ok(())
}

/// Test A005 with `builtins-strict-checking` unset
/// Test A005 with `strict-checking` unset
/// TODO(brent) This should currently match the strict version, but after the next minor
/// release it will match the non-strict version directly above
#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ linter.flake8_bandit.hardcoded_tmp_directory = [
]
linter.flake8_bandit.check_typed_exception = false
linter.flake8_bugbear.extend_immutable_calls = []
linter.flake8_builtins.builtins_allowed_modules = []
linter.flake8_builtins.builtins_ignorelist = []
linter.flake8_builtins.builtins_strict_checking = true
linter.flake8_builtins.allowed_modules = []
linter.flake8_builtins.ignorelist = []
linter.flake8_builtins.strict_checking = true
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
linter.flake8_copyright.author = none
Expand Down
14 changes: 7 additions & 7 deletions crates/ruff_linter/src/rules/flake8_builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings {
flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: true,
strict_checking: true,
..Default::default()
},
..LinterSettings::for_rule(rule_code)
Expand Down Expand Up @@ -83,7 +83,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings {
flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: strict,
strict_checking: strict,
..Default::default()
},
..LinterSettings::for_rule(rule_code)
Expand All @@ -106,7 +106,7 @@ mod tests {
&LinterSettings {
src: vec![test_resource_path(src.join(path.parent().unwrap()))],
flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: false,
strict_checking: false,
..Default::default()
},
..LinterSettings::for_rule(rule_code)
Expand All @@ -130,7 +130,7 @@ mod tests {
&LinterSettings {
project_root: test_resource_path(src.join(path.parent().unwrap())),
flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: false,
strict_checking: false,
..Default::default()
},
..LinterSettings::for_rule(rule_code)
Expand All @@ -156,7 +156,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings {
flake8_builtins: super::settings::Settings {
builtins_ignorelist: vec!["id".to_string(), "dir".to_string()],
ignorelist: vec!["id".to_string(), "dir".to_string()],
..Default::default()
},
..LinterSettings::for_rules(vec![rule_code])
Expand Down Expand Up @@ -199,8 +199,8 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings {
flake8_builtins: super::settings::Settings {
builtins_allowed_modules: vec!["xml".to_string(), "logging".to_string()],
builtins_strict_checking: true,
allowed_modules: vec!["xml".to_string(), "logging".to_string()],
strict_checking: true,
..Default::default()
},
..LinterSettings::for_rules(vec![rule_code])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::super::helpers::shadows_builtin;
/// builtin and vice versa.
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
/// [`lint.flake8-builtins.ignorelist`] configuration option.
///
/// ## Example
/// ```python
Expand All @@ -44,7 +44,7 @@ use super::super::helpers::shadows_builtin;
/// ```
///
/// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist`
/// - `lint.flake8-builtins.ignorelist`
///
/// ## References
/// - [_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)
Expand All @@ -67,7 +67,7 @@ pub(crate) fn builtin_argument_shadowing(checker: &Checker, parameter: &Paramete
if shadows_builtin(
parameter.name(),
checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist,
&checker.settings.flake8_builtins.ignorelist,
checker.settings.target_version,
) {
// Ignore parameters in lambda expressions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ```
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option, or
/// [`lint.flake8-builtins.ignorelist`] configuration option, or
/// converted to the appropriate dunder method. Methods decorated with
/// `@typing.override` or `@typing_extensions.override` are also
/// ignored.
Expand All @@ -55,7 +55,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ```
///
/// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist`
/// - `lint.flake8-builtins.ignorelist`
#[derive(ViolationMetadata)]
pub(crate) struct BuiltinAttributeShadowing {
kind: Kind,
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) fn builtin_attribute_shadowing(
if shadows_builtin(
name,
checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist,
&checker.settings.flake8_builtins.ignorelist,
checker.settings.target_version,
) {
// Ignore explicit overrides.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// as readers may mistake the variable for the builtin and vice versa.
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
/// [`lint.flake8-builtins.ignorelist`] configuration option.
///
/// ## Example
/// ```python
Expand All @@ -38,7 +38,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ```
///
/// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist`
/// - `lint.flake8-builtins.ignorelist`
/// - `target-version`
///
#[derive(ViolationMetadata)]
Expand All @@ -60,7 +60,7 @@ pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) {
if shadows_builtin(
name.as_str(),
checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist,
&checker.settings.flake8_builtins.ignorelist,
checker.settings.target_version,
) {
checker.report_diagnostic(Diagnostic::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// builtin, and vice versa.
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
/// [`lint.flake8-builtins.ignorelist`] configuration option.
///
/// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist`
/// - `lint.flake8-builtins.ignorelist`
#[derive(ViolationMetadata)]
pub(crate) struct BuiltinLambdaArgumentShadowing {
name: String,
Expand All @@ -43,7 +43,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &Expr
if shadows_builtin(
name,
checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist,
&checker.settings.flake8_builtins.ignorelist,
checker.settings.target_version,
) {
checker.report_diagnostic(Diagnostic::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// builtin and vice versa.
///
/// Builtins can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-ignorelist`] configuration option.
/// [`lint.flake8-builtins.ignorelist`] configuration option.
///
/// ## Example
/// ```python
Expand All @@ -40,7 +40,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ```
///
/// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist`
/// - `lint.flake8-builtins.ignorelist`
///
/// ## References
/// - [_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)
Expand All @@ -62,7 +62,7 @@ pub(crate) fn builtin_variable_shadowing(checker: &Checker, name: &str, range: T
if shadows_builtin(
name,
checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist,
&checker.settings.flake8_builtins.ignorelist,
checker.settings.target_version,
) {
checker.report_diagnostic(Diagnostic::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::settings::LinterSettings;
/// standard-library module and vice versa.
///
/// Standard-library modules can be marked as exceptions to this rule via the
/// [`lint.flake8-builtins.builtins-allowed-modules`] configuration option.
/// [`lint.flake8-builtins.allowed-modules`] configuration option.
///
/// This rule is not applied to stub files, as the name of a stub module is out
/// of the control of the author of the stub file. Instead, a stub should aim to
Expand All @@ -42,7 +42,7 @@ use crate::settings::LinterSettings;
/// ```
///
/// ## Options
/// - `lint.flake8-builtins.builtins-allowed-modules`
/// - `lint.flake8-builtins.allowed-modules`
#[derive(ViolationMetadata)]
pub(crate) struct StdlibModuleShadowing {
name: String,
Expand Down Expand Up @@ -94,7 +94,7 @@ pub(crate) fn stdlib_module_shadowing(
}

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

Expand Down Expand Up @@ -129,7 +129,7 @@ fn is_allowed_module(settings: &LinterSettings, module: &str) -> bool {

if settings
.flake8_builtins
.builtins_allowed_modules
.allowed_modules
.iter()
.any(|allowed_module| allowed_module == module)
{
Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_linter/src/rules/flake8_builtins/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Default, CacheKey)]
pub struct Settings {
pub builtins_ignorelist: Vec<String>,
pub builtins_allowed_modules: Vec<String>,
pub builtins_strict_checking: bool,
pub ignorelist: Vec<String>,
pub allowed_modules: Vec<String>,
pub strict_checking: bool,
}

impl Settings {
pub fn new(preview: PreviewMode) -> Self {
Self {
builtins_ignorelist: Vec::new(),
builtins_allowed_modules: Vec::new(),
builtins_strict_checking: preview.is_disabled(),
ignorelist: Vec::new(),
allowed_modules: Vec::new(),
strict_checking: preview.is_disabled(),
}
}
}
Expand All @@ -27,9 +27,9 @@ impl Display for Settings {
formatter = f,
namespace = "linter.flake8_builtins",
fields = [
self.builtins_allowed_modules | array,
self.builtins_ignorelist | array,
self.builtins_strict_checking,
self.allowed_modules | array,
self.ignorelist | array,
self.strict_checking,
]
}
Ok(())
Expand Down
Loading

0 comments on commit 56895d5

Please sign in to comment.