From 0efdc80b2c17c3b9eecc180147f676d82d898d78 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 20 Sep 2023 13:09:53 +0200 Subject: [PATCH] Introduce `LinterSettings` and `ResolverSettings` --- crates/ruff_benchmark/benches/linter.rs | 10 +- crates/ruff_cli/src/cache.rs | 6 +- crates/ruff_cli/src/commands/add_noqa.rs | 2 +- crates/ruff_cli/src/commands/check.rs | 15 +- crates/ruff_cli/src/commands/check_stdin.rs | 2 +- crates/ruff_cli/src/commands/format.rs | 5 +- crates/ruff_cli/src/commands/format_stdin.rs | 5 +- crates/ruff_cli/src/diagnostics.rs | 14 +- crates/ruff_dev/src/format_dev.rs | 7 +- .../src/checkers/ast/analyze/expression.rs | 2 +- crates/ruff_linter/src/checkers/ast/mod.rs | 10 +- crates/ruff_linter/src/checkers/filesystem.rs | 13 +- crates/ruff_linter/src/checkers/imports.rs | 4 +- .../ruff_linter/src/checkers/logical_lines.rs | 8 +- crates/ruff_linter/src/checkers/noqa.rs | 4 +- .../src/checkers/physical_lines.rs | 10 +- crates/ruff_linter/src/checkers/tokens.rs | 4 +- crates/ruff_linter/src/directives.rs | 4 +- crates/ruff_linter/src/linter.rs | 20 +- crates/ruff_linter/src/pyproject_toml.rs | 4 +- crates/ruff_linter/src/rules/airflow/mod.rs | 2 +- crates/ruff_linter/src/rules/eradicate/mod.rs | 2 +- .../eradicate/rules/commented_out_code.rs | 4 +- .../ruff_linter/src/rules/flake8_2020/mod.rs | 2 +- .../src/rules/flake8_annotations/mod.rs | 36 +-- .../ruff_linter/src/rules/flake8_async/mod.rs | 4 +- .../src/rules/flake8_bandit/mod.rs | 12 +- .../src/rules/flake8_blind_except/mod.rs | 2 +- .../src/rules/flake8_boolean_trap/mod.rs | 2 +- .../src/rules/flake8_bugbear/mod.rs | 14 +- .../src/rules/flake8_builtins/mod.rs | 8 +- .../src/rules/flake8_commas/mod.rs | 2 +- .../flake8_commas/rules/trailing_commas.rs | 4 +- .../src/rules/flake8_comprehensions/mod.rs | 8 +- .../src/rules/flake8_copyright/mod.rs | 24 +- .../rules/missing_copyright_notice.rs | 4 +- .../src/rules/flake8_datetimez/mod.rs | 2 +- .../src/rules/flake8_debugger/mod.rs | 2 +- .../src/rules/flake8_django/mod.rs | 2 +- .../src/rules/flake8_errmsg/mod.rs | 6 +- .../src/rules/flake8_executable/mod.rs | 2 +- .../src/rules/flake8_executable/rules/mod.rs | 4 +- .../rules/shebang_leading_whitespace.rs | 4 +- .../ruff_linter/src/rules/flake8_fixme/mod.rs | 2 +- .../rules/flake8_future_annotations/mod.rs | 8 +- .../src/rules/flake8_gettext/mod.rs | 2 +- .../rules/flake8_implicit_str_concat/mod.rs | 6 +- .../rules/flake8_import_conventions/mod.rs | 30 +- .../src/rules/flake8_logging/mod.rs | 4 +- .../src/rules/flake8_logging_format/mod.rs | 4 +- .../src/rules/flake8_no_pep420/mod.rs | 6 +- .../ruff_linter/src/rules/flake8_pie/mod.rs | 2 +- .../ruff_linter/src/rules/flake8_print/mod.rs | 2 +- .../ruff_linter/src/rules/flake8_pyi/mod.rs | 6 +- .../src/rules/flake8_pytest_style/mod.rs | 4 +- .../src/rules/flake8_quotes/mod.rs | 18 +- .../rules/flake8_quotes/rules/from_tokens.rs | 12 +- .../ruff_linter/src/rules/flake8_raise/mod.rs | 2 +- .../src/rules/flake8_return/mod.rs | 4 +- .../ruff_linter/src/rules/flake8_self/mod.rs | 6 +- .../src/rules/flake8_simplify/mod.rs | 2 +- .../ruff_linter/src/rules/flake8_slots/mod.rs | 2 +- .../src/rules/flake8_tidy_imports/mod.rs | 26 +- .../ruff_linter/src/rules/flake8_todos/mod.rs | 2 +- .../src/rules/flake8_todos/rules/todos.rs | 6 +- .../src/rules/flake8_type_checking/mod.rs | 20 +- .../src/rules/flake8_unused_arguments/mod.rs | 10 +- .../src/rules/flake8_use_pathlib/mod.rs | 4 +- crates/ruff_linter/src/rules/flynt/mod.rs | 2 +- crates/ruff_linter/src/rules/isort/mod.rs | 134 ++++----- .../rules/isort/rules/add_required_imports.rs | 6 +- .../src/rules/isort/rules/organize_imports.rs | 4 +- crates/ruff_linter/src/rules/mccabe/mod.rs | 6 +- crates/ruff_linter/src/rules/numpy/mod.rs | 2 +- .../ruff_linter/src/rules/pandas_vet/mod.rs | 4 +- .../ruff_linter/src/rules/pep8_naming/mod.rs | 12 +- crates/ruff_linter/src/rules/perflint/mod.rs | 4 +- .../ruff_linter/src/rules/pycodestyle/mod.rs | 26 +- .../pycodestyle/rules/compound_statements.rs | 4 +- .../pycodestyle/rules/doc_line_too_long.rs | 4 +- .../rules/pycodestyle/rules/line_too_long.rs | 4 +- .../pycodestyle/rules/trailing_whitespace.rs | 4 +- .../ruff_linter/src/rules/pydocstyle/mod.rs | 25 +- crates/ruff_linter/src/rules/pyflakes/mod.rs | 45 +-- .../ruff_linter/src/rules/pygrep_hooks/mod.rs | 2 +- .../ruff_linter/src/rules/pylint/helpers.rs | 4 +- crates/ruff_linter/src/rules/pylint/mod.rs | 37 +-- crates/ruff_linter/src/rules/pyupgrade/mod.rs | 34 +-- .../pyupgrade/rules/extraneous_parentheses.rs | 4 +- .../rules/unnecessary_coding_comment.rs | 4 +- crates/ruff_linter/src/rules/refurb/mod.rs | 2 +- crates/ruff_linter/src/rules/ruff/mod.rs | 41 +-- .../ruff/rules/ambiguous_unicode_character.rs | 6 +- .../ruff_linter/src/rules/tryceratops/mod.rs | 2 +- crates/ruff_linter/src/settings/defaults.rs | 95 ------ crates/ruff_linter/src/settings/mod.rs | 146 ++++++++-- crates/ruff_linter/src/test.rs | 14 +- crates/ruff_wasm/src/lib.rs | 15 +- crates/ruff_workspace/src/configuration.rs | 275 +++++++++--------- crates/ruff_workspace/src/resolver.rs | 5 +- fuzz/fuzz_targets/ruff_fix_validity.rs | 6 +- 101 files changed, 753 insertions(+), 716 deletions(-) diff --git a/crates/ruff_benchmark/benches/linter.rs b/crates/ruff_benchmark/benches/linter.rs index 50f3f4be8b4720..9a5e01f2bf5894 100644 --- a/crates/ruff_benchmark/benches/linter.rs +++ b/crates/ruff_benchmark/benches/linter.rs @@ -4,7 +4,7 @@ use ruff_benchmark::criterion::{ use ruff_benchmark::{TestCase, TestFile, TestFileDownloadError}; use ruff_linter::linter::lint_only; use ruff_linter::settings::rule_table::RuleTable; -use ruff_linter::settings::{flags, Settings}; +use ruff_linter::settings::{flags, LinterSettings}; use ruff_linter::source_kind::SourceKind; use ruff_linter::{registry::Rule, RuleSelector}; use ruff_python_ast::PySourceType; @@ -41,7 +41,7 @@ fn create_test_cases() -> Result, TestFileDownloadError> { ]) } -fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) { +fn benchmark_linter(mut group: BenchmarkGroup, settings: &LinterSettings) { let test_cases = create_test_cases().unwrap(); for case in test_cases { @@ -75,7 +75,7 @@ fn benchmark_linter(mut group: BenchmarkGroup, settings: &Settings) { fn benchmark_default_rules(criterion: &mut Criterion) { let group = criterion.benchmark_group("linter/default-rules"); - benchmark_linter(group, &Settings::default()); + benchmark_linter(group, &LinterSettings::default()); } fn benchmark_all_rules(criterion: &mut Criterion) { @@ -85,9 +85,9 @@ fn benchmark_all_rules(criterion: &mut Criterion) { rules.disable(Rule::ShebangMissingExecutableFile); rules.disable(Rule::ShebangNotExecutable); - let settings = Settings { + let settings = LinterSettings { rules, - ..Settings::default() + ..LinterSettings::default() }; let group = criterion.benchmark_group("linter/all-rules"); diff --git a/crates/ruff_cli/src/cache.rs b/crates/ruff_cli/src/cache.rs index 89634c0fb18566..c721bffcf2de78 100644 --- a/crates/ruff_cli/src/cache.rs +++ b/crates/ruff_cli/src/cache.rs @@ -405,7 +405,7 @@ mod tests { let diagnostics = lint_path( &path, Some(&package_root), - &settings, + &settings.linter, Some(&cache), flags::Noqa::Enabled, flags::FixMode::Generate, @@ -450,7 +450,7 @@ mod tests { got_diagnostics += lint_path( &path, Some(&package_root), - &settings, + &settings.linter, Some(&cache), flags::Noqa::Enabled, flags::FixMode::Generate, @@ -707,7 +707,7 @@ mod tests { lint_path( &self.package_root.join(path), Some(&self.package_root), - &self.settings, + &self.settings.linter, Some(cache), flags::Noqa::Enabled, flags::FixMode::Generate, diff --git a/crates/ruff_cli/src/commands/add_noqa.rs b/crates/ruff_cli/src/commands/add_noqa.rs index 3c3b895226b6d2..513f4ba2487ca5 100644 --- a/crates/ruff_cli/src/commands/add_noqa.rs +++ b/crates/ruff_cli/src/commands/add_noqa.rs @@ -65,7 +65,7 @@ pub(crate) fn add_noqa( return None; } }; - match add_noqa_to_path(path, package, &source_kind, source_type, settings) { + match add_noqa_to_path(path, package, &source_kind, source_type, &settings.linter) { Ok(count) => Some(count), Err(e) => { error!("Failed to add noqa to {}: {e}", path.display()); diff --git a/crates/ruff_cli/src/commands/check.rs b/crates/ruff_cli/src/commands/check.rs index 3590bf53a75ae9..1662b36af540c3 100644 --- a/crates/ruff_cli/src/commands/check.rs +++ b/crates/ruff_cli/src/commands/check.rs @@ -16,7 +16,7 @@ use rustc_hash::FxHashMap; use ruff_diagnostics::Diagnostic; use ruff_linter::message::Message; use ruff_linter::registry::Rule; -use ruff_linter::settings::{flags, Settings}; +use ruff_linter::settings::{flags, LinterSettings}; use ruff_linter::{fs, warn_user_once, IOError}; use ruff_python_ast::imports::ImportMap; use ruff_source_file::SourceFileBuilder; @@ -119,7 +119,7 @@ pub(crate) fn check( } }); - lint_path(path, package, settings, cache, noqa, autofix).map_err(|e| { + lint_path(path, package, &settings.linter, cache, noqa, autofix).map_err(|e| { (Some(path.to_owned()), { let mut error = e.to_string(); for cause in e.chain() { @@ -142,7 +142,7 @@ pub(crate) fn check( .unwrap_or_else(|(path, message)| { if let Some(path) = &path { let settings = resolver.resolve(path, pyproject_config); - if settings.rules.enabled(Rule::IOError) { + if settings.linter.rules.enabled(Rule::IOError) { let dummy = SourceFileBuilder::new(path.to_string_lossy().as_ref(), "").finish(); @@ -195,7 +195,7 @@ pub(crate) fn check( fn lint_path( path: &Path, package: Option<&Path>, - settings: &Settings, + settings: &LinterSettings, cache: Option<&Cache>, noqa: flags::Noqa, autofix: flags::FixMode, @@ -238,7 +238,7 @@ mod test { use ruff_linter::message::{Emitter, EmitterContext, TextEmitter}; use ruff_linter::registry::Rule; - use ruff_linter::settings::{flags, Settings}; + use ruff_linter::settings::{flags, LinterSettings, Settings}; use ruff_workspace::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy}; use crate::args::CliOverrides; @@ -268,7 +268,10 @@ mod test { // Configure let snapshot = format!("{}_{}", rule_code.noqa_code(), path); // invalid pyproject.toml is not active by default - let settings = Settings::for_rules(vec![rule_code, Rule::InvalidPyprojectToml]); + let settings = Settings { + linter: LinterSettings::for_rules(vec![rule_code, Rule::InvalidPyprojectToml]), + ..Settings::default() + }; let pyproject_config = PyprojectConfig::new(PyprojectDiscoveryStrategy::Fixed, settings, None); diff --git a/crates/ruff_cli/src/commands/check_stdin.rs b/crates/ruff_cli/src/commands/check_stdin.rs index e868db33b61bf2..9b391fb384e40d 100644 --- a/crates/ruff_cli/src/commands/check_stdin.rs +++ b/crates/ruff_cli/src/commands/check_stdin.rs @@ -24,7 +24,7 @@ pub(crate) fn check_stdin( } } let package_root = filename.and_then(Path::parent).and_then(|path| { - packaging::detect_package_root(path, &pyproject_config.settings.namespace_packages) + packaging::detect_package_root(path, &pyproject_config.settings.linter.namespace_packages) }); let stdin = read_from_stdin()?; let mut diagnostics = lint_stdin( diff --git a/crates/ruff_cli/src/commands/format.rs b/crates/ruff_cli/src/commands/format.rs index 07e664768cb52a..e90b0bbb7e0b21 100644 --- a/crates/ruff_cli/src/commands/format.rs +++ b/crates/ruff_cli/src/commands/format.rs @@ -77,11 +77,12 @@ pub(crate) fn format( let resolved_settings = resolver.resolve(path, &pyproject_config); - let preview = match resolved_settings.preview { + // TODO(micha): Use `formatter` settings instead + let preview = match resolved_settings.linter.preview { PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, }; - let line_length = resolved_settings.line_length; + let line_length = resolved_settings.linter.line_length; let options = PyFormatOptions::from_source_type(source_type) .with_line_width(LineWidth::from(NonZeroU16::from(line_length))) diff --git a/crates/ruff_cli/src/commands/format_stdin.rs b/crates/ruff_cli/src/commands/format_stdin.rs index dba9de0bf2036b..b5e8009ad4d607 100644 --- a/crates/ruff_cli/src/commands/format_stdin.rs +++ b/crates/ruff_cli/src/commands/format_stdin.rs @@ -39,11 +39,12 @@ pub(crate) fn format_stdin(cli: &FormatArguments, overrides: &CliOverrides) -> R // Format the file. let path = cli.stdin_filename.as_deref(); - let preview = match pyproject_config.settings.preview { + // TODO(micha): Use Formatter settings + let preview = match pyproject_config.settings.linter.preview { PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, }; - let line_length = pyproject_config.settings.line_length; + let line_length = pyproject_config.settings.linter.line_length; let options = path .map(PyFormatOptions::from_extension) diff --git a/crates/ruff_cli/src/diagnostics.rs b/crates/ruff_cli/src/diagnostics.rs index 487fce997b7a98..18acb45d55c3e4 100644 --- a/crates/ruff_cli/src/diagnostics.rs +++ b/crates/ruff_cli/src/diagnostics.rs @@ -22,7 +22,7 @@ use ruff_linter::logging::DisplayParseError; use ruff_linter::message::Message; use ruff_linter::pyproject_toml::lint_pyproject_toml; use ruff_linter::registry::AsRule; -use ruff_linter::settings::{flags, Settings}; +use ruff_linter::settings::{flags, LinterSettings, Settings}; use ruff_linter::source_kind::SourceKind; use ruff_linter::{fs, IOError, SyntaxError}; use ruff_macros::CacheKey; @@ -85,7 +85,7 @@ impl Diagnostics { pub(crate) fn from_source_error( err: &SourceExtractionError, path: Option<&Path>, - settings: &Settings, + settings: &LinterSettings, ) -> Self { let diagnostic = Diagnostic::from(err); if settings.rules.enabled(diagnostic.kind.rule()) { @@ -143,7 +143,7 @@ impl AddAssign for Diagnostics { pub(crate) fn lint_path( path: &Path, package: Option<&Path>, - settings: &Settings, + settings: &LinterSettings, cache: Option<&Cache>, noqa: flags::Noqa, autofix: flags::FixMode, @@ -381,7 +381,7 @@ pub(crate) fn lint_stdin( Ok(Some(sources)) => sources, Ok(None) => return Ok(Diagnostics::default()), Err(err) => { - return Ok(Diagnostics::from_source_error(&err, path, settings)); + return Ok(Diagnostics::from_source_error(&err, path, &settings.linter)); } }; @@ -401,7 +401,7 @@ pub(crate) fn lint_stdin( path.unwrap_or_else(|| Path::new("-")), package, noqa, - settings, + &settings.linter, &source_kind, source_type, ) { @@ -438,7 +438,7 @@ pub(crate) fn lint_stdin( let result = lint_only( path.unwrap_or_else(|| Path::new("-")), package, - settings, + &settings.linter, noqa, &source_kind, source_type, @@ -456,7 +456,7 @@ pub(crate) fn lint_stdin( let result = lint_only( path.unwrap_or_else(|| Path::new("-")), package, - settings, + &settings.linter, noqa, &source_kind, source_type, diff --git a/crates/ruff_dev/src/format_dev.rs b/crates/ruff_dev/src/format_dev.rs index 1567f8a513d57e..4a170bbca9f666 100644 --- a/crates/ruff_dev/src/format_dev.rs +++ b/crates/ruff_dev/src/format_dev.rs @@ -550,8 +550,11 @@ fn format_dir_entry( let settings = resolver.resolve(&path, pyproject_config); // That's a bad way of doing this but it's not worth doing something better for format_dev - if settings.line_length != LineLength::default() { - options = options.with_line_width(LineWidth::from(NonZeroU16::from(settings.line_length))); + // TODO(micha) use formatter settings instead + if settings.linter.line_length != LineLength::default() { + options = options.with_line_width(LineWidth::from(NonZeroU16::from( + settings.linter.line_length, + ))); } // Handle panics (mostly in `debug_assert!`) diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index e964b6caaa35ab..7c9a0c817994ce 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -116,7 +116,7 @@ pub(crate) fn expression(expr: &Expr, checker: &mut Checker) { if checker.enabled(Rule::InvalidIndexType) { ruff::rules::invalid_index_type(checker, subscript); } - if checker.settings.rules.enabled(Rule::SliceCopy) { + if checker.enabled(Rule::SliceCopy) { refurb::rules::slice_copy(checker, subscript); } diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 27a8a2a7d31b0f..4ff0beffa610e4 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -64,7 +64,7 @@ use crate::importer::Importer; use crate::noqa::NoqaMapping; use crate::registry::Rule; use crate::rules::{flake8_pyi, flake8_type_checking, pyflakes, pyupgrade}; -use crate::settings::{flags, Settings}; +use crate::settings::{flags, LinterSettings}; use crate::{docstrings, noqa}; mod analyze; @@ -85,8 +85,8 @@ pub(crate) struct Checker<'a> { /// The [`NoqaMapping`] for the current analysis (i.e., the mapping from line number to /// suppression commented line number). noqa_line_for: &'a NoqaMapping, - /// The [`Settings`] for the current analysis, including the enabled rules. - pub(crate) settings: &'a Settings, + /// The [`LinterSettings`] for the current analysis, including the enabled rules. + pub(crate) settings: &'a LinterSettings, /// The [`Locator`] for the current file, which enables extraction of source code from byte /// offsets. locator: &'a Locator<'a>, @@ -110,7 +110,7 @@ pub(crate) struct Checker<'a> { impl<'a> Checker<'a> { #[allow(clippy::too_many_arguments)] pub(crate) fn new( - settings: &'a Settings, + settings: &'a LinterSettings, noqa_line_for: &'a NoqaMapping, noqa: flags::Noqa, path: &'a Path, @@ -1929,7 +1929,7 @@ pub(crate) fn check_ast( stylist: &Stylist, indexer: &Indexer, noqa_line_for: &NoqaMapping, - settings: &Settings, + settings: &LinterSettings, noqa: flags::Noqa, path: &Path, package: Option<&Path>, diff --git a/crates/ruff_linter/src/checkers/filesystem.rs b/crates/ruff_linter/src/checkers/filesystem.rs index 5bc16ae6ac95d4..d4de20078c1b44 100644 --- a/crates/ruff_linter/src/checkers/filesystem.rs +++ b/crates/ruff_linter/src/checkers/filesystem.rs @@ -5,23 +5,20 @@ use ruff_diagnostics::Diagnostic; use crate::registry::Rule; use crate::rules::flake8_no_pep420::rules::implicit_namespace_package; use crate::rules::pep8_naming::rules::invalid_module_name; -use crate::settings::Settings; +use crate::settings::LinterSettings; pub(crate) fn check_file_path( path: &Path, package: Option<&Path>, - settings: &Settings, + settings: &LinterSettings, ) -> Vec { let mut diagnostics: Vec = vec![]; // flake8-no-pep420 if settings.rules.enabled(Rule::ImplicitNamespacePackage) { - if let Some(diagnostic) = implicit_namespace_package( - path, - package, - &settings.file_resolver.project_root, - &settings.src, - ) { + if let Some(diagnostic) = + implicit_namespace_package(path, package, &settings.project_root, &settings.src) + { diagnostics.push(diagnostic); } } diff --git a/crates/ruff_linter/src/checkers/imports.rs b/crates/ruff_linter/src/checkers/imports.rs index 0c96fafffd08c9..cf85c69d4c73d7 100644 --- a/crates/ruff_linter/src/checkers/imports.rs +++ b/crates/ruff_linter/src/checkers/imports.rs @@ -16,7 +16,7 @@ use crate::directives::IsortDirectives; use crate::registry::Rule; use crate::rules::isort; use crate::rules::isort::block::{Block, BlockBuilder}; -use crate::settings::Settings; +use crate::settings::LinterSettings; use crate::source_kind::SourceKind; fn extract_import_map(path: &Path, package: Option<&Path>, blocks: &[&Block]) -> Option { @@ -81,7 +81,7 @@ pub(crate) fn check_imports( locator: &Locator, indexer: &Indexer, directives: &IsortDirectives, - settings: &Settings, + settings: &LinterSettings, stylist: &Stylist, path: &Path, package: Option<&Path>, diff --git a/crates/ruff_linter/src/checkers/logical_lines.rs b/crates/ruff_linter/src/checkers/logical_lines.rs index 5f464dd0e0019d..c5585c4b93181b 100644 --- a/crates/ruff_linter/src/checkers/logical_lines.rs +++ b/crates/ruff_linter/src/checkers/logical_lines.rs @@ -12,7 +12,7 @@ use crate::rules::pycodestyle::rules::logical_lines::{ whitespace_around_keywords, whitespace_around_named_parameter_equals, whitespace_before_comment, whitespace_before_parameters, LogicalLines, TokenFlags, }; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// Return the amount of indentation, expanding tabs to the next multiple of 8. fn expand_indent(line: &str) -> usize { @@ -34,7 +34,7 @@ pub(crate) fn check_logical_lines( tokens: &[LexResult], locator: &Locator, stylist: &Stylist, - settings: &Settings, + settings: &LinterSettings, ) -> Vec { let mut context = LogicalLinesContext::new(settings); @@ -132,12 +132,12 @@ pub(crate) fn check_logical_lines( #[derive(Debug, Clone)] pub(crate) struct LogicalLinesContext<'a> { - settings: &'a Settings, + settings: &'a LinterSettings, diagnostics: Vec, } impl<'a> LogicalLinesContext<'a> { - fn new(settings: &'a Settings) -> Self { + fn new(settings: &'a LinterSettings) -> Self { Self { settings, diagnostics: Vec::new(), diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index 0e323ab0329f77..9a762c6cab5cd1 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -14,7 +14,7 @@ use crate::noqa::{Directive, FileExemption, NoqaDirectives, NoqaMapping}; use crate::registry::{AsRule, Rule}; use crate::rule_redirects::get_redirect_target; use crate::rules::ruff::rules::{UnusedCodes, UnusedNOQA}; -use crate::settings::Settings; +use crate::settings::LinterSettings; pub(crate) fn check_noqa( diagnostics: &mut Vec, @@ -23,7 +23,7 @@ pub(crate) fn check_noqa( comment_ranges: &CommentRanges, noqa_line_for: &NoqaMapping, analyze_directives: bool, - settings: &Settings, + settings: &LinterSettings, ) -> Vec { // Identify any codes that are globally exempted (within the current file). let exemption = FileExemption::try_extract(locator.contents(), comment_ranges, path, locator); diff --git a/crates/ruff_linter/src/checkers/physical_lines.rs b/crates/ruff_linter/src/checkers/physical_lines.rs index 7bbea82a3a3989..1f5cec0a7c707d 100644 --- a/crates/ruff_linter/src/checkers/physical_lines.rs +++ b/crates/ruff_linter/src/checkers/physical_lines.rs @@ -12,14 +12,14 @@ use crate::rules::pycodestyle::rules::{ trailing_whitespace, }; use crate::rules::pylint; -use crate::settings::Settings; +use crate::settings::LinterSettings; pub(crate) fn check_physical_lines( locator: &Locator, stylist: &Stylist, indexer: &Indexer, doc_lines: &[TextSize], - settings: &Settings, + settings: &LinterSettings, ) -> Vec { let mut diagnostics: Vec = vec![]; @@ -99,7 +99,7 @@ mod tests { use crate::line_width::LineLength; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use super::check_physical_lines; @@ -117,9 +117,9 @@ mod tests { &stylist, &indexer, &[], - &Settings { + &LinterSettings { line_length, - ..Settings::for_rule(Rule::LineTooLong) + ..LinterSettings::for_rule(Rule::LineTooLong) }, ) }; diff --git a/crates/ruff_linter/src/checkers/tokens.rs b/crates/ruff_linter/src/checkers/tokens.rs index 93174b0cbdcbb0..98ecbc28983635 100644 --- a/crates/ruff_linter/src/checkers/tokens.rs +++ b/crates/ruff_linter/src/checkers/tokens.rs @@ -17,14 +17,14 @@ use crate::rules::{ eradicate, flake8_commas, flake8_executable, flake8_fixme, flake8_implicit_str_concat, flake8_pyi, flake8_quotes, flake8_todos, pycodestyle, pygrep_hooks, pylint, pyupgrade, ruff, }; -use crate::settings::Settings; +use crate::settings::LinterSettings; pub(crate) fn check_tokens( tokens: &[LexResult], path: &Path, locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, is_stub: bool, ) -> Vec { let mut diagnostics: Vec = vec![]; diff --git a/crates/ruff_linter/src/directives.rs b/crates/ruff_linter/src/directives.rs index 68619ef1af00a7..60f8c69b78651e 100644 --- a/crates/ruff_linter/src/directives.rs +++ b/crates/ruff_linter/src/directives.rs @@ -11,7 +11,7 @@ use ruff_python_index::Indexer; use ruff_source_file::Locator; use crate::noqa::NoqaMapping; -use crate::settings::Settings; +use crate::settings::LinterSettings; bitflags! { #[derive(Debug, Copy, Clone)] @@ -22,7 +22,7 @@ bitflags! { } impl Flags { - pub fn from_settings(settings: &Settings) -> Self { + pub fn from_settings(settings: &LinterSettings) -> Self { if settings .rules .iter_enabled() diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index 2b08fec96b2796..f07e3d3f0781af 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -32,7 +32,7 @@ use crate::message::Message; use crate::noqa::add_noqa; use crate::registry::{AsRule, Rule}; use crate::rules::pycodestyle; -use crate::settings::{flags, Settings}; +use crate::settings::{flags, LinterSettings}; use crate::source_kind::SourceKind; use crate::{directives, fs}; @@ -76,7 +76,7 @@ pub fn check_path( stylist: &Stylist, indexer: &Indexer, directives: &Directives, - settings: &Settings, + settings: &LinterSettings, noqa: flags::Noqa, source_kind: &SourceKind, source_type: PySourceType, @@ -269,7 +269,7 @@ pub fn add_noqa_to_path( package: Option<&Path>, source_kind: &SourceKind, source_type: PySourceType, - settings: &Settings, + settings: &LinterSettings, ) -> Result { let contents = source_kind.source_code(); @@ -336,7 +336,7 @@ pub fn add_noqa_to_path( pub fn lint_only( path: &Path, package: Option<&Path>, - settings: &Settings, + settings: &LinterSettings, noqa: flags::Noqa, source_kind: &SourceKind, source_type: PySourceType, @@ -418,7 +418,7 @@ pub fn lint_fix<'a>( path: &Path, package: Option<&Path>, noqa: flags::Noqa, - settings: &Settings, + settings: &LinterSettings, source_kind: &'a SourceKind, source_type: PySourceType, ) -> Result> { @@ -635,7 +635,7 @@ mod tests { } = test_notebook_path( &actual, expected, - &settings::Settings::for_rule(Rule::UnsortedImports), + &settings::LinterSettings::for_rule(Rule::UnsortedImports), )?; assert_messages!(messages, actual, source_notebook); Ok(()) @@ -652,7 +652,7 @@ mod tests { } = test_notebook_path( &actual, expected, - &settings::Settings::for_rule(Rule::UnusedImport), + &settings::LinterSettings::for_rule(Rule::UnusedImport), )?; assert_messages!(messages, actual, source_notebook); Ok(()) @@ -669,7 +669,7 @@ mod tests { } = test_notebook_path( &actual, expected, - &settings::Settings::for_rule(Rule::UnusedVariable), + &settings::LinterSettings::for_rule(Rule::UnusedVariable), )?; assert_messages!(messages, actual, source_notebook); Ok(()) @@ -686,7 +686,7 @@ mod tests { } = test_notebook_path( actual_path, &expected_path, - &settings::Settings::for_rule(Rule::UnusedImport), + &settings::LinterSettings::for_rule(Rule::UnusedImport), )?; let mut writer = Vec::new(); fixed_notebook.write(&mut writer)?; @@ -720,7 +720,7 @@ mod tests { let (_, transformed) = test_contents( &source_kind, path, - &settings::Settings::for_rule(Rule::UnusedImport), + &settings::LinterSettings::for_rule(Rule::UnusedImport), ); let linted_notebook = transformed.into_owned().expect_ipy_notebook(); let mut writer = Vec::new(); diff --git a/crates/ruff_linter/src/pyproject_toml.rs b/crates/ruff_linter/src/pyproject_toml.rs index c06fafb140374d..d6fa8ddb9a732f 100644 --- a/crates/ruff_linter/src/pyproject_toml.rs +++ b/crates/ruff_linter/src/pyproject_toml.rs @@ -10,7 +10,7 @@ use ruff_source_file::SourceFile; use crate::message::Message; use crate::registry::Rule; use crate::rules::ruff::rules::InvalidPyprojectToml; -use crate::settings::Settings; +use crate::settings::LinterSettings; use crate::IOError; /// Unlike [`pyproject_toml::PyProjectToml`], in our case `build_system` is also optional @@ -23,7 +23,7 @@ struct PyProjectToml { project: Option, } -pub fn lint_pyproject_toml(source_file: SourceFile, settings: &Settings) -> Vec { +pub fn lint_pyproject_toml(source_file: SourceFile, settings: &LinterSettings) -> Vec { let Some(err) = toml::from_str::(source_file.source_text()).err() else { return Vec::default(); }; diff --git a/crates/ruff_linter/src/rules/airflow/mod.rs b/crates/ruff_linter/src/rules/airflow/mod.rs index 12871a42aabc6d..34ba5e4c4a14a9 100644 --- a/crates/ruff_linter/src/rules/airflow/mod.rs +++ b/crates/ruff_linter/src/rules/airflow/mod.rs @@ -17,7 +17,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("airflow").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/eradicate/mod.rs b/crates/ruff_linter/src/rules/eradicate/mod.rs index a363458154a5e5..7a1a13c8891ffd 100644 --- a/crates/ruff_linter/src/rules/eradicate/mod.rs +++ b/crates/ruff_linter/src/rules/eradicate/mod.rs @@ -18,7 +18,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("eradicate").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs index 69e451fa557f79..7c712f20a167e2 100644 --- a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs +++ b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs @@ -4,7 +4,7 @@ use ruff_python_index::Indexer; use ruff_source_file::Locator; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; use super::super::detection::comment_contains_code; @@ -52,7 +52,7 @@ pub(crate) fn commented_out_code( diagnostics: &mut Vec, locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, ) { for range in indexer.comment_ranges() { let line = locator.full_lines(*range); diff --git a/crates/ruff_linter/src/rules/flake8_2020/mod.rs b/crates/ruff_linter/src/rules/flake8_2020/mod.rs index ac20ee0b388165..d7182d699179a0 100644 --- a/crates/ruff_linter/src/rules/flake8_2020/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_2020/mod.rs @@ -27,7 +27,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_2020").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_annotations/mod.rs b/crates/ruff_linter/src/rules/flake8_annotations/mod.rs index 2322045c272b0b..19f948c37991d4 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/mod.rs @@ -11,15 +11,15 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test] fn defaults() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/annotation_presence.py"), - &Settings { - ..Settings::for_rules(vec![ + &LinterSettings { + ..LinterSettings::for_rules(vec![ Rule::MissingTypeFunctionArgument, Rule::MissingTypeArgs, Rule::MissingTypeKwargs, @@ -42,12 +42,12 @@ mod tests { fn ignore_fully_untyped() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/ignore_fully_untyped.py"), - &Settings { + &LinterSettings { flake8_annotations: super::settings::Settings { ignore_fully_untyped: true, ..Default::default() }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::MissingTypeFunctionArgument, Rule::MissingTypeArgs, Rule::MissingTypeKwargs, @@ -70,12 +70,12 @@ mod tests { fn suppress_dummy_args() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/suppress_dummy_args.py"), - &Settings { + &LinterSettings { flake8_annotations: super::settings::Settings { suppress_dummy_args: true, ..Default::default() }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::MissingTypeFunctionArgument, Rule::MissingTypeArgs, Rule::MissingTypeKwargs, @@ -92,12 +92,12 @@ mod tests { fn mypy_init_return() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/mypy_init_return.py"), - &Settings { + &LinterSettings { flake8_annotations: super::settings::Settings { mypy_init_return: true, ..Default::default() }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::MissingReturnTypeUndocumentedPublicFunction, Rule::MissingReturnTypePrivateFunction, Rule::MissingReturnTypeSpecialMethod, @@ -114,12 +114,12 @@ mod tests { fn suppress_none_returning() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/suppress_none_returning.py"), - &Settings { + &LinterSettings { flake8_annotations: super::settings::Settings { suppress_none_returning: true, ..Default::default() }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::MissingTypeFunctionArgument, Rule::MissingTypeArgs, Rule::MissingTypeKwargs, @@ -142,12 +142,12 @@ mod tests { fn allow_star_arg_any() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/allow_star_arg_any.py"), - &Settings { + &LinterSettings { flake8_annotations: super::settings::Settings { allow_star_arg_any: true, ..Default::default() }, - ..Settings::for_rules(vec![Rule::AnyType]) + ..LinterSettings::for_rules(vec![Rule::AnyType]) }, )?; assert_messages!(diagnostics); @@ -158,8 +158,8 @@ mod tests { fn allow_overload() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/allow_overload.py"), - &Settings { - ..Settings::for_rules(vec![ + &LinterSettings { + ..LinterSettings::for_rules(vec![ Rule::MissingReturnTypeUndocumentedPublicFunction, Rule::MissingReturnTypePrivateFunction, Rule::MissingReturnTypeSpecialMethod, @@ -176,8 +176,8 @@ mod tests { fn allow_nested_overload() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/allow_nested_overload.py"), - &Settings { - ..Settings::for_rules(vec![ + &LinterSettings { + ..LinterSettings::for_rules(vec![ Rule::MissingReturnTypeUndocumentedPublicFunction, Rule::MissingReturnTypePrivateFunction, Rule::MissingReturnTypeSpecialMethod, @@ -194,7 +194,7 @@ mod tests { fn simple_magic_methods() -> Result<()> { let diagnostics = test_path( Path::new("flake8_annotations/simple_magic_methods.py"), - &Settings::for_rule(Rule::MissingReturnTypeSpecialMethod), + &LinterSettings::for_rule(Rule::MissingReturnTypeSpecialMethod), )?; assert_messages!(diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_async/mod.rs b/crates/ruff_linter/src/rules/flake8_async/mod.rs index 7865ddf6b0a669..37a451233eb286 100644 --- a/crates/ruff_linter/src/rules/flake8_async/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_async/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::BlockingHttpCallInAsyncFunction, Path::new("ASYNC100.py"))] @@ -20,7 +20,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_async").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_bandit/mod.rs b/crates/ruff_linter/src/rules/flake8_bandit/mod.rs index 6891c3d0901a41..8c64fd4d9fdcd5 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/mod.rs @@ -12,7 +12,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::Assert, Path::new("S101.py"))] @@ -51,7 +51,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_bandit").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -61,7 +61,7 @@ mod tests { fn check_hardcoded_tmp_additional_dirs() -> Result<()> { let diagnostics = test_path( Path::new("flake8_bandit/S108.py"), - &Settings { + &LinterSettings { flake8_bandit: super::settings::Settings { hardcoded_tmp_directory: vec![ "/tmp".to_string(), @@ -71,7 +71,7 @@ mod tests { ], check_typed_exception: false, }, - ..Settings::for_rule(Rule::HardcodedTempFile) + ..LinterSettings::for_rule(Rule::HardcodedTempFile) }, )?; assert_messages!("S108_extend", diagnostics); @@ -82,12 +82,12 @@ mod tests { fn check_typed_exception() -> Result<()> { let diagnostics = test_path( Path::new("flake8_bandit/S110.py"), - &Settings { + &LinterSettings { flake8_bandit: super::settings::Settings { check_typed_exception: true, ..Default::default() }, - ..Settings::for_rule(Rule::TryExceptPass) + ..LinterSettings::for_rule(Rule::TryExceptPass) }, )?; assert_messages!("S110_typed", diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_blind_except/mod.rs b/crates/ruff_linter/src/rules/flake8_blind_except/mod.rs index ce2611ffaa9849..0f21a30396152d 100644 --- a/crates/ruff_linter/src/rules/flake8_blind_except/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_blind_except/mod.rs @@ -17,7 +17,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_blind_except").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs index 7a4a1ff943bb3c..41459c4c5e7a35 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs @@ -20,7 +20,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_boolean_trap").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/mod.rs b/crates/ruff_linter/src/rules/flake8_bugbear/mod.rs index be5b06a88c7456..8ce32f9e071fc3 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::AbstractBaseClassWithoutAbstractMethod, Path::new("B024.py"))] @@ -57,7 +57,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_bugbear").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -68,7 +68,7 @@ mod tests { let snapshot = "B905.py"; let diagnostics = test_path( Path::new("flake8_bugbear").join(snapshot).as_path(), - &Settings::for_rule(Rule::ZipWithoutExplicitStrict), + &LinterSettings::for_rule(Rule::ZipWithoutExplicitStrict), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -79,14 +79,14 @@ mod tests { let snapshot = "extend_immutable_calls_arg_annotation".to_string(); let diagnostics = test_path( Path::new("flake8_bugbear/B006_extended.py"), - &Settings { + &LinterSettings { flake8_bugbear: super::settings::Settings { extend_immutable_calls: vec![ "custom.ImmutableTypeA".to_string(), "custom.ImmutableTypeB".to_string(), ], }, - ..Settings::for_rule(Rule::MutableArgumentDefault) + ..LinterSettings::for_rule(Rule::MutableArgumentDefault) }, )?; assert_messages!(snapshot, diagnostics); @@ -98,7 +98,7 @@ mod tests { let snapshot = "extend_immutable_calls_arg_default".to_string(); let diagnostics = test_path( Path::new("flake8_bugbear/B008_extended.py"), - &Settings { + &LinterSettings { flake8_bugbear: super::settings::Settings { extend_immutable_calls: vec![ "fastapi.Depends".to_string(), @@ -106,7 +106,7 @@ mod tests { "custom.ImmutableTypeA".to_string(), ], }, - ..Settings::for_rule(Rule::FunctionCallInDefaultArgument) + ..LinterSettings::for_rule(Rule::FunctionCallInDefaultArgument) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_builtins/mod.rs b/crates/ruff_linter/src/rules/flake8_builtins/mod.rs index 9321db78d76541..3ce0725066ca23 100644 --- a/crates/ruff_linter/src/rules/flake8_builtins/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_builtins/mod.rs @@ -12,7 +12,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::BuiltinVariableShadowing, Path::new("A001.py"))] @@ -22,7 +22,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_builtins").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -40,11 +40,11 @@ mod tests { let diagnostics = test_path( Path::new("flake8_builtins").join(path).as_path(), - &Settings { + &LinterSettings { flake8_builtins: super::settings::Settings { builtins_ignorelist: vec!["id".to_string(), "dir".to_string()], }, - ..Settings::for_rules(vec![rule_code]) + ..LinterSettings::for_rules(vec![rule_code]) }, )?; diff --git a/crates/ruff_linter/src/rules/flake8_commas/mod.rs b/crates/ruff_linter/src/rules/flake8_commas/mod.rs index d08f8fc8ee0494..c7a274f1b3da71 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_commas/mod.rs @@ -17,7 +17,7 @@ mod tests { let snapshot = path.to_string_lossy().into_owned(); let diagnostics = test_path( Path::new("flake8_commas").join(path).as_path(), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::MissingTrailingComma, Rule::TrailingCommaOnBareTuple, Rule::ProhibitedTrailingComma, diff --git a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs index 7c2f253c85e18d..3b79acf051e864 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs +++ b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs @@ -9,7 +9,7 @@ use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextRange}; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// Simplified token type. #[derive(Copy, Clone, PartialEq, Eq)] @@ -225,7 +225,7 @@ pub(crate) fn trailing_commas( diagnostics: &mut Vec, tokens: &[LexResult], locator: &Locator, - settings: &Settings, + settings: &LinterSettings, ) { let tokens = tokens .iter() diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs index 279b504280426b..74c2a69ac323f4 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/mod.rs @@ -12,7 +12,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::UnnecessaryCallAroundSorted, Path::new("C413.py"))] @@ -37,7 +37,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_comprehensions").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -52,11 +52,11 @@ mod tests { ); let diagnostics = test_path( Path::new("flake8_comprehensions").join(path).as_path(), - &Settings { + &LinterSettings { flake8_comprehensions: super::settings::Settings { allow_dict_calls_with_keyword_arguments: true, }, - ..Settings::for_rule(rule_code) + ..LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_copyright/mod.rs b/crates/ruff_linter/src/rules/flake8_copyright/mod.rs index 0d86c51cee53ee..4f09279047e51f 100644 --- a/crates/ruff_linter/src/rules/flake8_copyright/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_copyright/mod.rs @@ -18,7 +18,7 @@ mod tests { import os "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } @@ -32,7 +32,7 @@ import os import os "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } @@ -46,7 +46,7 @@ import os import os "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } @@ -60,7 +60,7 @@ import os import os "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } @@ -74,12 +74,12 @@ import os import os "# .trim(), - &settings::Settings { + &settings::LinterSettings { flake8_copyright: super::settings::Settings { author: Some("Ruff".to_string()), ..super::settings::Settings::default() }, - ..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]) + ..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]) }, ); assert_messages!(diagnostics); @@ -94,12 +94,12 @@ import os import os "# .trim(), - &settings::Settings { + &settings::LinterSettings { flake8_copyright: super::settings::Settings { author: Some("Ruff".to_string()), ..super::settings::Settings::default() }, - ..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]) + ..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]) }, ); assert_messages!(diagnostics); @@ -112,12 +112,12 @@ import os import os "# .trim(), - &settings::Settings { + &settings::LinterSettings { flake8_copyright: super::settings::Settings { min_file_size: 256, ..super::settings::Settings::default() }, - ..settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]) + ..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]) }, ); assert_messages!(diagnostics); @@ -151,7 +151,7 @@ import os # Copyright 2023 "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } @@ -162,7 +162,7 @@ import os r#"কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক "# .trim(), - &settings::Settings::for_rules(vec![Rule::MissingCopyrightNotice]), + &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); assert_messages!(diagnostics); } diff --git a/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs b/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs index 65585808335f8c..a0befbe14e62ff 100644 --- a/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs +++ b/crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs @@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Locator; use ruff_text_size::{TextRange, TextSize}; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for the absence of copyright notices within Python files. @@ -24,7 +24,7 @@ impl Violation for MissingCopyrightNotice { /// CPY001 pub(crate) fn missing_copyright_notice( locator: &Locator, - settings: &Settings, + settings: &LinterSettings, ) -> Option { // Ignore files that are too small to contain a copyright notice. if locator.len() < settings.flake8_copyright.min_file_size { diff --git a/crates/ruff_linter/src/rules/flake8_datetimez/mod.rs b/crates/ruff_linter/src/rules/flake8_datetimez/mod.rs index d8af5d3691aa23..f803eb3e3c6384 100644 --- a/crates/ruff_linter/src/rules/flake8_datetimez/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_datetimez/mod.rs @@ -25,7 +25,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_datetimez").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_debugger/mod.rs b/crates/ruff_linter/src/rules/flake8_debugger/mod.rs index 51181d43c32a09..293e314a1eee05 100644 --- a/crates/ruff_linter/src/rules/flake8_debugger/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_debugger/mod.rs @@ -18,7 +18,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_debugger").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_django/mod.rs b/crates/ruff_linter/src/rules/flake8_django/mod.rs index 59173927467a14..fd577ba74f4fb2 100644 --- a/crates/ruff_linter/src/rules/flake8_django/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_django/mod.rs @@ -23,7 +23,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_django").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_errmsg/mod.rs b/crates/ruff_linter/src/rules/flake8_errmsg/mod.rs index 66d5fb07441ead..12cd58e650c2d1 100644 --- a/crates/ruff_linter/src/rules/flake8_errmsg/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_errmsg/mod.rs @@ -16,7 +16,7 @@ mod tests { fn defaults() -> Result<()> { let diagnostics = test_path( Path::new("flake8_errmsg/EM.py"), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::RawStringInException, Rule::FStringInException, Rule::DotFormatInException, @@ -30,11 +30,11 @@ mod tests { fn custom() -> Result<()> { let diagnostics = test_path( Path::new("flake8_errmsg/EM.py"), - &settings::Settings { + &settings::LinterSettings { flake8_errmsg: super::settings::Settings { max_string_length: 20, }, - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::RawStringInException, Rule::FStringInException, Rule::DotFormatInException, diff --git a/crates/ruff_linter/src/rules/flake8_executable/mod.rs b/crates/ruff_linter/src/rules/flake8_executable/mod.rs index 25eb88bf5ec4c8..795a81d3b8cc8c 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/mod.rs @@ -32,7 +32,7 @@ mod tests { let snapshot = path.to_string_lossy().into_owned(); let diagnostics = test_path( Path::new("flake8_executable").join(path).as_path(), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::ShebangNotExecutable, Rule::ShebangMissingExecutableFile, Rule::ShebangLeadingWhitespace, diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/mod.rs index b38e64235fb1b9..506a5a63ca538c 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/mod.rs @@ -12,7 +12,7 @@ pub(crate) use shebang_not_executable::*; pub(crate) use shebang_not_first_line::*; use crate::comments::shebang::ShebangDirective; -use crate::settings::Settings; +use crate::settings::LinterSettings; mod shebang_leading_whitespace; mod shebang_missing_executable_file; @@ -24,7 +24,7 @@ pub(crate) fn from_tokens( tokens: &[LexResult], path: &Path, locator: &Locator, - settings: &Settings, + settings: &LinterSettings, diagnostics: &mut Vec, ) { let mut has_any_shebang = false; diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs index 265b5b3db3161d..7055a3061e192e 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs @@ -6,7 +6,7 @@ use ruff_python_trivia::is_python_whitespace; use ruff_source_file::Locator; use crate::registry::AsRule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for whitespace before a shebang directive. @@ -50,7 +50,7 @@ impl AlwaysAutofixableViolation for ShebangLeadingWhitespace { pub(crate) fn shebang_leading_whitespace( range: TextRange, locator: &Locator, - settings: &Settings, + settings: &LinterSettings, ) -> Option { // If the shebang is at the beginning of the file, abort. if range.start() == TextSize::from(0) { diff --git a/crates/ruff_linter/src/rules/flake8_fixme/mod.rs b/crates/ruff_linter/src/rules/flake8_fixme/mod.rs index 735e61c72e6d45..d2433fc8b0495d 100644 --- a/crates/ruff_linter/src/rules/flake8_fixme/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_fixme/mod.rs @@ -19,7 +19,7 @@ mod tests { let snapshot = format!("{}_T00.py", rule_code.as_ref()); let diagnostics = test_path( Path::new("flake8_fixme/T00.py"), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs b/crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs index c6e994bd429b80..d6265a78db7354 100644 --- a/crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_future_annotations/mod.rs @@ -29,9 +29,9 @@ mod tests { let snapshot = path.to_string_lossy().into_owned(); let diagnostics = test_path( Path::new("flake8_future_annotations").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py37, - ..settings::Settings::for_rule(Rule::FutureRewritableTypeAnnotation) + ..settings::LinterSettings::for_rule(Rule::FutureRewritableTypeAnnotation) }, )?; assert_messages!(snapshot, diagnostics); @@ -47,9 +47,9 @@ mod tests { let snapshot = format!("fa102_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_future_annotations").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py37, - ..settings::Settings::for_rule(Rule::FutureRequiredTypeAnnotation) + ..settings::LinterSettings::for_rule(Rule::FutureRequiredTypeAnnotation) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_gettext/mod.rs b/crates/ruff_linter/src/rules/flake8_gettext/mod.rs index 3f5f9be91ccb5c..eec91be60eb187 100644 --- a/crates/ruff_linter/src/rules/flake8_gettext/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_gettext/mod.rs @@ -31,7 +31,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_gettext").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs index 898b3689af73c3..d40100d18be2c2 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs @@ -20,7 +20,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_implicit_str_concat").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -37,11 +37,11 @@ mod tests { ); let diagnostics = test_path( Path::new("flake8_implicit_str_concat").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_implicit_str_concat: super::settings::Settings { allow_multiline: false, }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/mod.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/mod.rs index f2bde8a7238875..3bf95be28128ed 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/mod.rs @@ -12,14 +12,14 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; use crate::rules::flake8_import_conventions::settings::default_aliases; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test] fn defaults() -> Result<()> { let diagnostics = test_path( Path::new("flake8_import_conventions/defaults.py"), - &Settings::for_rule(Rule::UnconventionalImportAlias), + &LinterSettings::for_rule(Rule::UnconventionalImportAlias), )?; assert_messages!(diagnostics); Ok(()) @@ -34,13 +34,13 @@ mod tests { ])); let diagnostics = test_path( Path::new("flake8_import_conventions/custom.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases, banned_aliases: FxHashMap::default(), banned_from: FxHashSet::default(), }, - ..Settings::for_rule(Rule::UnconventionalImportAlias) + ..LinterSettings::for_rule(Rule::UnconventionalImportAlias) }, )?; assert_messages!(diagnostics); @@ -51,7 +51,7 @@ mod tests { fn custom_banned() -> Result<()> { let diagnostics = test_path( Path::new("flake8_import_conventions/custom_banned.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases: default_aliases(), banned_aliases: FxHashMap::from_iter([ @@ -71,7 +71,7 @@ mod tests { ]), banned_from: FxHashSet::default(), }, - ..Settings::for_rule(Rule::BannedImportAlias) + ..LinterSettings::for_rule(Rule::BannedImportAlias) }, )?; assert_messages!(diagnostics); @@ -82,7 +82,7 @@ mod tests { fn custom_banned_from() -> Result<()> { let diagnostics = test_path( Path::new("flake8_import_conventions/custom_banned_from.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases: default_aliases(), banned_aliases: FxHashMap::default(), @@ -92,7 +92,7 @@ mod tests { "pandas".to_string(), ]), }, - ..Settings::for_rule(Rule::BannedImportFrom) + ..LinterSettings::for_rule(Rule::BannedImportFrom) }, )?; assert_messages!(diagnostics); @@ -103,7 +103,7 @@ mod tests { fn remove_defaults() -> Result<()> { let diagnostics = test_path( Path::new("flake8_import_conventions/remove_default.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases: FxHashMap::from_iter([ ("altair".to_string(), "alt".to_string()), @@ -114,7 +114,7 @@ mod tests { banned_aliases: FxHashMap::default(), banned_from: FxHashSet::default(), }, - ..Settings::for_rule(Rule::UnconventionalImportAlias) + ..LinterSettings::for_rule(Rule::UnconventionalImportAlias) }, )?; assert_messages!(diagnostics); @@ -131,13 +131,13 @@ mod tests { let diagnostics = test_path( Path::new("flake8_import_conventions/override_default.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases, banned_aliases: FxHashMap::default(), banned_from: FxHashSet::default(), }, - ..Settings::for_rule(Rule::UnconventionalImportAlias) + ..LinterSettings::for_rule(Rule::UnconventionalImportAlias) }, )?; assert_messages!(diagnostics); @@ -157,13 +157,13 @@ mod tests { let diagnostics = test_path( Path::new("flake8_import_conventions/from_imports.py"), - &Settings { + &LinterSettings { flake8_import_conventions: super::settings::Settings { aliases, banned_aliases: FxHashMap::default(), banned_from: FxHashSet::default(), }, - ..Settings::for_rule(Rule::UnconventionalImportAlias) + ..LinterSettings::for_rule(Rule::UnconventionalImportAlias) }, )?; assert_messages!(diagnostics); @@ -174,7 +174,7 @@ mod tests { fn tricky() -> Result<()> { let diagnostics = test_path( Path::new("flake8_import_conventions/tricky.py"), - &Settings::for_rule(Rule::UnconventionalImportAlias), + &LinterSettings::for_rule(Rule::UnconventionalImportAlias), )?; assert_messages!(diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_logging/mod.rs b/crates/ruff_linter/src/rules/flake8_logging/mod.rs index 7a759b206fd9fa..1870a26e631aa2 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::DirectLoggerInstantiation, Path::new("LOG001.py"))] @@ -21,7 +21,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_logging").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs b/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs index 81c2595e60da4d..997a72e9ed3766 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs @@ -31,9 +31,9 @@ mod tests { let snapshot = path.to_string_lossy().into_owned(); let diagnostics = test_path( Path::new("flake8_logging_format").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { logger_objects: vec!["logging_setup.logger".to_string()], - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::LoggingStringFormat, Rule::LoggingPercentFormat, Rule::LoggingStringConcat, diff --git a/crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs b/crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs index afb27c3615e946..092ca12d6c1bdd 100644 --- a/crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_no_pep420/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::{test_path, test_resource_path}; #[test_case(Path::new("test_pass_init"), Path::new("example.py"))] @@ -30,11 +30,11 @@ mod tests { )); let diagnostics = test_path( p.as_path(), - &Settings { + &LinterSettings { namespace_packages: vec![test_resource_path( "fixtures/flake8_no_pep420/test_pass_namespace_package", )], - ..Settings::for_rule(Rule::ImplicitNamespacePackage) + ..LinterSettings::for_rule(Rule::ImplicitNamespacePackage) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_pie/mod.rs b/crates/ruff_linter/src/rules/flake8_pie/mod.rs index d31962dc28c3af..b631b66df66c64 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/mod.rs @@ -24,7 +24,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_pie").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_print/mod.rs b/crates/ruff_linter/src/rules/flake8_print/mod.rs index 3d5179b3e0c016..8d40e8e1afaf8f 100644 --- a/crates/ruff_linter/src/rules/flake8_print/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_print/mod.rs @@ -18,7 +18,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_print").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/mod.rs b/crates/ruff_linter/src/rules/flake8_pyi/mod.rs index c5c545a55bab06..b549b80406a7a3 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/mod.rs @@ -112,7 +112,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_pyi").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -124,9 +124,9 @@ mod tests { let snapshot = format!("py38_{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_pyi").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py38, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs index fc73220c91d121..937a416f724edd 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs @@ -295,9 +295,9 @@ mod tests { ) -> Result<()> { let diagnostics = test_path( Path::new("flake8_pytest_style").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_pytest_style: plugin_settings, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(name, diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_quotes/mod.rs b/crates/ruff_linter/src/rules/flake8_quotes/mod.rs index ee9648bcb3c70c..f3c1e86ad1046a 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; use super::settings::Quote; @@ -26,14 +26,14 @@ mod tests { let snapshot = format!("require_singles_over_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_quotes").join(path).as_path(), - &Settings { + &LinterSettings { flake8_quotes: super::settings::Settings { inline_quotes: Quote::Single, multiline_quotes: Quote::Single, docstring_quotes: Quote::Single, avoid_escape: true, }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::BadQuotesInlineString, Rule::BadQuotesMultilineString, Rule::BadQuotesDocstring, @@ -55,14 +55,14 @@ mod tests { let snapshot = format!("require_doubles_over_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_quotes").join(path).as_path(), - &Settings { + &LinterSettings { flake8_quotes: super::settings::Settings { inline_quotes: Quote::Double, multiline_quotes: Quote::Double, docstring_quotes: Quote::Double, avoid_escape: true, }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::BadQuotesInlineString, Rule::BadQuotesMultilineString, Rule::BadQuotesDocstring, @@ -88,14 +88,14 @@ mod tests { let snapshot = format!("require_docstring_doubles_over_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_quotes").join(path).as_path(), - &Settings { + &LinterSettings { flake8_quotes: super::settings::Settings { inline_quotes: Quote::Single, multiline_quotes: Quote::Single, docstring_quotes: Quote::Double, avoid_escape: true, }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::BadQuotesInlineString, Rule::BadQuotesMultilineString, Rule::BadQuotesDocstring, @@ -121,14 +121,14 @@ mod tests { let snapshot = format!("require_docstring_singles_over_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_quotes").join(path).as_path(), - &Settings { + &LinterSettings { flake8_quotes: super::settings::Settings { inline_quotes: Quote::Single, multiline_quotes: Quote::Double, docstring_quotes: Quote::Single, avoid_escape: true, }, - ..Settings::for_rules(vec![ + ..LinterSettings::for_rules(vec![ Rule::BadQuotesInlineString, Rule::BadQuotesMultilineString, Rule::BadQuotesDocstring, diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs index f4fd9581ab2b81..7cb159008147a0 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs @@ -8,7 +8,7 @@ use ruff_source_file::Locator; use crate::lex::docstring_detection::StateMachine; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; use super::super::settings::Quote; @@ -255,7 +255,7 @@ impl<'a> From<&'a str> for Trivia<'a> { } /// Q003 -fn docstring(locator: &Locator, range: TextRange, settings: &Settings) -> Option { +fn docstring(locator: &Locator, range: TextRange, settings: &LinterSettings) -> Option { let quotes_settings = &settings.flake8_quotes; let text = locator.slice(range); @@ -293,7 +293,11 @@ fn docstring(locator: &Locator, range: TextRange, settings: &Settings) -> Option } /// Q001, Q002 -fn strings(locator: &Locator, sequence: &[TextRange], settings: &Settings) -> Vec { +fn strings( + locator: &Locator, + sequence: &[TextRange], + settings: &LinterSettings, +) -> Vec { let mut diagnostics = vec![]; let quotes_settings = &settings.flake8_quotes; @@ -467,7 +471,7 @@ pub(crate) fn from_tokens( diagnostics: &mut Vec, lxr: &[LexResult], locator: &Locator, - settings: &Settings, + settings: &LinterSettings, ) { // Keep track of sequences of strings, which represent implicit string // concatenation, and should thus be handled as a single unit. diff --git a/crates/ruff_linter/src/rules/flake8_raise/mod.rs b/crates/ruff_linter/src/rules/flake8_raise/mod.rs index c6591b3a152517..d2d636b1e8e412 100644 --- a/crates/ruff_linter/src/rules/flake8_raise/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_raise/mod.rs @@ -18,7 +18,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_raise").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_return/mod.rs b/crates/ruff_linter/src/rules/flake8_return/mod.rs index d07613029a8205..bfad9cf6ba09c2 100644 --- a/crates/ruff_linter/src/rules/flake8_return/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_return/mod.rs @@ -13,7 +13,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::UnnecessaryReturnNone, Path::new("RET501.py"))] @@ -28,7 +28,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_return").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_self/mod.rs b/crates/ruff_linter/src/rules/flake8_self/mod.rs index 8c9ab60d7e70f6..70f1557c5ec1ae 100644 --- a/crates/ruff_linter/src/rules/flake8_self/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_self/mod.rs @@ -20,7 +20,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_self").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -30,11 +30,11 @@ mod tests { fn ignore_names() -> Result<()> { let diagnostics = test_path( Path::new("flake8_self/SLF001_extended.py"), - &settings::Settings { + &settings::LinterSettings { flake8_self: flake8_self::settings::Settings { ignore_names: vec!["_meta".to_string()], }, - ..settings::Settings::for_rule(Rule::PrivateMemberAccess) + ..settings::LinterSettings::for_rule(Rule::PrivateMemberAccess) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/mod.rs b/crates/ruff_linter/src/rules/flake8_simplify/mod.rs index a942a265aca0db..bd22a1a0ac7464 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/mod.rs @@ -47,7 +47,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_simplify").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_slots/mod.rs b/crates/ruff_linter/src/rules/flake8_slots/mod.rs index 4367fbb5f15cd7..422ff4f7be2f89 100644 --- a/crates/ruff_linter/src/rules/flake8_slots/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_slots/mod.rs @@ -19,7 +19,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_slots").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/mod.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/mod.rs index 12f48d331ed59f..c037ae78842ef1 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/mod.rs @@ -14,14 +14,14 @@ mod tests { use crate::registry::Rule; use crate::rules::flake8_tidy_imports; use crate::rules::flake8_tidy_imports::settings::{ApiBan, Strictness}; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test] fn banned_api() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID251.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { banned_api: FxHashMap::from_iter([ ( @@ -39,7 +39,7 @@ mod tests { ]), ..Default::default() }, - ..Settings::for_rules(vec![Rule::BannedApi]) + ..LinterSettings::for_rules(vec![Rule::BannedApi]) }, )?; assert_messages!(diagnostics); @@ -50,7 +50,7 @@ mod tests { fn banned_api_package() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { banned_api: FxHashMap::from_iter([ ( @@ -69,7 +69,7 @@ mod tests { ..Default::default() }, namespace_packages: vec![Path::new("my_package").to_path_buf()], - ..Settings::for_rules(vec![Rule::BannedApi]) + ..LinterSettings::for_rules(vec![Rule::BannedApi]) }, )?; assert_messages!(diagnostics); @@ -80,12 +80,12 @@ mod tests { fn ban_parent_imports() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID252.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { ban_relative_imports: Strictness::Parents, ..Default::default() }, - ..Settings::for_rules(vec![Rule::RelativeImports]) + ..LinterSettings::for_rules(vec![Rule::RelativeImports]) }, )?; assert_messages!(diagnostics); @@ -96,12 +96,12 @@ mod tests { fn ban_all_imports() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID252.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { ban_relative_imports: Strictness::All, ..Default::default() }, - ..Settings::for_rules(vec![Rule::RelativeImports]) + ..LinterSettings::for_rules(vec![Rule::RelativeImports]) }, )?; assert_messages!(diagnostics); @@ -112,13 +112,13 @@ mod tests { fn ban_parent_imports_package() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID/my_package/sublib/api/application.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { ban_relative_imports: Strictness::Parents, ..Default::default() }, namespace_packages: vec![Path::new("my_package").to_path_buf()], - ..Settings::for_rules(vec![Rule::RelativeImports]) + ..LinterSettings::for_rules(vec![Rule::RelativeImports]) }, )?; assert_messages!(diagnostics); @@ -129,7 +129,7 @@ mod tests { fn banned_module_level_imports() -> Result<()> { let diagnostics = test_path( Path::new("flake8_tidy_imports/TID253.py"), - &Settings { + &LinterSettings { flake8_tidy_imports: flake8_tidy_imports::settings::Settings { banned_module_level_imports: vec![ "torch".to_string(), @@ -137,7 +137,7 @@ mod tests { ], ..Default::default() }, - ..Settings::for_rules(vec![Rule::BannedModuleLevelImports]) + ..LinterSettings::for_rules(vec![Rule::BannedModuleLevelImports]) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/flake8_todos/mod.rs b/crates/ruff_linter/src/rules/flake8_todos/mod.rs index 3c305275996bb2..7a4129a78b6825 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/mod.rs @@ -23,7 +23,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_todos").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs index 23021d9caac712..5e6f84253b77fd 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs @@ -7,10 +7,10 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; +use crate::settings::LinterSettings; use crate::{ directives::{TodoComment, TodoDirective, TodoDirectiveKind}, registry::Rule, - settings::Settings, }; /// ## What it does @@ -240,7 +240,7 @@ pub(crate) fn todos( todo_comments: &[TodoComment], locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, ) { for todo_comment in todo_comments { let TodoComment { @@ -303,7 +303,7 @@ pub(crate) fn todos( fn directive_errors( diagnostics: &mut Vec, directive: &TodoDirective, - settings: &Settings, + settings: &LinterSettings, ) { if directive.content == "TODO" { return; diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs index 99a76cb890bd4e..314e1a67851f5d 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs @@ -39,7 +39,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_type_checking").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -49,12 +49,12 @@ mod tests { fn strict(rule_code: Rule, path: &Path) -> Result<()> { let diagnostics = test_path( Path::new("flake8_type_checking").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_type_checking: super::settings::Settings { strict: true, ..Default::default() }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(diagnostics); @@ -65,12 +65,12 @@ mod tests { fn exempt_modules(rule_code: Rule, path: &Path) -> Result<()> { let diagnostics = test_path( Path::new("flake8_type_checking").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_type_checking: super::settings::Settings { exempt_modules: vec!["pandas".to_string()], ..Default::default() }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(diagnostics); @@ -97,7 +97,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_type_checking").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_type_checking: super::settings::Settings { runtime_evaluated_base_classes: vec![ "pydantic.BaseModel".to_string(), @@ -105,7 +105,7 @@ mod tests { ], ..Default::default() }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); @@ -128,7 +128,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_type_checking").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { flake8_type_checking: super::settings::Settings { runtime_evaluated_decorators: vec![ "attrs.define".to_string(), @@ -136,7 +136,7 @@ mod tests { ], ..Default::default() }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); @@ -335,7 +335,7 @@ mod tests { fn contents(contents: &str, snapshot: &str) { let diagnostics = test_snippet( contents, - &settings::Settings::for_rules(Linter::Flake8TypeChecking.rules()), + &settings::LinterSettings::for_rules(Linter::Flake8TypeChecking.rules()), ); assert_messages!(snapshot, diagnostics); } diff --git a/crates/ruff_linter/src/rules/flake8_unused_arguments/mod.rs b/crates/ruff_linter/src/rules/flake8_unused_arguments/mod.rs index b1faea753457a7..0c412f7d0507b3 100644 --- a/crates/ruff_linter/src/rules/flake8_unused_arguments/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_unused_arguments/mod.rs @@ -23,7 +23,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_unused_arguments").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -33,11 +33,11 @@ mod tests { fn ignore_variadic_names() -> Result<()> { let diagnostics = test_path( Path::new("flake8_unused_arguments/ignore_variadic_names.py"), - &settings::Settings { + &settings::LinterSettings { flake8_unused_arguments: super::settings::Settings { ignore_variadic_names: true, }, - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::UnusedFunctionArgument, Rule::UnusedMethodArgument, Rule::UnusedClassMethodArgument, @@ -54,11 +54,11 @@ mod tests { fn enforce_variadic_names() -> Result<()> { let diagnostics = test_path( Path::new("flake8_unused_arguments/ignore_variadic_names.py"), - &settings::Settings { + &settings::LinterSettings { flake8_unused_arguments: super::settings::Settings { ignore_variadic_names: false, }, - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::UnusedFunctionArgument, Rule::UnusedMethodArgument, Rule::UnusedClassMethodArgument, diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs index b319fd92ee24d2..01b1ae356800e4 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs @@ -23,7 +23,7 @@ mod tests { let snapshot = format!("{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_use_pathlib").join(path).as_path(), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::OsPathAbspath, Rule::OsChmod, Rule::OsMkdir, @@ -67,7 +67,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flake8_use_pathlib").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/flynt/mod.rs b/crates/ruff_linter/src/rules/flynt/mod.rs index 96bc568cbe0419..28d49c212518a3 100644 --- a/crates/ruff_linter/src/rules/flynt/mod.rs +++ b/crates/ruff_linter/src/rules/flynt/mod.rs @@ -18,7 +18,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("flynt").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/isort/mod.rs b/crates/ruff_linter/src/rules/isort/mod.rs index 184700668966f3..84b0cf7c425d0d 100644 --- a/crates/ruff_linter/src/rules/isort/mod.rs +++ b/crates/ruff_linter/src/rules/isort/mod.rs @@ -324,7 +324,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; use crate::rules::isort::categorize::{ImportSection, KnownModules}; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::{test_path, test_resource_path}; use super::categorize::ImportType; @@ -383,9 +383,9 @@ mod tests { let snapshot = format!("{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -401,7 +401,7 @@ mod tests { let snapshot = format!("1_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { known_modules: KnownModules::new( vec![pattern("foo.bar"), pattern("baz")], @@ -413,7 +413,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -425,7 +425,7 @@ mod tests { let snapshot = format!("glob_1_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { known_modules: KnownModules::new( vec![pattern("foo.*"), pattern("baz")], @@ -437,7 +437,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -449,7 +449,7 @@ mod tests { let snapshot = format!("2_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { known_modules: KnownModules::new( vec![pattern("foo")], @@ -461,7 +461,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -477,9 +477,9 @@ mod tests { // Path::new("isort") // .join(path) // .as_path(), - // &Settings { + // &LinterSettings { // src: vec![test_resource_path("fixtures/isort")], - // ..Settings::for_rule(Rule::UnsortedImports) + // ..LinterSettings::for_rule(Rule::UnsortedImports) // }, // )?; // crate::assert_messages!(snapshot, diagnostics); @@ -491,7 +491,7 @@ mod tests { let snapshot = format!("known_local_folder_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { known_modules: KnownModules::new( vec![], @@ -503,7 +503,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -515,13 +515,13 @@ mod tests { let snapshot = format!("case_sensitive_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { case_sensitive: true, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -533,7 +533,7 @@ mod tests { let snapshot = format!("force_to_top_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { force_to_top: BTreeSet::from([ "z".to_string(), @@ -545,7 +545,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -557,13 +557,13 @@ mod tests { let snapshot = format!("combine_as_imports_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { combine_as_imports: true, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -575,14 +575,14 @@ mod tests { let snapshot = format!("force_wrap_aliases_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { force_wrap_aliases: true, combine_as_imports: true, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -594,13 +594,13 @@ mod tests { let snapshot = format!("split_on_trailing_comma_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { split_on_trailing_comma: false, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -612,7 +612,7 @@ mod tests { let snapshot = format!("force_single_line_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { force_single_line: true, single_line_exclusions: vec!["os".to_string(), "logging.handlers".to_string()] @@ -621,7 +621,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -633,13 +633,13 @@ mod tests { let snapshot = format!("propagate_inline_comments_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { force_single_line: true, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -651,13 +651,13 @@ mod tests { let snapshot = format!("order_by_type_false_{}", path.to_string_lossy()); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { order_by_type: false, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -673,7 +673,7 @@ mod tests { ); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { order_by_type: true, classes: BTreeSet::from([ @@ -685,7 +685,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -701,7 +701,7 @@ mod tests { ); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { order_by_type: true, constants: BTreeSet::from([ @@ -715,7 +715,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -731,7 +731,7 @@ mod tests { ); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { order_by_type: true, variables: BTreeSet::from([ @@ -743,7 +743,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -756,14 +756,14 @@ mod tests { let snapshot = format!("force_sort_within_sections_{}", path.to_string_lossy()); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { force_sort_within_sections: true, force_to_top: BTreeSet::from(["z".to_string()]), ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -786,7 +786,7 @@ mod tests { let snapshot = format!("required_import_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort/required_imports").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { required_imports: BTreeSet::from([ @@ -794,7 +794,7 @@ mod tests { ]), ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::MissingRequiredImport) + ..LinterSettings::for_rule(Rule::MissingRequiredImport) }, )?; assert_messages!(snapshot, diagnostics); @@ -816,7 +816,7 @@ mod tests { let snapshot = format!("required_import_with_alias_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort/required_imports").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { required_imports: BTreeSet::from([ @@ -824,7 +824,7 @@ mod tests { ]), ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::MissingRequiredImport) + ..LinterSettings::for_rule(Rule::MissingRequiredImport) }, )?; assert_messages!(snapshot, diagnostics); @@ -839,7 +839,7 @@ mod tests { let snapshot = format!("required_imports_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort/required_imports").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { required_imports: BTreeSet::from([ @@ -848,7 +848,7 @@ mod tests { ]), ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::MissingRequiredImport) + ..LinterSettings::for_rule(Rule::MissingRequiredImport) }, )?; assert_messages!(snapshot, diagnostics); @@ -863,7 +863,7 @@ mod tests { let snapshot = format!("combined_required_imports_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort/required_imports").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { required_imports: BTreeSet::from(["from __future__ import annotations, \ @@ -871,7 +871,7 @@ mod tests { .to_string()]), ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::MissingRequiredImport) + ..LinterSettings::for_rule(Rule::MissingRequiredImport) }, )?; assert_messages!(snapshot, diagnostics); @@ -886,13 +886,13 @@ mod tests { let snapshot = format!("straight_required_import_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort/required_imports").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { required_imports: BTreeSet::from(["import os".to_string()]), ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::MissingRequiredImport) + ..LinterSettings::for_rule(Rule::MissingRequiredImport) }, )?; assert_messages!(snapshot, diagnostics); @@ -904,13 +904,13 @@ mod tests { let snapshot = format!("closest_to_furthest_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { relative_imports_order: RelativeImportsOrder::ClosestToFurthest, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -922,7 +922,7 @@ mod tests { let snapshot = format!("no_lines_before.py_{}", path.to_string_lossy()); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { no_lines_before: BTreeSet::from([ ImportSection::Known(ImportType::Future), @@ -934,7 +934,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -950,7 +950,7 @@ mod tests { ); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { no_lines_before: BTreeSet::from([ ImportSection::Known(ImportType::StandardLibrary), @@ -959,7 +959,7 @@ mod tests { ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -974,13 +974,13 @@ mod tests { let snapshot = format!("lines_after_imports_{}", path.to_string_lossy()); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { lines_after_imports: 3, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -993,13 +993,13 @@ mod tests { let snapshot = format!("lines_between_types{}", path.to_string_lossy()); let mut diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { isort: super::settings::Settings { lines_between_types: 2, ..super::settings::Settings::default() }, src: vec![test_resource_path("fixtures/isort")], - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; diagnostics.sort_by_key(Ranged::start); @@ -1012,7 +1012,7 @@ mod tests { let snapshot = format!("{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { forced_separate: vec![ @@ -1023,7 +1023,7 @@ mod tests { ], ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -1035,7 +1035,7 @@ mod tests { let snapshot = format!("sections_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { known_modules: KnownModules::new( @@ -1056,7 +1056,7 @@ mod tests { ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -1068,7 +1068,7 @@ mod tests { let snapshot = format!("section_order_{}", path.to_string_lossy()); let diagnostics = test_path( Path::new("isort").join(path).as_path(), - &Settings { + &LinterSettings { src: vec![test_resource_path("fixtures/isort")], isort: super::settings::Settings { known_modules: KnownModules::new( @@ -1088,7 +1088,7 @@ mod tests { ], ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(snapshot, diagnostics); @@ -1099,13 +1099,13 @@ mod tests { fn detect_same_package() -> Result<()> { let diagnostics = test_path( Path::new("isort/detect_same_package/foo/bar.py"), - &Settings { + &LinterSettings { src: vec![], isort: super::settings::Settings { detect_same_package: true, ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(diagnostics); @@ -1116,13 +1116,13 @@ mod tests { fn no_detect_same_package() -> Result<()> { let diagnostics = test_path( Path::new("isort/detect_same_package/foo/bar.py"), - &Settings { + &LinterSettings { src: vec![], isort: super::settings::Settings { detect_same_package: false, ..super::settings::Settings::default() }, - ..Settings::for_rule(Rule::UnsortedImports) + ..LinterSettings::for_rule(Rule::UnsortedImports) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs index 73a5dc0da64339..240dc7e76f4fdd 100644 --- a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs @@ -12,7 +12,7 @@ use ruff_text_size::{TextRange, TextSize}; use crate::importer::Importer; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Adds any required imports, as specified by the user, to the top of the @@ -90,7 +90,7 @@ fn add_required_import( python_ast: &Suite, locator: &Locator, stylist: &Stylist, - settings: &Settings, + settings: &LinterSettings, source_type: PySourceType, ) -> Option { // Don't add imports to semantically-empty files. @@ -130,7 +130,7 @@ pub(crate) fn add_required_imports( python_ast: &Suite, locator: &Locator, stylist: &Stylist, - settings: &Settings, + settings: &LinterSettings, source_type: PySourceType, ) -> Vec { settings diff --git a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs index f3f0ced20c2603..62b2043f8c49a5 100644 --- a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs @@ -14,7 +14,7 @@ use ruff_text_size::{Ranged, TextRange}; use crate::line_width::LineWidthBuilder; use crate::registry::AsRule; -use crate::settings::Settings; +use crate::settings::LinterSettings; use super::super::block::Block; use super::super::{comments, format_imports}; @@ -85,7 +85,7 @@ pub(crate) fn organize_imports( locator: &Locator, stylist: &Stylist, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, package: Option<&Path>, source_type: PySourceType, ) -> Option { diff --git a/crates/ruff_linter/src/rules/mccabe/mod.rs b/crates/ruff_linter/src/rules/mccabe/mod.rs index 697859e26a52bb..e8d1d3313f163b 100644 --- a/crates/ruff_linter/src/rules/mccabe/mod.rs +++ b/crates/ruff_linter/src/rules/mccabe/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(0)] @@ -21,9 +21,9 @@ mod tests { let snapshot = format!("max_complexity_{max_complexity}"); let diagnostics = test_path( Path::new("mccabe/C901.py"), - &Settings { + &LinterSettings { mccabe: super::settings::Settings { max_complexity }, - ..Settings::for_rules(vec![Rule::ComplexStructure]) + ..LinterSettings::for_rules(vec![Rule::ComplexStructure]) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/numpy/mod.rs b/crates/ruff_linter/src/rules/numpy/mod.rs index 2bdb951dac5b16..027b543dd60f9b 100644 --- a/crates/ruff_linter/src/rules/numpy/mod.rs +++ b/crates/ruff_linter/src/rules/numpy/mod.rs @@ -20,7 +20,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("numpy").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/pandas_vet/mod.rs b/crates/ruff_linter/src/rules/pandas_vet/mod.rs index b2c2d150fe33f1..3422fc71ab4f28 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/mod.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/mod.rs @@ -351,7 +351,7 @@ mod tests { fn contents(contents: &str, snapshot: &str) { let diagnostics = test_snippet( contents, - &settings::Settings::for_rules(Linter::PandasVet.rules()), + &settings::LinterSettings::for_rules(Linter::PandasVet.rules()), ); assert_messages!(snapshot, diagnostics); } @@ -366,7 +366,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pandas_vet").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/pep8_naming/mod.rs b/crates/ruff_linter/src/rules/pep8_naming/mod.rs index f7e55dfe1de175..49ab25abfc2c9f 100644 --- a/crates/ruff_linter/src/rules/pep8_naming/mod.rs +++ b/crates/ruff_linter/src/rules/pep8_naming/mod.rs @@ -79,8 +79,8 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pep8_naming").join(path).as_path(), - &settings::Settings { - ..settings::Settings::for_rule(rule_code) + &settings::LinterSettings { + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); @@ -91,7 +91,7 @@ mod tests { fn classmethod_decorators() -> Result<()> { let diagnostics = test_path( Path::new("pep8_naming").join("N805.py").as_path(), - &settings::Settings { + &settings::LinterSettings { pep8_naming: pep8_naming::settings::Settings { classmethod_decorators: vec![ "classmethod".to_string(), @@ -99,7 +99,7 @@ mod tests { ], ..Default::default() }, - ..settings::Settings::for_rule(Rule::InvalidFirstArgumentNameForMethod) + ..settings::LinterSettings::for_rule(Rule::InvalidFirstArgumentNameForMethod) }, )?; assert_messages!(diagnostics); @@ -126,7 +126,7 @@ mod tests { let snapshot = format!("ignore_names_{}_{path}", rule_code.noqa_code()); let diagnostics = test_path( PathBuf::from_iter(["pep8_naming", "ignore_names", path]).as_path(), - &settings::Settings { + &settings::LinterSettings { pep8_naming: pep8_naming::settings::Settings { ignore_names: vec![ IdentifierPattern::new("*allowed*").unwrap(), @@ -136,7 +136,7 @@ mod tests { ], ..Default::default() }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/perflint/mod.rs b/crates/ruff_linter/src/rules/perflint/mod.rs index 0f060aefa136c7..2d073e639e242e 100644 --- a/crates/ruff_linter/src/rules/perflint/mod.rs +++ b/crates/ruff_linter/src/rules/perflint/mod.rs @@ -11,7 +11,7 @@ mod tests { use crate::assert_messages; use crate::registry::Rule; use crate::settings::types::PythonVersion; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::UnnecessaryListCast, Path::new("PERF101.py"))] @@ -24,7 +24,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("perflint").join(path).as_path(), - &Settings::for_rule(rule_code).with_target_version(PythonVersion::Py310), + &LinterSettings::for_rule(rule_code).with_target_version(PythonVersion::Py310), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/pycodestyle/mod.rs b/crates/ruff_linter/src/rules/pycodestyle/mod.rs index c6387432637e84..d5fb9eb9e3f2b4 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/mod.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/mod.rs @@ -52,7 +52,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pycodestyle").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -62,7 +62,7 @@ mod tests { fn w292_4() -> Result<()> { let diagnostics = test_path( Path::new("pycodestyle/W292_4.py"), - &settings::Settings::for_rule(Rule::MissingNewlineAtEndOfFile), + &settings::LinterSettings::for_rule(Rule::MissingNewlineAtEndOfFile), )?; assert_messages!(diagnostics); @@ -112,7 +112,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pycodestyle").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -122,7 +122,7 @@ mod tests { fn constant_literals() -> Result<()> { let diagnostics = test_path( Path::new("pycodestyle/constant_literals.py"), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::NoneComparison, Rule::TrueFalseComparison, Rule::IsLiteral, @@ -136,7 +136,7 @@ mod tests { fn shebang() -> Result<()> { let diagnostics = test_path( Path::new("pycodestyle/shebang.py"), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::TooFewSpacesBeforeInlineComment, Rule::NoSpaceAfterInlineComment, Rule::NoSpaceAfterBlockComment, @@ -153,12 +153,12 @@ mod tests { let snapshot = format!("task_tags_{ignore_overlong_task_comments}"); let diagnostics = test_path( Path::new("pycodestyle/E501_1.py"), - &settings::Settings { + &settings::LinterSettings { pycodestyle: Settings { ignore_overlong_task_comments, ..Settings::default() }, - ..settings::Settings::for_rule(Rule::LineTooLong) + ..settings::LinterSettings::for_rule(Rule::LineTooLong) }, )?; assert_messages!(snapshot, diagnostics); @@ -169,12 +169,12 @@ mod tests { fn max_doc_length() -> Result<()> { let diagnostics = test_path( Path::new("pycodestyle/W505.py"), - &settings::Settings { + &settings::LinterSettings { pycodestyle: Settings { max_doc_length: Some(LineLength::try_from(50).unwrap()), ..Settings::default() }, - ..settings::Settings::for_rule(Rule::DocLineTooLong) + ..settings::LinterSettings::for_rule(Rule::DocLineTooLong) }, )?; assert_messages!(diagnostics); @@ -185,12 +185,12 @@ mod tests { fn max_doc_length_with_utf_8() -> Result<()> { let diagnostics = test_path( Path::new("pycodestyle/W505_utf_8.py"), - &settings::Settings { + &settings::LinterSettings { pycodestyle: Settings { max_doc_length: Some(LineLength::try_from(50).unwrap()), ..Settings::default() }, - ..settings::Settings::for_rule(Rule::DocLineTooLong) + ..settings::LinterSettings::for_rule(Rule::DocLineTooLong) }, )?; assert_messages!(diagnostics); @@ -205,10 +205,10 @@ mod tests { let snapshot = format!("tab_size_{tab_size}"); let diagnostics = test_path( Path::new("pycodestyle/E501_2.py"), - &settings::Settings { + &settings::LinterSettings { tab_size: NonZeroU8::new(tab_size).unwrap().into(), line_length: LineLength::try_from(6).unwrap(), - ..settings::Settings::for_rule(Rule::LineTooLong) + ..settings::LinterSettings::for_rule(Rule::LineTooLong) }, )?; assert_messages!(snapshot, diagnostics); diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs index fa253d0e0350ce..2ca7657ff273d3 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs @@ -9,7 +9,7 @@ use ruff_python_index::Indexer; use ruff_source_file::Locator; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for compound statements (multiple statements on the same line). @@ -104,7 +104,7 @@ pub(crate) fn compound_statements( lxr: &[LexResult], locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, ) { // Track the last seen instance of a variety of tokens. let mut colon = None; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs index e4e8b3ae330cd8..efa002ab841778 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/doc_line_too_long.rs @@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Line; use crate::rules::pycodestyle::helpers::is_overlong; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for doc lines that exceed the specified maximum character length. @@ -61,7 +61,7 @@ impl Violation for DocLineTooLong { } /// W505 -pub(crate) fn doc_line_too_long(line: &Line, settings: &Settings) -> Option { +pub(crate) fn doc_line_too_long(line: &Line, settings: &LinterSettings) -> Option { let Some(limit) = settings.pycodestyle.max_doc_length else { return None; }; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs index 1b25557e3d1056..db18c37f1e6626 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/line_too_long.rs @@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Line; use crate::rules::pycodestyle::helpers::is_overlong; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for lines that exceed the specified maximum character length. @@ -55,7 +55,7 @@ impl Violation for LineTooLong { } /// E501 -pub(crate) fn line_too_long(line: &Line, settings: &Settings) -> Option { +pub(crate) fn line_too_long(line: &Line, settings: &LinterSettings) -> Option { let limit = settings.line_length; is_overlong( diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs index 6f62451dc8c398..88483409e58502 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -5,7 +5,7 @@ use ruff_source_file::{Line, Locator}; use ruff_text_size::{TextLen, TextRange, TextSize}; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for superfluous trailing whitespace. @@ -76,7 +76,7 @@ pub(crate) fn trailing_whitespace( line: &Line, locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, ) -> Option { let whitespace_len: TextSize = line .chars() diff --git a/crates/ruff_linter/src/rules/pydocstyle/mod.rs b/crates/ruff_linter/src/rules/pydocstyle/mod.rs index c8a525466665b2..dae662eb99e07f 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/mod.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/mod.rs @@ -90,7 +90,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pydocstyle").join(path).as_path(), - &settings::Settings { + &settings::LinterSettings { pydocstyle: Settings { convention: None, ignore_decorators: BTreeSet::from_iter(["functools.wraps".to_string()]), @@ -98,7 +98,7 @@ mod tests { "gi.repository.GObject.Property".to_string() ]), }, - ..settings::Settings::for_rule(rule_code) + ..settings::LinterSettings::for_rule(rule_code) }, )?; assert_messages!(snapshot, diagnostics); @@ -109,7 +109,7 @@ mod tests { fn bom() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/bom.py"), - &settings::Settings::for_rule(Rule::TripleSingleQuotes), + &settings::LinterSettings::for_rule(Rule::TripleSingleQuotes), )?; assert_messages!(diagnostics); Ok(()) @@ -119,7 +119,7 @@ mod tests { fn d417_unspecified() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/D417.py"), - &settings::Settings { + &settings::LinterSettings { // When inferring the convention, we'll see a few false negatives. // See: https://github.com/PyCQA/pydocstyle/issues/459. pydocstyle: Settings { @@ -127,7 +127,7 @@ mod tests { ignore_decorators: BTreeSet::new(), property_decorators: BTreeSet::new(), }, - ..settings::Settings::for_rule(Rule::UndocumentedParam) + ..settings::LinterSettings::for_rule(Rule::UndocumentedParam) }, )?; assert_messages!(diagnostics); @@ -138,14 +138,14 @@ mod tests { fn d417_google() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/D417.py"), - &settings::Settings { + &settings::LinterSettings { // With explicit Google convention, we should flag every function. pydocstyle: Settings { convention: Some(Convention::Google), ignore_decorators: BTreeSet::new(), property_decorators: BTreeSet::new(), }, - ..settings::Settings::for_rule(Rule::UndocumentedParam) + ..settings::LinterSettings::for_rule(Rule::UndocumentedParam) }, )?; assert_messages!(diagnostics); @@ -156,14 +156,14 @@ mod tests { fn d417_numpy() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/D417.py"), - &settings::Settings { + &settings::LinterSettings { // With explicit Google convention, we shouldn't flag anything. pydocstyle: Settings { convention: Some(Convention::Numpy), ignore_decorators: BTreeSet::new(), property_decorators: BTreeSet::new(), }, - ..settings::Settings::for_rule(Rule::UndocumentedParam) + ..settings::LinterSettings::for_rule(Rule::UndocumentedParam) }, )?; assert_messages!(diagnostics); @@ -174,7 +174,10 @@ mod tests { fn d209_d400() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/D209_D400.py"), - &settings::Settings::for_rules([Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod]), + &settings::LinterSettings::for_rules([ + Rule::NewLineAfterLastParagraph, + Rule::EndsInPeriod, + ]), )?; assert_messages!(diagnostics); Ok(()) @@ -184,7 +187,7 @@ mod tests { fn all() -> Result<()> { let diagnostics = test_path( Path::new("pydocstyle/all.py"), - &settings::Settings::for_rules([ + &settings::LinterSettings::for_rules([ Rule::UndocumentedPublicModule, Rule::UndocumentedPublicClass, Rule::UndocumentedPublicMethod, diff --git a/crates/ruff_linter/src/rules/pyflakes/mod.rs b/crates/ruff_linter/src/rules/pyflakes/mod.rs index 97ab5d158ed79c..1ce5133933c917 100644 --- a/crates/ruff_linter/src/rules/pyflakes/mod.rs +++ b/crates/ruff_linter/src/rules/pyflakes/mod.rs @@ -26,7 +26,7 @@ mod tests { use crate::linter::{check_path, LinterResult}; use crate::registry::{AsRule, Linter, Rule}; use crate::rules::pyflakes; - use crate::settings::{flags, Settings}; + use crate::settings::{flags, LinterSettings}; use crate::source_kind::SourceKind; use crate::test::{test_path, test_snippet}; use crate::{assert_messages, directives}; @@ -147,7 +147,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pyflakes").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -157,9 +157,9 @@ mod tests { fn f841_dummy_variable_rgx() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/F841_0.py"), - &Settings { + &LinterSettings { dummy_variable_rgx: Regex::new(r"^z$").unwrap(), - ..Settings::for_rule(Rule::UnusedVariable) + ..LinterSettings::for_rule(Rule::UnusedVariable) }, )?; assert_messages!(diagnostics); @@ -170,7 +170,7 @@ mod tests { fn init() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/__init__.py"), - &Settings::for_rules(vec![Rule::UndefinedName, Rule::UndefinedExport]), + &LinterSettings::for_rules(vec![Rule::UndefinedName, Rule::UndefinedExport]), )?; assert_messages!(diagnostics); Ok(()) @@ -180,7 +180,7 @@ mod tests { fn default_builtins() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/builtins.py"), - &Settings::for_rules(vec![Rule::UndefinedName]), + &LinterSettings::for_rules(vec![Rule::UndefinedName]), )?; assert_messages!(diagnostics); Ok(()) @@ -190,9 +190,9 @@ mod tests { fn extra_builtins() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/builtins.py"), - &Settings { + &LinterSettings { builtins: vec!["_".to_string()], - ..Settings::for_rules(vec![Rule::UndefinedName]) + ..LinterSettings::for_rules(vec![Rule::UndefinedName]) }, )?; assert_messages!(diagnostics); @@ -203,7 +203,7 @@ mod tests { fn default_typing_modules() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/typing_modules.py"), - &Settings::for_rules(vec![Rule::UndefinedName]), + &LinterSettings::for_rules(vec![Rule::UndefinedName]), )?; assert_messages!(diagnostics); Ok(()) @@ -213,9 +213,9 @@ mod tests { fn extra_typing_modules() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/typing_modules.py"), - &Settings { + &LinterSettings { typing_modules: vec!["airflow.typing_compat".to_string()], - ..Settings::for_rules(vec![Rule::UndefinedName]) + ..LinterSettings::for_rules(vec![Rule::UndefinedName]) }, )?; assert_messages!(diagnostics); @@ -226,7 +226,7 @@ mod tests { fn future_annotations() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/future_annotations.py"), - &Settings::for_rules(vec![Rule::UnusedImport, Rule::UndefinedName]), + &LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UndefinedName]), )?; assert_messages!(diagnostics); Ok(()) @@ -236,7 +236,7 @@ mod tests { fn multi_statement_lines() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/multi_statement_lines.py"), - &Settings::for_rule(Rule::UnusedImport), + &LinterSettings::for_rule(Rule::UnusedImport), )?; assert_messages!(diagnostics); Ok(()) @@ -246,9 +246,9 @@ mod tests { fn relative_typing_module() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/project/foo/bar.py"), - &Settings { + &LinterSettings { typing_modules: vec!["foo.typical".to_string()], - ..Settings::for_rules(vec![Rule::UndefinedName]) + ..LinterSettings::for_rules(vec![Rule::UndefinedName]) }, )?; assert_messages!(diagnostics); @@ -259,9 +259,9 @@ mod tests { fn nested_relative_typing_module() -> Result<()> { let diagnostics = test_path( Path::new("pyflakes/project/foo/bop/baz.py"), - &Settings { + &LinterSettings { typing_modules: vec!["foo.typical".to_string()], - ..Settings::for_rules(vec![Rule::UndefinedName]) + ..LinterSettings::for_rules(vec![Rule::UndefinedName]) }, )?; assert_messages!(diagnostics); @@ -273,11 +273,11 @@ mod tests { let snapshot = "extend_immutable_calls".to_string(); let diagnostics = test_path( Path::new("pyflakes/F401_15.py"), - &Settings { + &LinterSettings { pyflakes: pyflakes::settings::Settings { extend_generics: vec!["django.db.models.ForeignKey".to_string()], }, - ..Settings::for_rules(vec![Rule::UnusedImport]) + ..LinterSettings::for_rules(vec![Rule::UnusedImport]) }, )?; assert_messages!(snapshot, diagnostics); @@ -500,7 +500,10 @@ mod tests { "load_after_unbind_from_class_scope" )] fn contents(contents: &str, snapshot: &str) { - let diagnostics = test_snippet(contents, &Settings::for_rules(Linter::Pyflakes.rules())); + let diagnostics = test_snippet( + contents, + &LinterSettings::for_rules(Linter::Pyflakes.rules()), + ); assert_messages!(snapshot, diagnostics); } @@ -510,7 +513,7 @@ mod tests { let contents = dedent(contents); let source_type = PySourceType::default(); let source_kind = SourceKind::Python(contents.to_string()); - let settings = Settings::for_rules(Linter::Pyflakes.rules()); + let settings = LinterSettings::for_rules(Linter::Pyflakes.rules()); let tokens: Vec = ruff_python_parser::tokenize(&contents, source_type.as_mode()); let locator = Locator::new(&contents); let stylist = Stylist::from_tokens(&tokens, &locator); diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs b/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs index c128517518da0e..5a64e2c53513f1 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs @@ -24,7 +24,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pygrep_hooks").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/pylint/helpers.rs b/crates/ruff_linter/src/rules/pylint/helpers.rs index 60bb0dd22329d3..effffd71fb8b57 100644 --- a/crates/ruff_linter/src/rules/pylint/helpers.rs +++ b/crates/ruff_linter/src/rules/pylint/helpers.rs @@ -5,7 +5,7 @@ use ruff_python_ast::{Arguments, CmpOp, Constant, Expr}; use ruff_python_semantic::analyze::function_type; use ruff_python_semantic::{ScopeKind, SemanticModel}; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// Returns the value of the `name` parameter to, e.g., a `TypeVar` constructor. pub(super) fn type_param_name(arguments: &Arguments) -> Option<&str> { @@ -22,7 +22,7 @@ pub(super) fn type_param_name(arguments: &Arguments) -> Option<&str> { } } -pub(super) fn in_dunder_init(semantic: &SemanticModel, settings: &Settings) -> bool { +pub(super) fn in_dunder_init(semantic: &SemanticModel, settings: &LinterSettings) -> bool { let scope = semantic.current_scope(); let ScopeKind::Function(ast::StmtFunctionDef { name, diff --git a/crates/ruff_linter/src/rules/pylint/mod.rs b/crates/ruff_linter/src/rules/pylint/mod.rs index ad3f7f3d66db06..2e173f65577198 100644 --- a/crates/ruff_linter/src/rules/pylint/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/mod.rs @@ -15,7 +15,7 @@ mod tests { use crate::registry::Rule; use crate::rules::pylint; use crate::settings::types::PythonVersion; - use crate::settings::Settings; + use crate::settings::LinterSettings; use crate::test::test_path; #[test_case(Rule::AssertOnStringLiteral, Path::new("assert_on_string_literal.py"))] @@ -137,7 +137,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("pylint").join(path).as_path(), - &Settings::for_rule(rule_code), + &LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -147,7 +147,7 @@ mod tests { fn repeated_isinstance_calls() -> Result<()> { let diagnostics = test_path( Path::new("pylint/repeated_isinstance_calls.py"), - &Settings::for_rule(Rule::RepeatedIsinstanceCalls) + &LinterSettings::for_rule(Rule::RepeatedIsinstanceCalls) .with_target_version(PythonVersion::Py39), )?; assert_messages!(diagnostics); @@ -158,7 +158,8 @@ mod tests { fn continue_in_finally() -> Result<()> { let diagnostics = test_path( Path::new("pylint/continue_in_finally.py"), - &Settings::for_rule(Rule::ContinueInFinally).with_target_version(PythonVersion::Py37), + &LinterSettings::for_rule(Rule::ContinueInFinally) + .with_target_version(PythonVersion::Py37), )?; assert_messages!(diagnostics); Ok(()) @@ -168,12 +169,12 @@ mod tests { fn allow_magic_value_types() -> Result<()> { let diagnostics = test_path( Path::new("pylint/magic_value_comparison.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { allow_magic_value_types: vec![pylint::settings::ConstantType::Int], ..pylint::settings::Settings::default() }, - ..Settings::for_rule(Rule::MagicValueComparison) + ..LinterSettings::for_rule(Rule::MagicValueComparison) }, )?; assert_messages!(diagnostics); @@ -184,12 +185,12 @@ mod tests { fn max_args() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_arguments_params.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { max_args: 4, ..pylint::settings::Settings::default() }, - ..Settings::for_rule(Rule::TooManyArguments) + ..LinterSettings::for_rule(Rule::TooManyArguments) }, )?; assert_messages!(diagnostics); @@ -200,9 +201,9 @@ mod tests { fn max_args_with_dummy_variables() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_arguments_params.py"), - &Settings { + &LinterSettings { dummy_variable_rgx: Regex::new(r"skip_.*").unwrap(), - ..Settings::for_rule(Rule::TooManyArguments) + ..LinterSettings::for_rule(Rule::TooManyArguments) }, )?; assert_messages!(diagnostics); @@ -213,12 +214,12 @@ mod tests { fn max_branches() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_branches_params.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { max_branches: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rule(Rule::TooManyBranches) + ..LinterSettings::for_rule(Rule::TooManyBranches) }, )?; assert_messages!(diagnostics); @@ -229,12 +230,12 @@ mod tests { fn max_statements() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_statements_params.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { max_statements: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rule(Rule::TooManyStatements) + ..LinterSettings::for_rule(Rule::TooManyStatements) }, )?; assert_messages!(diagnostics); @@ -245,12 +246,12 @@ mod tests { fn max_return_statements() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_return_statements_params.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { max_returns: 1, ..pylint::settings::Settings::default() }, - ..Settings::for_rule(Rule::TooManyReturnStatements) + ..LinterSettings::for_rule(Rule::TooManyReturnStatements) }, )?; assert_messages!(diagnostics); @@ -261,12 +262,12 @@ mod tests { fn too_many_public_methods() -> Result<()> { let diagnostics = test_path( Path::new("pylint/too_many_public_methods.py"), - &Settings { + &LinterSettings { pylint: pylint::settings::Settings { max_public_methods: 7, ..pylint::settings::Settings::default() }, - ..Settings::for_rules(vec![Rule::TooManyPublicMethods]) + ..LinterSettings::for_rules(vec![Rule::TooManyPublicMethods]) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/pyupgrade/mod.rs b/crates/ruff_linter/src/rules/pyupgrade/mod.rs index 416972454fcc41..bff478382baaaa 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/mod.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/mod.rs @@ -87,7 +87,7 @@ mod tests { let snapshot = path.to_string_lossy().to_string(); let diagnostics = test_path( Path::new("pyupgrade").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -97,9 +97,9 @@ mod tests { fn non_pep695_type_alias_not_applied_py311() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/UP040.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py311, - ..settings::Settings::for_rule(Rule::NonPEP695TypeAlias) + ..settings::LinterSettings::for_rule(Rule::NonPEP695TypeAlias) }, )?; assert_messages!(diagnostics); @@ -110,12 +110,12 @@ mod tests { fn future_annotations_keep_runtime_typing_p37() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { pyupgrade: pyupgrade::settings::Settings { keep_runtime_typing: true, }, target_version: PythonVersion::Py37, - ..settings::Settings::for_rule(Rule::NonPEP585Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation) }, )?; assert_messages!(diagnostics); @@ -126,12 +126,12 @@ mod tests { fn future_annotations_keep_runtime_typing_p310() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { pyupgrade: pyupgrade::settings::Settings { keep_runtime_typing: true, }, target_version: PythonVersion::Py310, - ..settings::Settings::for_rule(Rule::NonPEP585Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation) }, )?; assert_messages!(diagnostics); @@ -142,9 +142,9 @@ mod tests { fn future_annotations_pep_585_p37() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py37, - ..settings::Settings::for_rule(Rule::NonPEP585Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation) }, )?; assert_messages!(diagnostics); @@ -155,9 +155,9 @@ mod tests { fn future_annotations_pep_585_py310() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py310, - ..settings::Settings::for_rule(Rule::NonPEP585Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP585Annotation) }, )?; assert_messages!(diagnostics); @@ -168,9 +168,9 @@ mod tests { fn future_annotations_pep_604_p37() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py37, - ..settings::Settings::for_rule(Rule::NonPEP604Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP604Annotation) }, )?; assert_messages!(diagnostics); @@ -181,9 +181,9 @@ mod tests { fn future_annotations_pep_604_py310() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/future_annotations.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py310, - ..settings::Settings::for_rule(Rule::NonPEP604Annotation) + ..settings::LinterSettings::for_rule(Rule::NonPEP604Annotation) }, )?; assert_messages!(diagnostics); @@ -194,9 +194,9 @@ mod tests { fn datetime_utc_alias_py311() -> Result<()> { let diagnostics = test_path( Path::new("pyupgrade/UP017.py"), - &settings::Settings { + &settings::LinterSettings { target_version: PythonVersion::Py311, - ..settings::Settings::for_rule(Rule::DatetimeTimezoneUTC) + ..settings::LinterSettings::for_rule(Rule::DatetimeTimezoneUTC) }, )?; assert_messages!(diagnostics); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs index 824b7634618b36..7e82eaf2b297db 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -7,7 +7,7 @@ use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Locator; use crate::registry::Rule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for extraneous parentheses. @@ -137,7 +137,7 @@ pub(crate) fn extraneous_parentheses( diagnostics: &mut Vec, tokens: &[LexResult], locator: &Locator, - settings: &Settings, + settings: &LinterSettings, ) { let mut i = 0; while i < tokens.len() { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs index f8c0ee8f637927..d80d72e599215b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -8,7 +8,7 @@ use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextRange}; use crate::registry::AsRule; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for unnecessary UTF-8 encoding declarations. @@ -52,7 +52,7 @@ pub(crate) fn unnecessary_coding_comment( diagnostics: &mut Vec, locator: &Locator, indexer: &Indexer, - settings: &Settings, + settings: &LinterSettings, ) { // The coding comment must be on one of the first two lines. Since each comment spans at least // one line, we only need to check the first two comments at most. diff --git a/crates/ruff_linter/src/rules/refurb/mod.rs b/crates/ruff_linter/src/rules/refurb/mod.rs index 73436726c31f98..189a5a6283270a 100644 --- a/crates/ruff_linter/src/rules/refurb/mod.rs +++ b/crates/ruff_linter/src/rules/refurb/mod.rs @@ -24,7 +24,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("refurb").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/rules/ruff/mod.rs b/crates/ruff_linter/src/rules/ruff/mod.rs index 79028c9b5b2357..722caa0bf72c5f 100644 --- a/crates/ruff_linter/src/rules/ruff/mod.rs +++ b/crates/ruff_linter/src/rules/ruff/mod.rs @@ -45,7 +45,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); let diagnostics = test_path( Path::new("ruff").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) @@ -61,7 +61,7 @@ mod tests { ); let diagnostics = test_path( Path::new("ruff").join(path).as_path(), - &settings::Settings::for_rule(Rule::ImplicitOptional) + &settings::LinterSettings::for_rule(Rule::ImplicitOptional) .with_target_version(PythonVersion::Py39), )?; assert_messages!(snapshot, diagnostics); @@ -72,9 +72,9 @@ mod tests { fn confusables() -> Result<()> { let diagnostics = test_path( Path::new("ruff/confusables.py"), - &settings::Settings { + &settings::LinterSettings { allowed_confusables: FxHashSet::from_iter(['−', 'ρ', '∗']), - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::AmbiguousUnicodeCharacterString, Rule::AmbiguousUnicodeCharacterDocstring, Rule::AmbiguousUnicodeCharacterComment, @@ -89,7 +89,10 @@ mod tests { fn noqa() -> Result<()> { let diagnostics = test_path( Path::new("ruff/noqa.py"), - &settings::Settings::for_rules(vec![Rule::UnusedVariable, Rule::AmbiguousVariableName]), + &settings::LinterSettings::for_rules(vec![ + Rule::UnusedVariable, + Rule::AmbiguousVariableName, + ]), )?; assert_messages!(diagnostics); Ok(()) @@ -99,9 +102,9 @@ mod tests { fn ruf100_0() -> Result<()> { let diagnostics = test_path( Path::new("ruff/RUF100_0.py"), - &settings::Settings { + &settings::LinterSettings { external: FxHashSet::from_iter(vec!["V101".to_string()]), - ..settings::Settings::for_rules(vec![ + ..settings::LinterSettings::for_rules(vec![ Rule::UnusedNOQA, Rule::LineTooLong, Rule::UnusedImport, @@ -118,7 +121,7 @@ mod tests { fn ruf100_1() -> Result<()> { let diagnostics = test_path( Path::new("ruff/RUF100_1.py"), - &settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]), )?; assert_messages!(diagnostics); Ok(()) @@ -127,7 +130,7 @@ mod tests { #[test] fn ruf100_2() -> Result<()> { let mut settings = - settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]); + settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]); settings.per_file_ignores = resolve_per_file_ignores(vec![PerFileIgnore::new( "RUF100_2.py".to_string(), @@ -145,7 +148,7 @@ mod tests { fn ruf100_3() -> Result<()> { let diagnostics = test_path( Path::new("ruff/RUF100_3.py"), - &settings::Settings::for_rules(vec![ + &settings::LinterSettings::for_rules(vec![ Rule::UnusedNOQA, Rule::LineTooLong, Rule::UndefinedName, @@ -159,7 +162,7 @@ mod tests { fn ruf100_4() -> Result<()> { let diagnostics = test_path( Path::new("ruff/RUF100_4.py"), - &settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]), )?; assert_messages!(diagnostics); Ok(()) @@ -169,8 +172,8 @@ mod tests { fn ruf100_5() -> Result<()> { let diagnostics = test_path( Path::new("ruff/RUF100_5.py"), - &settings::Settings { - ..settings::Settings::for_rules(vec![ + &settings::LinterSettings { + ..settings::LinterSettings::for_rules(vec![ Rule::UnusedNOQA, Rule::LineTooLong, Rule::CommentedOutCode, @@ -184,7 +187,7 @@ mod tests { fn flake8_noqa() -> Result<()> { let diagnostics = test_path( Path::new("ruff/flake8_noqa.py"), - &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; assert_messages!(diagnostics); Ok(()) @@ -194,7 +197,7 @@ mod tests { fn ruff_noqa_all() -> Result<()> { let diagnostics = test_path( Path::new("ruff/ruff_noqa_all.py"), - &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; assert_messages!(diagnostics); Ok(()) @@ -204,7 +207,7 @@ mod tests { fn ruff_noqa_codes() -> Result<()> { let diagnostics = test_path( Path::new("ruff/ruff_noqa_codes.py"), - &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; assert_messages!(diagnostics); Ok(()) @@ -214,7 +217,7 @@ mod tests { fn ruff_noqa_invalid() -> Result<()> { let diagnostics = test_path( Path::new("ruff/ruff_noqa_invalid.py"), - &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), + &settings::LinterSettings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; assert_messages!(diagnostics); Ok(()) @@ -224,7 +227,7 @@ mod tests { fn redirects() -> Result<()> { let diagnostics = test_path( Path::new("ruff/redirects.py"), - &settings::Settings::for_rules(vec![Rule::NonPEP604Annotation]), + &settings::LinterSettings::for_rules(vec![Rule::NonPEP604Annotation]), )?; assert_messages!(diagnostics); Ok(()) @@ -245,7 +248,7 @@ mod tests { let source_file = SourceFileBuilder::new("pyproject.toml", contents).finish(); let messages = lint_pyproject_toml( source_file, - &settings::Settings::for_rule(Rule::InvalidPyprojectToml), + &settings::LinterSettings::for_rule(Rule::InvalidPyprojectToml), ); assert_messages!(snapshot, messages); Ok(()) diff --git a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs index 50d600fe59d6b2..f105e3754dc7d5 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/ambiguous_unicode_character.rs @@ -10,7 +10,7 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; use crate::registry::AsRule; use crate::rules::ruff::rules::confusables::confusable; use crate::rules::ruff::rules::Context; -use crate::settings::Settings; +use crate::settings::LinterSettings; /// ## What it does /// Checks for ambiguous unicode characters in strings. @@ -128,7 +128,7 @@ pub(crate) fn ambiguous_unicode_character( locator: &Locator, range: TextRange, context: Context, - settings: &Settings, + settings: &LinterSettings, ) { let text = locator.slice(range); @@ -241,7 +241,7 @@ impl Candidate { } } - fn into_diagnostic(self, context: Context, settings: &Settings) -> Option { + fn into_diagnostic(self, context: Context, settings: &LinterSettings) -> Option { if !settings.allowed_confusables.contains(&self.confusable) { let char_range = TextRange::at(self.offset, self.confusable.text_len()); let diagnostic = Diagnostic::new::( diff --git a/crates/ruff_linter/src/rules/tryceratops/mod.rs b/crates/ruff_linter/src/rules/tryceratops/mod.rs index cd1075ba865776..c2418287caaf1d 100644 --- a/crates/ruff_linter/src/rules/tryceratops/mod.rs +++ b/crates/ruff_linter/src/rules/tryceratops/mod.rs @@ -28,7 +28,7 @@ mod tests { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("tryceratops").join(path).as_path(), - &settings::Settings::for_rule(rule_code), + &settings::LinterSettings::for_rule(rule_code), )?; assert_messages!(snapshot, diagnostics); Ok(()) diff --git a/crates/ruff_linter/src/settings/defaults.rs b/crates/ruff_linter/src/settings/defaults.rs index c4f5397434171b..8b137891791fe9 100644 --- a/crates/ruff_linter/src/settings/defaults.rs +++ b/crates/ruff_linter/src/settings/defaults.rs @@ -1,96 +1 @@ -use once_cell::sync::Lazy; -use path_absolutize::path_dedot; -use regex::Regex; -use ruff_cache::cache_dir; -use rustc_hash::FxHashSet; -use std::collections::HashSet; -use super::types::{PreviewMode, PythonVersion}; -use super::Settings; -use crate::codes::{self, RuleCodePrefix}; -use crate::line_width::{LineLength, TabSize}; -use crate::registry::Linter; -use crate::rule_selector::RuleSelector; -use crate::rules::{ - flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions, - flake8_copyright, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, - flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_self, - flake8_tidy_imports, flake8_type_checking, flake8_unused_arguments, isort, mccabe, pep8_naming, - pycodestyle, pydocstyle, pyflakes, pylint, pyupgrade, -}; -use crate::settings::types::SerializationFormat; -use crate::settings::FileResolverSettings; - -pub const PREFIXES: &[RuleSelector] = &[ - RuleSelector::Prefix { - prefix: RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E), - redirected_from: None, - }, - RuleSelector::Linter(Linter::Pyflakes), -]; - -pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"]; - -pub static DUMMY_VARIABLE_RGX: Lazy = - Lazy::new(|| Regex::new("^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$").unwrap()); - -impl Default for Settings { - fn default() -> Self { - let project_root = path_dedot::CWD.clone(); - Self { - cache_dir: cache_dir(&project_root), - fix: false, - fix_only: false, - output_format: SerializationFormat::default(), - show_fixes: false, - show_source: false, - - file_resolver: FileResolverSettings::with_project_root(project_root), - - rules: PREFIXES - .iter() - .flat_map(|selector| selector.rules(PreviewMode::default())) - .collect(), - allowed_confusables: FxHashSet::from_iter([]), - builtins: vec![], - dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone(), - external: HashSet::default(), - ignore_init_module_imports: false, - line_length: LineLength::default(), - logger_objects: vec![], - namespace_packages: vec![], - preview: PreviewMode::default(), - per_file_ignores: vec![], - - src: vec![path_dedot::CWD.clone()], - tab_size: TabSize::default(), - target_version: PythonVersion::default(), - task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(), - typing_modules: vec![], - flake8_annotations: flake8_annotations::settings::Settings::default(), - flake8_bandit: flake8_bandit::settings::Settings::default(), - flake8_bugbear: flake8_bugbear::settings::Settings::default(), - flake8_builtins: flake8_builtins::settings::Settings::default(), - flake8_comprehensions: flake8_comprehensions::settings::Settings::default(), - flake8_copyright: flake8_copyright::settings::Settings::default(), - flake8_errmsg: flake8_errmsg::settings::Settings::default(), - flake8_implicit_str_concat: flake8_implicit_str_concat::settings::Settings::default(), - flake8_import_conventions: flake8_import_conventions::settings::Settings::default(), - flake8_pytest_style: flake8_pytest_style::settings::Settings::default(), - flake8_quotes: flake8_quotes::settings::Settings::default(), - flake8_gettext: flake8_gettext::settings::Settings::default(), - flake8_self: flake8_self::settings::Settings::default(), - flake8_tidy_imports: flake8_tidy_imports::settings::Settings::default(), - flake8_type_checking: flake8_type_checking::settings::Settings::default(), - flake8_unused_arguments: flake8_unused_arguments::settings::Settings::default(), - isort: isort::settings::Settings::default(), - mccabe: mccabe::settings::Settings::default(), - pep8_naming: pep8_naming::settings::Settings::default(), - pycodestyle: pycodestyle::settings::Settings::default(), - pydocstyle: pydocstyle::settings::Settings::default(), - pyflakes: pyflakes::settings::Settings::default(), - pylint: pylint::settings::Settings::default(), - pyupgrade: pyupgrade::settings::Settings::default(), - } - } -} diff --git a/crates/ruff_linter/src/settings/mod.rs b/crates/ruff_linter/src/settings/mod.rs index ea6bd05afb1fac..ba35f4969bb089 100644 --- a/crates/ruff_linter/src/settings/mod.rs +++ b/crates/ruff_linter/src/settings/mod.rs @@ -2,17 +2,21 @@ //! command-line options. Structure is optimized for internal usage, as opposed //! to external visibility or parsing. -use std::path::PathBuf; +use std::collections::HashSet; +use std::path::{Path, PathBuf}; use anyhow::Result; use globset::{Glob, GlobMatcher}; use once_cell::sync::Lazy; +use path_absolutize::path_dedot; use regex::Regex; +use ruff_cache::cache_dir; use rustc_hash::FxHashSet; +use crate::codes::RuleCodePrefix; use ruff_macros::CacheKey; -use crate::registry::{Rule, RuleSet}; +use crate::registry::{Linter, Rule, RuleSet}; use crate::rules::{ flake8_annotations, flake8_bandit, flake8_bugbear, flake8_builtins, flake8_comprehensions, flake8_copyright, flake8_errmsg, flake8_gettext, flake8_implicit_str_concat, @@ -23,13 +27,13 @@ use crate::rules::{ use crate::settings::types::{ FilePattern, FilePatternSet, PerFileIgnore, PythonVersion, SerializationFormat, }; +use crate::{codes, RuleSelector}; use super::line_width::{LineLength, TabSize}; use self::rule_table::RuleTable; use self::types::PreviewMode; -pub mod defaults; pub mod flags; pub mod rule_table; pub mod types; @@ -84,9 +88,9 @@ pub struct FileResolverSettings { } impl FileResolverSettings { - fn with_project_root(project_root: PathBuf) -> Self { + fn with_project_root(project_root: &Path) -> Self { Self { - project_root, + project_root: project_root.to_path_buf(), exclude: FilePatternSet::try_from_vec(EXCLUDE.clone()).unwrap(), extend_exclude: FilePatternSet::default(), extend_include: FilePatternSet::default(), @@ -98,22 +102,8 @@ impl FileResolverSettings { } #[derive(Debug, CacheKey)] -#[allow(clippy::struct_excessive_bools)] -pub struct Settings { - #[cache_key(ignore)] - pub cache_dir: PathBuf, - #[cache_key(ignore)] - pub fix: bool, - #[cache_key(ignore)] - pub fix_only: bool, - #[cache_key(ignore)] - pub output_format: SerializationFormat, - #[cache_key(ignore)] - pub show_fixes: bool, - #[cache_key(ignore)] - pub show_source: bool, - - pub file_resolver: FileResolverSettings, +pub struct LinterSettings { + pub project_root: PathBuf, pub rules: RuleTable, pub per_file_ignores: Vec<(GlobMatcher, GlobMatcher, RuleSet)>, @@ -161,7 +151,20 @@ pub struct Settings { pub pyupgrade: pyupgrade::settings::Settings, } -impl Settings { +pub const PREFIXES: &[RuleSelector] = &[ + RuleSelector::Prefix { + prefix: RuleCodePrefix::Pycodestyle(codes::Pycodestyle::E), + redirected_from: None, + }, + RuleSelector::Linter(Linter::Pyflakes), +]; + +pub const TASK_TAGS: &[&str] = &["TODO", "FIXME", "XXX"]; + +pub static DUMMY_VARIABLE_RGX: Lazy = + Lazy::new(|| Regex::new("^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$").unwrap()); + +impl LinterSettings { pub fn for_rule(rule_code: Rule) -> Self { Self { rules: RuleTable::from_iter([rule_code]), @@ -178,7 +181,62 @@ impl Settings { } } - /// Return the [`Settings`] after updating the target [`PythonVersion`]. + pub fn with_project_root(project_root: &Path) -> Self { + Self { + target_version: PythonVersion::default(), + project_root: project_root.to_path_buf(), + rules: PREFIXES + .iter() + .flat_map(|selector| selector.rules(PreviewMode::default())) + .collect(), + allowed_confusables: FxHashSet::from_iter([]), + + // Needs duplicating + builtins: vec![], + dummy_variable_rgx: DUMMY_VARIABLE_RGX.clone(), + + external: HashSet::default(), + ignore_init_module_imports: false, + line_length: LineLength::default(), + logger_objects: vec![], + namespace_packages: vec![], + + per_file_ignores: vec![], + + src: vec![path_dedot::CWD.clone()], + // Needs duplicating + tab_size: TabSize::default(), + + task_tags: TASK_TAGS.iter().map(ToString::to_string).collect(), + typing_modules: vec![], + flake8_annotations: flake8_annotations::settings::Settings::default(), + flake8_bandit: flake8_bandit::settings::Settings::default(), + flake8_bugbear: flake8_bugbear::settings::Settings::default(), + flake8_builtins: flake8_builtins::settings::Settings::default(), + flake8_comprehensions: flake8_comprehensions::settings::Settings::default(), + flake8_copyright: flake8_copyright::settings::Settings::default(), + flake8_errmsg: flake8_errmsg::settings::Settings::default(), + flake8_implicit_str_concat: flake8_implicit_str_concat::settings::Settings::default(), + flake8_import_conventions: flake8_import_conventions::settings::Settings::default(), + flake8_pytest_style: flake8_pytest_style::settings::Settings::default(), + flake8_quotes: flake8_quotes::settings::Settings::default(), + flake8_gettext: flake8_gettext::settings::Settings::default(), + flake8_self: flake8_self::settings::Settings::default(), + flake8_tidy_imports: flake8_tidy_imports::settings::Settings::default(), + flake8_type_checking: flake8_type_checking::settings::Settings::default(), + flake8_unused_arguments: flake8_unused_arguments::settings::Settings::default(), + isort: isort::settings::Settings::default(), + mccabe: mccabe::settings::Settings::default(), + pep8_naming: pep8_naming::settings::Settings::default(), + pycodestyle: pycodestyle::settings::Settings::default(), + pydocstyle: pydocstyle::settings::Settings::default(), + pyflakes: pyflakes::settings::Settings::default(), + pylint: pylint::settings::Settings::default(), + pyupgrade: pyupgrade::settings::Settings::default(), + preview: PreviewMode::default(), + } + } + #[must_use] pub fn with_target_version(mut self, target_version: PythonVersion) -> Self { self.target_version = target_version; @@ -186,6 +244,32 @@ impl Settings { } } +impl Default for LinterSettings { + fn default() -> Self { + Self::with_project_root(path_dedot::CWD.as_path()) + } +} + +#[derive(Debug, CacheKey)] +#[allow(clippy::struct_excessive_bools)] +pub struct Settings { + #[cache_key(ignore)] + pub cache_dir: PathBuf, + #[cache_key(ignore)] + pub fix: bool, + #[cache_key(ignore)] + pub fix_only: bool, + #[cache_key(ignore)] + pub output_format: SerializationFormat, + #[cache_key(ignore)] + pub show_fixes: bool, + #[cache_key(ignore)] + pub show_source: bool, + + pub file_resolver: FileResolverSettings, + pub linter: LinterSettings, +} + /// Given a list of patterns, create a `GlobSet`. pub fn resolve_per_file_ignores( per_file_ignores: Vec, @@ -204,3 +288,19 @@ pub fn resolve_per_file_ignores( }) .collect() } + +impl Default for Settings { + fn default() -> Self { + let project_root = path_dedot::CWD.as_path(); + Self { + cache_dir: cache_dir(project_root), + fix: false, + fix_only: false, + output_format: SerializationFormat::default(), + show_fixes: false, + show_source: false, + linter: LinterSettings::with_project_root(project_root), + file_resolver: FileResolverSettings::with_project_root(project_root), + } + } +} diff --git a/crates/ruff_linter/src/test.rs b/crates/ruff_linter/src/test.rs index 9edcc0e8e4e425..2924814c085429 100644 --- a/crates/ruff_linter/src/test.rs +++ b/crates/ruff_linter/src/test.rs @@ -26,9 +26,11 @@ use crate::message::{Emitter, EmitterContext, Message, TextEmitter}; use crate::packaging::detect_package_root; use crate::registry::AsRule; use crate::rules::pycodestyle::rules::syntax_error; -use crate::settings::{flags, Settings}; +use crate::settings::{flags, LinterSettings}; use crate::source_kind::SourceKind; -use ruff_notebook::{Notebook, NotebookError}; +use ruff_notebook::Notebook; +#[cfg(not(fuzzing))] +use ruff_notebook::NotebookError; #[cfg(not(fuzzing))] pub(crate) fn test_resource_path(path: impl AsRef) -> std::path::PathBuf { @@ -37,7 +39,7 @@ pub(crate) fn test_resource_path(path: impl AsRef) -> std::path::PathBuf { /// Run [`check_path`] on a file in the `resources/test/fixtures` directory. #[cfg(not(fuzzing))] -pub(crate) fn test_path(path: impl AsRef, settings: &Settings) -> Result> { +pub(crate) fn test_path(path: impl AsRef, settings: &LinterSettings) -> Result> { let path = test_resource_path("fixtures").join(path); let contents = std::fs::read_to_string(&path)?; Ok(test_contents(&SourceKind::Python(contents), &path, settings).0) @@ -54,7 +56,7 @@ pub(crate) struct TestedNotebook { pub(crate) fn test_notebook_path( path: impl AsRef, expected: impl AsRef, - settings: &Settings, + settings: &LinterSettings, ) -> Result { let source_notebook = Notebook::from_path(path.as_ref())?; @@ -81,7 +83,7 @@ pub(crate) fn test_notebook_path( } /// Run [`check_path`] on a snippet of Python code. -pub fn test_snippet(contents: &str, settings: &Settings) -> Vec { +pub fn test_snippet(contents: &str, settings: &LinterSettings) -> Vec { let path = Path::new(""); let contents = dedent(contents); test_contents(&SourceKind::Python(contents.into_owned()), path, settings).0 @@ -104,7 +106,7 @@ pub(crate) fn max_iterations() -> usize { pub(crate) fn test_contents<'a>( source_kind: &'a SourceKind, path: &Path, - settings: &Settings, + settings: &LinterSettings, ) -> (Vec, Cow<'a, SourceKind>) { let source_type = PySourceType::from(path); let tokens: Vec = diff --git a/crates/ruff_wasm/src/lib.rs b/crates/ruff_wasm/src/lib.rs index daf9eef1297386..ea9b5dff70d72b 100644 --- a/crates/ruff_wasm/src/lib.rs +++ b/crates/ruff_wasm/src/lib.rs @@ -11,7 +11,7 @@ use ruff_linter::line_width::{LineLength, TabSize}; use ruff_linter::linter::{check_path, LinterResult}; use ruff_linter::registry::AsRule; use ruff_linter::settings::types::{PreviewMode, PythonVersion}; -use ruff_linter::settings::{defaults, flags, Settings}; +use ruff_linter::settings::{flags, Settings, DUMMY_VARIABLE_RGX, PREFIXES}; use ruff_linter::source_kind::SourceKind; use ruff_python_ast::{Mod, PySourceType}; use ruff_python_codegen::Stylist; @@ -122,7 +122,7 @@ impl Workspace { // Propagate defaults. allowed_confusables: Some(Vec::default()), builtins: Some(Vec::default()), - dummy_variable_rgx: Some(defaults::DUMMY_VARIABLE_RGX.as_str().to_string()), + dummy_variable_rgx: Some(DUMMY_VARIABLE_RGX.as_str().to_string()), extend_fixable: Some(Vec::default()), extend_ignore: Some(Vec::default()), extend_select: Some(Vec::default()), @@ -131,7 +131,7 @@ impl Workspace { ignore: Some(Vec::default()), line_length: Some(LineLength::default()), preview: Some(false), - select: Some(defaults::PREFIXES.to_vec()), + select: Some(PREFIXES.to_vec()), tab_size: Some(TabSize::default()), target_version: Some(PythonVersion::default()), // Ignore a bunch of options that don't make sense in a single-file editor. @@ -198,7 +198,7 @@ impl Workspace { &stylist, &indexer, &directives, - &self.settings, + &self.settings.linter, flags::Noqa::Enabled, &source_kind, source_type, @@ -301,12 +301,15 @@ impl<'a> ParsedModule<'a> { fn format(&self, settings: &Settings) -> FormatResult> { // TODO(konstin): Add an options for py/pyi to the UI (2/2) + // TODO(micha): Use formatter settings instead let options = PyFormatOptions::from_source_type(PySourceType::default()) - .with_preview(match settings.preview { + .with_preview(match settings.linter.preview { PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, }) - .with_line_width(LineWidth::from(NonZeroU16::from(settings.line_length))); + .with_line_width(LineWidth::from(NonZeroU16::from( + settings.linter.line_length, + ))); format_node( &self.module, diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 40b6a6b7b10c00..dd13b9cdcde19c 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -28,7 +28,8 @@ use ruff_linter::settings::types::{ Version, }; use ruff_linter::settings::{ - defaults, resolve_per_file_ignores, FileResolverSettings, Settings, EXCLUDE, INCLUDE, + resolve_per_file_ignores, FileResolverSettings, LinterSettings, Settings, DUMMY_VARIABLE_RGX, + EXCLUDE, INCLUDE, PREFIXES, TASK_TAGS, }; use ruff_linter::{ fs, warn_user, warn_user_once, warn_user_once_by_id, RuleSelector, RUFF_PKG_VERSION, @@ -121,6 +122,9 @@ impl Configuration { } } + let target_version = self.target_version.unwrap_or_default(); + let rules = self.as_rule_table(); + Ok(Settings { cache_dir: self .cache_dir @@ -132,15 +136,6 @@ impl Configuration { show_fixes: self.show_fixes.unwrap_or(false), show_source: self.show_source.unwrap_or(false), - rules: self.as_rule_table(), - allowed_confusables: self - .allowed_confusables - .map(FxHashSet::from_iter) - .unwrap_or_default(), - builtins: self.builtins.unwrap_or_default(), - dummy_variable_rgx: self - .dummy_variable_rgx - .unwrap_or_else(|| defaults::DUMMY_VARIABLE_RGX.clone()), file_resolver: FileResolverSettings { exclude: FilePatternSet::try_from_vec( self.exclude.unwrap_or_else(|| EXCLUDE.clone()), @@ -154,130 +149,140 @@ impl Configuration { respect_gitignore: self.respect_gitignore.unwrap_or(true), project_root: project_root.to_path_buf(), }, - external: FxHashSet::from_iter(self.external.unwrap_or_default()), - ignore_init_module_imports: self.ignore_init_module_imports.unwrap_or_default(), - line_length: self.line_length.unwrap_or_default(), - tab_size: self.tab_size.unwrap_or_default(), - namespace_packages: self.namespace_packages.unwrap_or_default(), - per_file_ignores: resolve_per_file_ignores( - self.per_file_ignores - .unwrap_or_default() - .into_iter() - .chain(self.extend_per_file_ignores) - .collect(), - )?, - src: self.src.unwrap_or_else(|| vec![project_root.to_path_buf()]), - target_version: self.target_version.unwrap_or_default(), - task_tags: self.task_tags.unwrap_or_else(|| { - defaults::TASK_TAGS - .iter() - .map(ToString::to_string) - .collect() - }), - logger_objects: self.logger_objects.unwrap_or_default(), - preview: self.preview.unwrap_or_default(), - typing_modules: self.typing_modules.unwrap_or_default(), - // Plugins - flake8_annotations: self - .flake8_annotations - .map(Flake8AnnotationsOptions::into_settings) - .unwrap_or_default(), - flake8_bandit: self - .flake8_bandit - .map(Flake8BanditOptions::into_settings) - .unwrap_or_default(), - flake8_bugbear: self - .flake8_bugbear - .map(Flake8BugbearOptions::into_settings) - .unwrap_or_default(), - flake8_builtins: self - .flake8_builtins - .map(Flake8BuiltinsOptions::into_settings) - .unwrap_or_default(), - flake8_comprehensions: self - .flake8_comprehensions - .map(Flake8ComprehensionsOptions::into_settings) - .unwrap_or_default(), - flake8_copyright: self - .flake8_copyright - .map(Flake8CopyrightOptions::try_into_settings) - .transpose()? - .unwrap_or_default(), - flake8_errmsg: self - .flake8_errmsg - .map(Flake8ErrMsgOptions::into_settings) - .unwrap_or_default(), - flake8_implicit_str_concat: self - .flake8_implicit_str_concat - .map(Flake8ImplicitStrConcatOptions::into_settings) - .unwrap_or_default(), - flake8_import_conventions: self - .flake8_import_conventions - .map(Flake8ImportConventionsOptions::into_settings) - .unwrap_or_default(), - flake8_pytest_style: self - .flake8_pytest_style - .map(Flake8PytestStyleOptions::try_into_settings) - .transpose()? - .unwrap_or_default(), - flake8_quotes: self - .flake8_quotes - .map(Flake8QuotesOptions::into_settings) - .unwrap_or_default(), - flake8_self: self - .flake8_self - .map(Flake8SelfOptions::into_settings) - .unwrap_or_default(), - flake8_tidy_imports: self - .flake8_tidy_imports - .map(Flake8TidyImportsOptions::into_settings) - .unwrap_or_default(), - flake8_type_checking: self - .flake8_type_checking - .map(Flake8TypeCheckingOptions::into_settings) - .unwrap_or_default(), - flake8_unused_arguments: self - .flake8_unused_arguments - .map(Flake8UnusedArgumentsOptions::into_settings) - .unwrap_or_default(), - flake8_gettext: self - .flake8_gettext - .map(Flake8GetTextOptions::into_settings) - .unwrap_or_default(), - isort: self - .isort - .map(IsortOptions::try_into_settings) - .transpose()? - .unwrap_or_default(), - mccabe: self - .mccabe - .map(McCabeOptions::into_settings) - .unwrap_or_default(), - pep8_naming: self - .pep8_naming - .map(Pep8NamingOptions::try_into_settings) - .transpose()? - .unwrap_or_default(), - pycodestyle: self - .pycodestyle - .map(PycodestyleOptions::into_settings) - .unwrap_or_default(), - pydocstyle: self - .pydocstyle - .map(PydocstyleOptions::into_settings) - .unwrap_or_default(), - pyflakes: self - .pyflakes - .map(PyflakesOptions::into_settings) - .unwrap_or_default(), - pylint: self - .pylint - .map(PylintOptions::into_settings) - .unwrap_or_default(), - pyupgrade: self - .pyupgrade - .map(PyUpgradeOptions::into_settings) - .unwrap_or_default(), + linter: LinterSettings { + target_version, + project_root: project_root.to_path_buf(), + rules, + allowed_confusables: self + .allowed_confusables + .map(FxHashSet::from_iter) + .unwrap_or_default(), + builtins: self.builtins.unwrap_or_default(), + dummy_variable_rgx: self + .dummy_variable_rgx + .unwrap_or_else(|| DUMMY_VARIABLE_RGX.clone()), + external: FxHashSet::from_iter(self.external.unwrap_or_default()), + ignore_init_module_imports: self.ignore_init_module_imports.unwrap_or_default(), + line_length: self.line_length.unwrap_or_default(), + tab_size: self.tab_size.unwrap_or_default(), + namespace_packages: self.namespace_packages.unwrap_or_default(), + per_file_ignores: resolve_per_file_ignores( + self.per_file_ignores + .unwrap_or_default() + .into_iter() + .chain(self.extend_per_file_ignores) + .collect(), + )?, + src: self.src.unwrap_or_else(|| vec![project_root.to_path_buf()]), + + task_tags: self + .task_tags + .unwrap_or_else(|| TASK_TAGS.iter().map(ToString::to_string).collect()), + logger_objects: self.logger_objects.unwrap_or_default(), + preview: self.preview.unwrap_or_default(), + typing_modules: self.typing_modules.unwrap_or_default(), + // Plugins + flake8_annotations: self + .flake8_annotations + .map(Flake8AnnotationsOptions::into_settings) + .unwrap_or_default(), + flake8_bandit: self + .flake8_bandit + .map(Flake8BanditOptions::into_settings) + .unwrap_or_default(), + flake8_bugbear: self + .flake8_bugbear + .map(Flake8BugbearOptions::into_settings) + .unwrap_or_default(), + flake8_builtins: self + .flake8_builtins + .map(Flake8BuiltinsOptions::into_settings) + .unwrap_or_default(), + flake8_comprehensions: self + .flake8_comprehensions + .map(Flake8ComprehensionsOptions::into_settings) + .unwrap_or_default(), + flake8_copyright: self + .flake8_copyright + .map(Flake8CopyrightOptions::try_into_settings) + .transpose()? + .unwrap_or_default(), + flake8_errmsg: self + .flake8_errmsg + .map(Flake8ErrMsgOptions::into_settings) + .unwrap_or_default(), + flake8_implicit_str_concat: self + .flake8_implicit_str_concat + .map(Flake8ImplicitStrConcatOptions::into_settings) + .unwrap_or_default(), + flake8_import_conventions: self + .flake8_import_conventions + .map(Flake8ImportConventionsOptions::into_settings) + .unwrap_or_default(), + flake8_pytest_style: self + .flake8_pytest_style + .map(Flake8PytestStyleOptions::try_into_settings) + .transpose()? + .unwrap_or_default(), + flake8_quotes: self + .flake8_quotes + .map(Flake8QuotesOptions::into_settings) + .unwrap_or_default(), + flake8_self: self + .flake8_self + .map(Flake8SelfOptions::into_settings) + .unwrap_or_default(), + flake8_tidy_imports: self + .flake8_tidy_imports + .map(Flake8TidyImportsOptions::into_settings) + .unwrap_or_default(), + flake8_type_checking: self + .flake8_type_checking + .map(Flake8TypeCheckingOptions::into_settings) + .unwrap_or_default(), + flake8_unused_arguments: self + .flake8_unused_arguments + .map(Flake8UnusedArgumentsOptions::into_settings) + .unwrap_or_default(), + flake8_gettext: self + .flake8_gettext + .map(Flake8GetTextOptions::into_settings) + .unwrap_or_default(), + isort: self + .isort + .map(IsortOptions::try_into_settings) + .transpose()? + .unwrap_or_default(), + mccabe: self + .mccabe + .map(McCabeOptions::into_settings) + .unwrap_or_default(), + pep8_naming: self + .pep8_naming + .map(Pep8NamingOptions::try_into_settings) + .transpose()? + .unwrap_or_default(), + pycodestyle: self + .pycodestyle + .map(PycodestyleOptions::into_settings) + .unwrap_or_default(), + pydocstyle: self + .pydocstyle + .map(PydocstyleOptions::into_settings) + .unwrap_or_default(), + pyflakes: self + .pyflakes + .map(PyflakesOptions::into_settings) + .unwrap_or_default(), + pylint: self + .pylint + .map(PylintOptions::into_settings) + .unwrap_or_default(), + pyupgrade: self + .pyupgrade + .map(PyUpgradeOptions::into_settings) + .unwrap_or_default(), + }, }) } @@ -442,7 +447,7 @@ impl Configuration { let preview = self.preview.unwrap_or_default(); // The select_set keeps track of which rules have been selected. - let mut select_set: RuleSet = defaults::PREFIXES + let mut select_set: RuleSet = PREFIXES .iter() .flat_map(|selector| selector.rules(preview)) .collect(); diff --git a/crates/ruff_workspace/src/resolver.rs b/crates/ruff_workspace/src/resolver.rs index 4f4c97d1fa8e4c..dbe564167fd945 100644 --- a/crates/ruff_workspace/src/resolver.rs +++ b/crates/ruff_workspace/src/resolver.rs @@ -139,7 +139,10 @@ impl Resolver { // Search for the package root for each file. let mut package_roots: FxHashMap<&Path, Option<&Path>> = FxHashMap::default(); for file in files { - let namespace_packages = &self.resolve(file, pyproject_config).namespace_packages; + let namespace_packages = &self + .resolve(file, pyproject_config) + .linter + .namespace_packages; if let Some(package) = file.parent() { if package_roots.contains_key(package) { continue; diff --git a/fuzz/fuzz_targets/ruff_fix_validity.rs b/fuzz/fuzz_targets/ruff_fix_validity.rs index 8bebda3c93e628..c7df3f24e2a723 100644 --- a/fuzz/fuzz_targets/ruff_fix_validity.rs +++ b/fuzz/fuzz_targets/ruff_fix_validity.rs @@ -4,10 +4,10 @@ #![no_main] use libfuzzer_sys::{fuzz_target, Corpus}; -use ruff_linter::settings::Settings; +use ruff_linter::settings::LinterSettings; use std::sync::OnceLock; -static SETTINGS: OnceLock = OnceLock::new(); +static SETTINGS: OnceLock = OnceLock::new(); fn do_fuzz(case: &[u8]) -> Corpus { // throw away inputs which aren't utf-8 @@ -16,7 +16,7 @@ fn do_fuzz(case: &[u8]) -> Corpus { }; // the settings are immutable to test_snippet, so we avoid re-initialising here - let settings = SETTINGS.get_or_init(Settings::default); + let settings = SETTINGS.get_or_init(LinterSettings::default); ruff_linter::test::set_max_iterations(usize::MAX); // unlike in the test framework, where the number of iterations is well-defined, we are only