Skip to content

Commit

Permalink
Deprecate F401 ignore-init-module-imports and make default behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Mar 12, 2024
1 parent d02a3df commit 3526092
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ linter.allowed_confusables = []
linter.builtins = []
linter.dummy_variable_rgx = ^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$
linter.external = []
linter.ignore_init_module_imports = false
linter.ignore_init_module_imports = true
linter.logger_objects = []
linter.namespace_packages = []
linter.src = [
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
}
}

let in_init =
checker.settings.ignore_init_module_imports && checker.path().ends_with("__init__.py");
let in_init = checker.path().ends_with("__init__.py");
let fix_init = in_init && !checker.settings.ignore_init_module_imports;

// Generate a diagnostic for every import, but share a fix across all imports within the same
// statement (excluding those that are ignored).
Expand All @@ -164,7 +164,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope, diagnostics: &mut
exceptions.intersects(Exceptions::MODULE_NOT_FOUND_ERROR | Exceptions::IMPORT_ERROR);
let multiple = imports.len() > 1;

let fix = if !in_init && !in_except_handler {
let fix = if !fix_init && !in_except_handler {
fix_imports(checker, node_id, &imports).ok()
} else {
None
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl Configuration {
project_root: project_root.to_path_buf(),
},

#[allow(deprecated)]
linter: LinterSettings {
rules: lint.as_rule_table(lint_preview)?,
exclude: FilePatternSet::try_from_iter(lint.exclude.unwrap_or_default())?,
Expand All @@ -253,7 +254,7 @@ impl Configuration {
.dummy_variable_rgx
.unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()),
external: lint.external.unwrap_or_default(),
ignore_init_module_imports: lint.ignore_init_module_imports.unwrap_or_default(),
ignore_init_module_imports: lint.ignore_init_module_imports.unwrap_or(true),
line_length,
tab_size: self.indent_width.unwrap_or_default(),
namespace_packages: self.namespace_packages.unwrap_or_default(),
Expand Down Expand Up @@ -650,6 +651,10 @@ impl LintConfiguration {
.flatten()
.chain(options.common.extend_unfixable.into_iter().flatten())
.collect();

#[allow(deprecated)]
let ignore_init_module_imports = options.common.ignore_init_module_imports;

Ok(LintConfiguration {
exclude: options.exclude.map(|paths| {
paths
Expand Down Expand Up @@ -692,7 +697,7 @@ impl LintConfiguration {
})
.unwrap_or_default(),
external: options.common.external,
ignore_init_module_imports: options.common.ignore_init_module_imports,
ignore_init_module_imports,
explicit_preview_rules: options.common.explicit_preview_rules,
per_file_ignores: options.common.per_file_ignores.map(|per_file_ignores| {
per_file_ignores
Expand Down Expand Up @@ -1316,6 +1321,7 @@ fn warn_about_deprecated_top_level_lint_options(
used_options.push("extend-unsafe-fixes");
}

#[allow(deprecated)]
if top_level_options.ignore_init_module_imports.is_some() {
used_options.push("ignore-init-module-imports");
}
Expand Down
9 changes: 7 additions & 2 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,18 @@ pub struct LintCommonOptions {
/// imports will still be flagged, but with a dedicated message suggesting
/// that the import is either added to the module's `__all__` symbol, or
/// re-exported with a redundant alias (e.g., `import os as os`).
///
/// This option is enabled by default.
#[option(
default = "false",
default = "true",
value_type = "bool",
example = r#"
ignore-init-module-imports = true
ignore-init-module-imports = false
"#
)]
#[deprecated(
note = "`ignore-init-module-imports` is deprecated and is now enabled by default."
)]
pub ignore_init_module_imports: Option<bool>,

/// A list of objects that should be treated equivalently to a
Expand Down
5 changes: 3 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 3526092

Please sign in to comment.