Skip to content

Commit

Permalink
Rename allowed-imports to allowed-unused-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Oct 3, 2024
1 parent 678ae20 commit a064259
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ linter.task_tags = [
XXX,
]
linter.typing_modules = []
linter.allowed_imports = []
linter.allowed_unused_imports = []

# Linter Plugins
linter.flake8_annotations.mypy_init_return = false
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
}
if checker
.settings
.allowed_imports
.allowed_unused_imports
.iter()
.any(|allowed_import| name.starts_with(allowed_import))
.any(|allowed_unused_import| name.starts_with(allowed_unused_import))
{
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub struct LinterSettings {
pub line_length: LineLength,
pub task_tags: Vec<String>,
pub typing_modules: Vec<String>,
pub allowed_imports: Vec<String>,
pub allowed_unused_imports: Vec<String>,

// Plugins
pub flake8_annotations: flake8_annotations::settings::Settings,
Expand Down Expand Up @@ -300,7 +300,7 @@ impl Display for LinterSettings {
self.line_length,
self.task_tags | array,
self.typing_modules | array,
self.allowed_imports | array,
self.allowed_unused_imports | array,
]
}
writeln!(f, "\n# Linter Plugins")?;
Expand Down Expand Up @@ -407,7 +407,7 @@ impl LinterSettings {

task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(),
typing_modules: vec![],
allowed_imports: vec![],
allowed_unused_imports: vec![],
flake8_annotations: flake8_annotations::settings::Settings::default(),
flake8_bandit: flake8_bandit::settings::Settings::default(),
flake8_boolean_trap: flake8_boolean_trap::settings::Settings::default(),
Expand Down
16 changes: 9 additions & 7 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl Configuration {
.unwrap_or_else(|| TASK_TAGS.iter().map(ToString::to_string).collect()),
logger_objects: lint.logger_objects.unwrap_or_default(),
typing_modules: lint.typing_modules.unwrap_or_default(),
allowed_imports: lint.allowed_imports.unwrap_or_default(),
allowed_unused_imports: lint.allowed_unused_imports.unwrap_or_default(),
// Plugins
flake8_annotations: lint
.flake8_annotations
Expand Down Expand Up @@ -627,7 +627,7 @@ pub struct LintConfiguration {
pub logger_objects: Option<Vec<String>>,
pub task_tags: Option<Vec<String>>,
pub typing_modules: Option<Vec<String>>,
pub allowed_imports: Option<Vec<String>>,
pub allowed_unused_imports: Option<Vec<String>>,

// Plugins
pub flake8_annotations: Option<Flake8AnnotationsOptions>,
Expand Down Expand Up @@ -740,7 +740,7 @@ impl LintConfiguration {
task_tags: options.common.task_tags,
logger_objects: options.common.logger_objects,
typing_modules: options.common.typing_modules,
allowed_imports: options.common.allowed_imports,
allowed_unused_imports: options.common.allowed_unused_imports,
// Plugins
flake8_annotations: options.common.flake8_annotations,
flake8_bandit: options.common.flake8_bandit,
Expand Down Expand Up @@ -1109,7 +1109,9 @@ impl LintConfiguration {
.or(config.explicit_preview_rules),
task_tags: self.task_tags.or(config.task_tags),
typing_modules: self.typing_modules.or(config.typing_modules),
allowed_imports: self.allowed_imports.or(config.allowed_imports),
allowed_unused_imports: self
.allowed_unused_imports
.or(config.allowed_unused_imports),
// Plugins
flake8_annotations: self.flake8_annotations.combine(config.flake8_annotations),
flake8_bandit: self.flake8_bandit.combine(config.flake8_bandit),
Expand Down Expand Up @@ -1331,7 +1333,7 @@ fn warn_about_deprecated_top_level_lint_options(
explicit_preview_rules,
task_tags,
typing_modules,
allowed_imports,
allowed_unused_imports,
unfixable,
flake8_annotations,
flake8_bandit,
Expand Down Expand Up @@ -1430,8 +1432,8 @@ fn warn_about_deprecated_top_level_lint_options(
if typing_modules.is_some() {
used_options.push("typing-modules");
}
if allowed_imports.is_some() {
used_options.push("allowed-imports");
if allowed_unused_imports.is_some() {
used_options.push("allowed-unused-imports");
}

if unfixable.is_some() {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ pub struct LintCommonOptions {
#[option(
default = r#"[]"#,
value_type = "list[str]",
example = r#"allowed-imports = ["hvplot.pandas"]"#
example = r#"allowed-unused-imports = ["hvplot.pandas"]"#
)]
pub allowed_imports: Option<Vec<String>>,
pub allowed_unused_imports: Option<Vec<String>>,
/// A list of rule codes or prefixes to consider non-fixable.
#[option(
default = "[]",
Expand Down
4 changes: 2 additions & 2 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a064259

Please sign in to comment.