[`flake8-builtins`] Remove `builtins-` prefix from option names (#16092)

## Summary

Resolves #15368.

The following options have been renamed:

* `builtins-allowed-modules` → `allowed-modules`
* `builtins-ignorelist` → `ignorelist`
* `builtins-strict-checking` → `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 <micha@reiser.io>
This commit is contained in:
InSync 2025-03-11 19:29:19 +07:00 committed by Micha Reiser
parent c0b1413ecd
commit 24ec94562c
13 changed files with 196 additions and 60 deletions

View File

@ -2470,7 +2470,7 @@ fn create_a005_module_structure(tempdir: &TempDir) -> Result<()> {
Ok(()) Ok(())
} }
/// Test A005 with `builtins-strict-checking = true` /// Test A005 with `strict-checking = true`
#[test] #[test]
fn a005_module_shadowing_strict() -> Result<()> { fn a005_module_shadowing_strict() -> Result<()> {
let tempdir = TempDir::new()?; let tempdir = TempDir::new()?;
@ -2482,7 +2482,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS) .args(STDIN_BASE_OPTIONS)
.arg("--config") .arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = true"#) .arg(r#"lint.flake8-builtins.strict-checking = true"#)
.args(["--select", "A005"]) .args(["--select", "A005"])
.current_dir(tempdir.path()), .current_dir(tempdir.path()),
@r" @r"
@ -2504,7 +2504,7 @@ fn a005_module_shadowing_strict() -> Result<()> {
Ok(()) Ok(())
} }
/// Test A005 with `builtins-strict-checking = false` /// Test A005 with `strict-checking = false`
#[test] #[test]
fn a005_module_shadowing_non_strict() -> Result<()> { fn a005_module_shadowing_non_strict() -> Result<()> {
let tempdir = TempDir::new()?; let tempdir = TempDir::new()?;
@ -2516,7 +2516,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS) .args(STDIN_BASE_OPTIONS)
.arg("--config") .arg("--config")
.arg(r#"lint.flake8-builtins.builtins-strict-checking = false"#) .arg(r#"lint.flake8-builtins.strict-checking = false"#)
.args(["--select", "A005"]) .args(["--select", "A005"])
.current_dir(tempdir.path()), .current_dir(tempdir.path()),
@r" @r"
@ -2535,7 +2535,7 @@ fn a005_module_shadowing_non_strict() -> Result<()> {
Ok(()) 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 /// TODO(brent) This should currently match the strict version, but after the next minor
/// release it will match the non-strict version directly above /// release it will match the non-strict version directly above
#[test] #[test]

View File

@ -229,9 +229,9 @@ linter.flake8_bandit.check_typed_exception = false
linter.flake8_bandit.extend_markup_names = [] linter.flake8_bandit.extend_markup_names = []
linter.flake8_bandit.allowed_markup_calls = [] linter.flake8_bandit.allowed_markup_calls = []
linter.flake8_bugbear.extend_immutable_calls = [] linter.flake8_bugbear.extend_immutable_calls = []
linter.flake8_builtins.builtins_allowed_modules = [] linter.flake8_builtins.allowed_modules = []
linter.flake8_builtins.builtins_ignorelist = [] linter.flake8_builtins.ignorelist = []
linter.flake8_builtins.builtins_strict_checking = true linter.flake8_builtins.strict_checking = true
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false 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.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
linter.flake8_copyright.author = none linter.flake8_copyright.author = none

View File

@ -53,7 +53,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(), Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings { &LinterSettings {
flake8_builtins: flake8_builtins::settings::Settings { flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: true, strict_checking: true,
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rule(rule_code) ..LinterSettings::for_rule(rule_code)
@ -83,7 +83,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(), Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings { &LinterSettings {
flake8_builtins: flake8_builtins::settings::Settings { flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: strict, strict_checking: strict,
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rule(rule_code) ..LinterSettings::for_rule(rule_code)
@ -106,7 +106,7 @@ mod tests {
&LinterSettings { &LinterSettings {
src: vec![test_resource_path(src.join(path.parent().unwrap()))], src: vec![test_resource_path(src.join(path.parent().unwrap()))],
flake8_builtins: flake8_builtins::settings::Settings { flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: false, strict_checking: false,
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rule(rule_code) ..LinterSettings::for_rule(rule_code)
@ -130,7 +130,7 @@ mod tests {
&LinterSettings { &LinterSettings {
project_root: test_resource_path(src.join(path.parent().unwrap())), project_root: test_resource_path(src.join(path.parent().unwrap())),
flake8_builtins: flake8_builtins::settings::Settings { flake8_builtins: flake8_builtins::settings::Settings {
builtins_strict_checking: false, strict_checking: false,
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rule(rule_code) ..LinterSettings::for_rule(rule_code)
@ -156,7 +156,7 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(), Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings { &LinterSettings {
flake8_builtins: super::settings::Settings { flake8_builtins: super::settings::Settings {
builtins_ignorelist: vec!["id".to_string(), "dir".to_string()], ignorelist: vec!["id".to_string(), "dir".to_string()],
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rules(vec![rule_code]) ..LinterSettings::for_rules(vec![rule_code])
@ -199,8 +199,8 @@ mod tests {
Path::new("flake8_builtins").join(path).as_path(), Path::new("flake8_builtins").join(path).as_path(),
&LinterSettings { &LinterSettings {
flake8_builtins: super::settings::Settings { flake8_builtins: super::settings::Settings {
builtins_allowed_modules: vec!["xml".to_string(), "logging".to_string()], allowed_modules: vec!["xml".to_string(), "logging".to_string()],
builtins_strict_checking: true, strict_checking: true,
..Default::default() ..Default::default()
}, },
..LinterSettings::for_rules(vec![rule_code]) ..LinterSettings::for_rules(vec![rule_code])

View File

@ -19,7 +19,7 @@ use super::super::helpers::shadows_builtin;
/// builtin and vice versa. /// builtin and vice versa.
/// ///
/// Builtins can be marked as exceptions to this rule via the /// 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 /// ## Example
/// ```python /// ```python
@ -44,7 +44,7 @@ use super::super::helpers::shadows_builtin;
/// ``` /// ```
/// ///
/// ## Options /// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist` /// - `lint.flake8-builtins.ignorelist`
/// ///
/// ## References /// ## 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) /// - [_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
if shadows_builtin( if shadows_builtin(
parameter.name(), parameter.name(),
checker.source_type, checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist, &checker.settings.flake8_builtins.ignorelist,
checker.target_version(), checker.target_version(),
) { ) {
// Ignore parameters in lambda expressions. // Ignore parameters in lambda expressions.

View File

@ -37,7 +37,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ``` /// ```
/// ///
/// Builtins can be marked as exceptions to this rule via the /// 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 /// converted to the appropriate dunder method. Methods decorated with
/// `@typing.override` or `@typing_extensions.override` are also /// `@typing.override` or `@typing_extensions.override` are also
/// ignored. /// ignored.
@ -55,7 +55,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ``` /// ```
/// ///
/// ## Options /// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist` /// - `lint.flake8-builtins.ignorelist`
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BuiltinAttributeShadowing { pub(crate) struct BuiltinAttributeShadowing {
kind: Kind, kind: Kind,
@ -98,7 +98,7 @@ pub(crate) fn builtin_attribute_shadowing(
if shadows_builtin( if shadows_builtin(
name, name,
checker.source_type, checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist, &checker.settings.flake8_builtins.ignorelist,
checker.target_version(), checker.target_version(),
) { ) {
// Ignore explicit overrides. // Ignore explicit overrides.

View File

@ -14,7 +14,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// as readers may mistake the variable for the builtin and vice versa. /// as readers may mistake the variable for the builtin and vice versa.
/// ///
/// Builtins can be marked as exceptions to this rule via the /// 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 /// ## Example
/// ```python /// ```python
@ -38,7 +38,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ``` /// ```
/// ///
/// ## Options /// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist` /// - `lint.flake8-builtins.ignorelist`
/// - `target-version` /// - `target-version`
/// ///
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
@ -60,7 +60,7 @@ pub(crate) fn builtin_import_shadowing(checker: &Checker, alias: &Alias) {
if shadows_builtin( if shadows_builtin(
name.as_str(), name.as_str(),
checker.source_type, checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist, &checker.settings.flake8_builtins.ignorelist,
checker.target_version(), checker.target_version(),
) { ) {
checker.report_diagnostic(Diagnostic::new( checker.report_diagnostic(Diagnostic::new(

View File

@ -16,10 +16,10 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// builtin, and vice versa. /// builtin, and vice versa.
/// ///
/// Builtins can be marked as exceptions to this rule via the /// 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 /// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist` /// - `lint.flake8-builtins.ignorelist`
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct BuiltinLambdaArgumentShadowing { pub(crate) struct BuiltinLambdaArgumentShadowing {
name: String, name: String,
@ -43,7 +43,7 @@ pub(crate) fn builtin_lambda_argument_shadowing(checker: &Checker, lambda: &Expr
if shadows_builtin( if shadows_builtin(
name, name,
checker.source_type, checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist, &checker.settings.flake8_builtins.ignorelist,
checker.target_version(), checker.target_version(),
) { ) {
checker.report_diagnostic(Diagnostic::new( checker.report_diagnostic(Diagnostic::new(

View File

@ -17,7 +17,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// builtin and vice versa. /// builtin and vice versa.
/// ///
/// Builtins can be marked as exceptions to this rule via the /// 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 /// ## Example
/// ```python /// ```python
@ -40,7 +40,7 @@ use crate::rules::flake8_builtins::helpers::shadows_builtin;
/// ``` /// ```
/// ///
/// ## Options /// ## Options
/// - `lint.flake8-builtins.builtins-ignorelist` /// - `lint.flake8-builtins.ignorelist`
/// ///
/// ## References /// ## 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) /// - [_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
if shadows_builtin( if shadows_builtin(
name, name,
checker.source_type, checker.source_type,
&checker.settings.flake8_builtins.builtins_ignorelist, &checker.settings.flake8_builtins.ignorelist,
checker.target_version(), checker.target_version(),
) { ) {
checker.report_diagnostic(Diagnostic::new( checker.report_diagnostic(Diagnostic::new(

View File

@ -21,15 +21,14 @@ use crate::settings::LinterSettings;
/// standard-library module and vice versa. /// standard-library module and vice versa.
/// ///
/// Standard-library modules can be marked as exceptions to this rule via the /// 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.
/// ///
/// By default, only the last component of the module name is considered, so `logging.py`, /// By default, only the last component of the module name is considered, so `logging.py`,
/// `utils/logging.py`, and `utils/logging/__init__.py` would all clash with the builtin `logging` /// `utils/logging.py`, and `utils/logging/__init__.py` would all clash with the builtin `logging`
/// module. With the [`lint.flake8-builtins.builtins-strict-checking`] option set to `false`, the /// module. With the [`lint.flake8-builtins.strict-checking`] option set to `false`, the module
/// module path is considered, so only a top-level `logging.py` or `logging/__init__.py` will /// path is considered, so only a top-level `logging.py` or `logging/__init__.py` will trigger the
/// trigger the rule and `utils/logging.py`, for example, would not. In preview mode, the default /// rule and `utils/logging.py`, for example, would not. In preview mode, the default value of
/// value of [`lint.flake8-builtins.builtins-strict-checking`] is `false` rather than `true` in /// [`lint.flake8-builtins.strict-checking`] is `false` rather than `true` in stable mode.
/// stable mode.
/// ///
/// This rule is not applied to stub files, as the name of a stub module is out /// 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 /// of the control of the author of the stub file. Instead, a stub should aim to
@ -50,8 +49,8 @@ use crate::settings::LinterSettings;
/// ``` /// ```
/// ///
/// ## Options /// ## Options
/// - `lint.flake8-builtins.builtins-allowed-modules` /// - `lint.flake8-builtins.allowed-modules`
/// - `lint.flake8-builtins.builtins-strict-checking` /// - `lint.flake8-builtins.strict-checking`
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
pub(crate) struct StdlibModuleShadowing { pub(crate) struct StdlibModuleShadowing {
name: String, name: String,
@ -104,7 +103,7 @@ pub(crate) fn stdlib_module_shadowing(
} }
// not allowed generally, but check for a parent in non-strict mode // 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; return None;
} }
@ -136,7 +135,7 @@ fn is_allowed_module(settings: &LinterSettings, version: PythonVersion, module:
if settings if settings
.flake8_builtins .flake8_builtins
.builtins_allowed_modules .allowed_modules
.iter() .iter()
.any(|allowed_module| allowed_module == module) .any(|allowed_module| allowed_module == module)
{ {

View File

@ -6,17 +6,17 @@ use std::fmt::{Display, Formatter};
#[derive(Debug, Clone, Default, CacheKey)] #[derive(Debug, Clone, Default, CacheKey)]
pub struct Settings { pub struct Settings {
pub builtins_ignorelist: Vec<String>, pub ignorelist: Vec<String>,
pub builtins_allowed_modules: Vec<String>, pub allowed_modules: Vec<String>,
pub builtins_strict_checking: bool, pub strict_checking: bool,
} }
impl Settings { impl Settings {
pub fn new(preview: PreviewMode) -> Self { pub fn new(preview: PreviewMode) -> Self {
Self { Self {
builtins_ignorelist: Vec::new(), ignorelist: Vec::new(),
builtins_allowed_modules: Vec::new(), allowed_modules: Vec::new(),
builtins_strict_checking: preview.is_disabled(), strict_checking: preview.is_disabled(),
} }
} }
} }
@ -27,9 +27,9 @@ impl Display for Settings {
formatter = f, formatter = f,
namespace = "linter.flake8_builtins", namespace = "linter.flake8_builtins",
fields = [ fields = [
self.builtins_allowed_modules | array, self.allowed_modules | array,
self.builtins_ignorelist | array, self.ignorelist | array,
self.builtins_strict_checking, self.strict_checking,
] ]
} }
Ok(()) Ok(())

View File

@ -1213,31 +1213,81 @@ impl Flake8BugbearOptions {
#[serde(deny_unknown_fields, rename_all = "kebab-case")] #[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct Flake8BuiltinsOptions { pub struct Flake8BuiltinsOptions {
/// DEPRECATED: This option has been renamed to `ignorelist`. Use `ignorelist` instead.
///
/// Ignore list of builtins.
///
/// This option is ignored if both `ignorelist` and `builtins-ignorelist` are set.
#[option( #[option(
default = r#"[]"#, default = r#"[]"#,
value_type = "list[str]", value_type = "list[str]",
example = "builtins-ignorelist = [\"id\"]" example = "builtins-ignorelist = [\"id\"]"
)] )]
/// Ignore list of builtins. #[deprecated(
since = "0.10.0",
note = "`builtins-ignorelist` has been renamed to `ignorelist`. Use that instead."
)]
pub builtins_ignorelist: Option<Vec<String>>, pub builtins_ignorelist: Option<Vec<String>>,
/// Ignore list of builtins.
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = "ignorelist = [\"id\"]"
)]
pub ignorelist: Option<Vec<String>>,
/// DEPRECATED: This option has been renamed to `allowed-modules`. Use `allowed-modules` instead.
///
/// List of builtin module names to allow.
///
/// This option is ignored if both `allowed-modules` and `builtins-allowed-modules` are set.
#[option( #[option(
default = r#"[]"#, default = r#"[]"#,
value_type = "list[str]", value_type = "list[str]",
example = "builtins-allowed-modules = [\"secrets\"]" example = "builtins-allowed-modules = [\"secrets\"]"
)] )]
/// List of builtin module names to allow. #[deprecated(
since = "0.10.0",
note = "`builtins-allowed-modules` has been renamed to `allowed-modules`. Use that instead."
)]
pub builtins_allowed_modules: Option<Vec<String>>, pub builtins_allowed_modules: Option<Vec<String>>,
/// List of builtin module names to allow.
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = "allowed-modules = [\"secrets\"]"
)]
pub allowed_modules: Option<Vec<String>>,
/// DEPRECATED: This option has been renamed to `strict-checking`. Use `strict-checking` instead.
///
/// Compare module names instead of full module paths.
///
/// This option is ignored if both `strict-checking` and `builtins-strict-checking` are set.
#[option( #[option(
default = r#"true"#, default = r#"true"#,
value_type = "bool", value_type = "bool",
example = "builtins-strict-checking = false" example = "builtins-strict-checking = false"
)] )]
#[deprecated(
since = "0.10.0",
note = "`builtins-strict-checking` has been renamed to `strict-checking`. Use that instead."
)]
pub builtins_strict_checking: Option<bool>,
/// Compare module names instead of full module paths. /// Compare module names instead of full module paths.
/// ///
/// Used by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/). /// Used by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).
/// ///
/// In preview mode the default value is `false` rather than `true`. /// In preview mode the default value is `false` rather than `true`.
pub builtins_strict_checking: Option<bool>, #[option(
default = r#"true"#,
value_type = "bool",
example = "strict-checking = false"
)]
pub strict_checking: Option<bool>,
} }
impl Flake8BuiltinsOptions { impl Flake8BuiltinsOptions {
@ -1245,11 +1295,19 @@ impl Flake8BuiltinsOptions {
self, self,
preview: PreviewMode, preview: PreviewMode,
) -> ruff_linter::rules::flake8_builtins::settings::Settings { ) -> ruff_linter::rules::flake8_builtins::settings::Settings {
#[allow(deprecated)]
ruff_linter::rules::flake8_builtins::settings::Settings { ruff_linter::rules::flake8_builtins::settings::Settings {
builtins_ignorelist: self.builtins_ignorelist.unwrap_or_default(), ignorelist: self
builtins_allowed_modules: self.builtins_allowed_modules.unwrap_or_default(), .ignorelist
builtins_strict_checking: self .or(self.builtins_ignorelist)
.builtins_strict_checking .unwrap_or_default(),
allowed_modules: self
.allowed_modules
.or(self.builtins_allowed_modules)
.unwrap_or_default(),
strict_checking: self
.strict_checking
.or(self.builtins_strict_checking)
// use the old default of true on non-preview // use the old default of true on non-preview
.unwrap_or(preview.is_disabled()), .unwrap_or(preview.is_disabled()),
} }

View File

@ -210,9 +210,9 @@ mod tests {
use ruff_linter::codes; use ruff_linter::codes;
use ruff_linter::line_width::LineLength; use ruff_linter::line_width::LineLength;
use ruff_linter::settings::types::PatternPrefixPair; use ruff_linter::settings::types::{PatternPrefixPair, PreviewMode};
use crate::options::{LintCommonOptions, LintOptions, Options}; use crate::options::{Flake8BuiltinsOptions, LintCommonOptions, LintOptions, Options};
use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools}; use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools};
#[test] #[test]
@ -323,6 +323,55 @@ ignore = ["E501"]
}) })
); );
let pyproject: Pyproject = toml::from_str(
r#"
[tool.ruff.lint.flake8-builtins]
builtins-allowed-modules = ["asyncio"]
builtins-ignorelist = ["argparse", 'typing']
builtins-strict-checking = true
allowed-modules = ['sys']
ignorelist = ["os", 'io']
strict-checking = false
"#,
)?;
#[allow(deprecated)]
let expected = Flake8BuiltinsOptions {
builtins_allowed_modules: Some(vec!["asyncio".to_string()]),
allowed_modules: Some(vec!["sys".to_string()]),
builtins_ignorelist: Some(vec!["argparse".to_string(), "typing".to_string()]),
ignorelist: Some(vec!["os".to_string(), "io".to_string()]),
builtins_strict_checking: Some(true),
strict_checking: Some(false),
};
assert_eq!(
pyproject.tool,
Some(Tools {
ruff: Some(Options {
lint: Some(LintOptions {
common: LintCommonOptions {
flake8_builtins: Some(expected.clone()),
..LintCommonOptions::default()
},
..LintOptions::default()
}),
..Options::default()
})
})
);
let settings = expected.into_settings(PreviewMode::Enabled);
assert_eq!(settings.allowed_modules, vec!["sys".to_string()]);
assert_eq!(
settings.ignorelist,
vec!["os".to_string(), "io".to_string()]
);
assert!(!settings.strict_checking);
assert!(toml::from_str::<Pyproject>( assert!(toml::from_str::<Pyproject>(
r" r"
[tool.black] [tool.black]

34
ruff.schema.json generated
View File

@ -1035,7 +1035,7 @@
"description": "Options for the `flake8-builtins` plugin.", "description": "Options for the `flake8-builtins` plugin.",
"type": "object", "type": "object",
"properties": { "properties": {
"builtins-allowed-modules": { "allowed-modules": {
"description": "List of builtin module names to allow.", "description": "List of builtin module names to allow.",
"type": [ "type": [
"array", "array",
@ -1045,8 +1045,20 @@
"type": "string" "type": "string"
} }
}, },
"builtins-allowed-modules": {
"description": "DEPRECATED: This option has been renamed to `allowed-modules`. Use `allowed-modules` instead.\n\nList of builtin module names to allow.\n\nThis option is ignored if both `allowed-modules` and `builtins-allowed-modules` are set.",
"deprecated": true,
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"builtins-ignorelist": { "builtins-ignorelist": {
"description": "Ignore list of builtins.", "description": "DEPRECATED: This option has been renamed to `ignorelist`. Use `ignorelist` instead.\n\nIgnore list of builtins.\n\nThis option is ignored if both `ignorelist` and `builtins-ignorelist` are set.",
"deprecated": true,
"type": [ "type": [
"array", "array",
"null" "null"
@ -1056,6 +1068,24 @@
} }
}, },
"builtins-strict-checking": { "builtins-strict-checking": {
"description": "DEPRECATED: This option has been renamed to `strict-checking`. Use `strict-checking` instead.\n\nCompare module names instead of full module paths.\n\nThis option is ignored if both `strict-checking` and `builtins-strict-checking` are set.",
"deprecated": true,
"type": [
"boolean",
"null"
]
},
"ignorelist": {
"description": "Ignore list of builtins.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"strict-checking": {
"description": "Compare module names instead of full module paths.\n\nUsed by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).\n\nIn preview mode the default value is `false` rather than `true`.", "description": "Compare module names instead of full module paths.\n\nUsed by [`A005` - `stdlib-module-shadowing`](https://docs.astral.sh/ruff/rules/stdlib-module-shadowing/).\n\nIn preview mode the default value is `false` rather than `true`.",
"type": [ "type": [
"boolean", "boolean",