mirror of https://github.com/astral-sh/ruff
[`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:
parent
c0b1413ecd
commit
24ec94562c
|
|
@ -2470,7 +2470,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()?;
|
||||
|
|
@ -2482,7 +2482,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"
|
||||
|
|
@ -2504,7 +2504,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()?;
|
||||
|
|
@ -2516,7 +2516,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"
|
||||
|
|
@ -2535,7 +2535,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]
|
||||
|
|
|
|||
|
|
@ -229,9 +229,9 @@ linter.flake8_bandit.check_typed_exception = false
|
|||
linter.flake8_bandit.extend_markup_names = []
|
||||
linter.flake8_bandit.allowed_markup_calls = []
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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])
|
||||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -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.target_version(),
|
||||
) {
|
||||
// Ignore parameters in lambda expressions.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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,
|
||||
|
|
@ -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.target_version(),
|
||||
) {
|
||||
// Ignore explicit overrides.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)]
|
||||
|
|
@ -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.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(Diagnostic::new(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(Diagnostic::new(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -71,7 +71,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.target_version(),
|
||||
) {
|
||||
checker.report_diagnostic(Diagnostic::new(
|
||||
|
|
|
|||
|
|
@ -21,15 +21,14 @@ 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.
|
||||
///
|
||||
/// 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`
|
||||
/// module. With the [`lint.flake8-builtins.builtins-strict-checking`] option set to `false`, the
|
||||
/// module path is considered, so only a top-level `logging.py` or `logging/__init__.py` will
|
||||
/// trigger the rule and `utils/logging.py`, for example, would not. In preview mode, the default
|
||||
/// value of [`lint.flake8-builtins.builtins-strict-checking`] is `false` rather than `true` in
|
||||
/// stable mode.
|
||||
/// module. With the [`lint.flake8-builtins.strict-checking`] option set to `false`, the module
|
||||
/// path is considered, so only a top-level `logging.py` or `logging/__init__.py` will trigger the
|
||||
/// rule and `utils/logging.py`, for example, would not. In preview mode, the default value of
|
||||
/// [`lint.flake8-builtins.strict-checking`] is `false` rather than `true` in stable mode.
|
||||
///
|
||||
/// 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
|
||||
|
|
@ -50,8 +49,8 @@ use crate::settings::LinterSettings;
|
|||
/// ```
|
||||
///
|
||||
/// ## Options
|
||||
/// - `lint.flake8-builtins.builtins-allowed-modules`
|
||||
/// - `lint.flake8-builtins.builtins-strict-checking`
|
||||
/// - `lint.flake8-builtins.allowed-modules`
|
||||
/// - `lint.flake8-builtins.strict-checking`
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct StdlibModuleShadowing {
|
||||
name: String,
|
||||
|
|
@ -104,7 +103,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;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +135,7 @@ fn is_allowed_module(settings: &LinterSettings, version: PythonVersion, module:
|
|||
|
||||
if settings
|
||||
.flake8_builtins
|
||||
.builtins_allowed_modules
|
||||
.allowed_modules
|
||||
.iter()
|
||||
.any(|allowed_module| allowed_module == module)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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(())
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -1035,7 +1035,7 @@
|
|||
"description": "Options for the `flake8-builtins` plugin.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"builtins-allowed-modules": {
|
||||
"allowed-modules": {
|
||||
"description": "List of builtin module names to allow.",
|
||||
"type": [
|
||||
"array",
|
||||
|
|
@ -1045,8 +1045,20 @@
|
|||
"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": {
|
||||
"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": [
|
||||
"array",
|
||||
"null"
|
||||
|
|
@ -1056,6 +1068,24 @@
|
|||
}
|
||||
},
|
||||
"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`.",
|
||||
"type": [
|
||||
"boolean",
|
||||
|
|
|
|||
Loading…
Reference in New Issue