[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

@ -1213,31 +1213,81 @@ impl Flake8BugbearOptions {
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
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(
default = r#"[]"#,
value_type = "list[str]",
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>>,
/// 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(
default = r#"[]"#,
value_type = "list[str]",
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>>,
/// 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(
default = r#"true"#,
value_type = "bool",
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.
///
/// 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`.
pub builtins_strict_checking: Option<bool>,
#[option(
default = r#"true"#,
value_type = "bool",
example = "strict-checking = false"
)]
pub strict_checking: Option<bool>,
}
impl Flake8BuiltinsOptions {
@ -1245,11 +1295,19 @@ impl Flake8BuiltinsOptions {
self,
preview: PreviewMode,
) -> ruff_linter::rules::flake8_builtins::settings::Settings {
#[allow(deprecated)]
ruff_linter::rules::flake8_builtins::settings::Settings {
builtins_ignorelist: self.builtins_ignorelist.unwrap_or_default(),
builtins_allowed_modules: self.builtins_allowed_modules.unwrap_or_default(),
builtins_strict_checking: self
.builtins_strict_checking
ignorelist: self
.ignorelist
.or(self.builtins_ignorelist)
.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
.unwrap_or(preview.is_disabled()),
}

View file

@ -210,9 +210,9 @@ mod tests {
use ruff_linter::codes;
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};
#[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>(
r"
[tool.black]