Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ if __name__ == '__main__':
say_hy("dear Ruff contributor")

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'
- 'ignore' -> 'lint.ignore'


"###);
Ok(())
}
Expand Down Expand Up @@ -546,6 +551,11 @@ if __name__ == '__main__':
say_hy("dear Ruff contributor")

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'
- 'ignore' -> 'lint.ignore'


"###);
Ok(())
}
Expand Down
34 changes: 34 additions & 0 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ inline-quotes = "single"
[*] 2 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'
- 'flake8-quotes' -> 'lint.flake8-quotes'


"###);
Ok(())
}
Expand Down Expand Up @@ -114,6 +119,10 @@ inline-quotes = "single"
[*] 2 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'


"###);
Ok(())
}
Expand Down Expand Up @@ -153,6 +162,10 @@ inline-quotes = "single"
[*] 2 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'flake8-quotes' -> 'lint.flake8-quotes'


"###);
Ok(())
}
Expand Down Expand Up @@ -228,6 +241,10 @@ OTHER = "OTHER"
[*] 3 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'


"###);
Ok(())
}
Expand Down Expand Up @@ -271,6 +288,10 @@ if __name__ == "__main__":
[*] 2 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'


"###);
Ok(())
}
Expand Down Expand Up @@ -309,6 +330,11 @@ _ = "---------------------------------------------------------------------------
Found 1 error.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'select' -> 'lint.select'
- 'pycodestyle' -> 'lint.pycodestyle'


"###);
Ok(())
}
Expand Down Expand Up @@ -351,6 +377,10 @@ if __name__ == "__main__":
[*] 1 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'


"###);
Ok(())
}
Expand Down Expand Up @@ -393,6 +423,10 @@ if __name__ == "__main__":
[*] 1 fixable with the `--fix` option.

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'extend-select' -> 'lint.extend-select'


"###);
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions crates/ruff/tests/resolve_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ fn check_project_include_defaults() {
[BASEPATH]/include-test/subdirectory/c.py

----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:
- 'select' -> 'lint.select'


"###);
});
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_macros/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result<TokenStream> {
for token in list.tokens.clone() {
if let TokenTree::Ident(ident) = token {
if ident == "flatten" {
let ty_name = ty.path.require_ident()?;
output.push(quote_spanned!(
ident.span() => (#ty_name::record(visit))
ty.span() => (<#ty>::record(visit))
));

break;
}
}
Expand Down
208 changes: 203 additions & 5 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};

use anyhow::{anyhow, Result};
use glob::{glob, GlobError, Paths, PatternError};
use itertools::Itertools;
use regex::Regex;
use ruff_linter::settings::fix_safety_table::FixSafetyTable;
use rustc_hash::{FxHashMap, FxHashSet};
Expand Down Expand Up @@ -41,9 +42,9 @@ use crate::options::{
Flake8ComprehensionsOptions, Flake8CopyrightOptions, Flake8ErrMsgOptions, Flake8GetTextOptions,
Flake8ImplicitStrConcatOptions, Flake8ImportConventionsOptions, Flake8PytestStyleOptions,
Flake8QuotesOptions, Flake8SelfOptions, Flake8TidyImportsOptions, Flake8TypeCheckingOptions,
Flake8UnusedArgumentsOptions, FormatOptions, IsortOptions, LintOptions, McCabeOptions, Options,
Pep8NamingOptions, PyUpgradeOptions, PycodestyleOptions, PydocstyleOptions, PyflakesOptions,
PylintOptions,
Flake8UnusedArgumentsOptions, FormatOptions, IsortOptions, LintCommonOptions, LintOptions,
McCabeOptions, Options, Pep8NamingOptions, PyUpgradeOptions, PycodestyleOptions,
PydocstyleOptions, PyflakesOptions, PylintOptions,
};
use crate::settings::{
FileResolverSettings, FormatterSettings, LineEnding, Settings, EXCLUDE, INCLUDE,
Expand Down Expand Up @@ -395,12 +396,14 @@ impl Configuration {
}

pub fn from_options(options: Options, project_root: &Path) -> Result<Self> {
warn_about_deprecated_top_level_lint_options(&options.lint_top_level.0);

let lint = if let Some(mut lint) = options.lint {
lint.common = lint.common.combine(options.lint_top_level.common);
lint.common = lint.common.combine(options.lint_top_level.0);
lint
} else {
LintOptions {
common: options.lint_top_level.common,
common: options.lint_top_level.0,
..LintOptions::default()
}
};
Expand Down Expand Up @@ -1132,6 +1135,201 @@ pub fn resolve_src(src: &[String], project_root: &Path) -> Result<Vec<PathBuf>>
Ok(paths)
}

fn warn_about_deprecated_top_level_lint_options(top_level_options: &LintCommonOptions) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit silly, but writing a macro for it didn't feel worth the time because we shouldn't be adding any new options to LintCommonOptions anyway.

let mut used_options = Vec::new();

if top_level_options.allowed_confusables.is_some() {
used_options.push("allowed-confusables");
}

if top_level_options.dummy_variable_rgx.is_some() {
used_options.push("dummy-variable-rgx");
}

#[allow(deprecated)]
if top_level_options.extend_ignore.is_some() {
used_options.push("extend-ignore");
}

if top_level_options.extend_select.is_some() {
used_options.push("extend-select");
}

if top_level_options.extend_fixable.is_some() {
used_options.push("extend-fixable");
}

#[allow(deprecated)]
if top_level_options.extend_unfixable.is_some() {
used_options.push("extend-unfixable");
}

if top_level_options.external.is_some() {
used_options.push("external");
}

if top_level_options.fixable.is_some() {
used_options.push("fixable");
}

if top_level_options.ignore.is_some() {
used_options.push("ignore");
}

if top_level_options.extend_safe_fixes.is_some() {
used_options.push("extend-safe-fixes");
}

if top_level_options.extend_unsafe_fixes.is_some() {
used_options.push("extend-unsafe-fixes");
}

if top_level_options.ignore_init_module_imports.is_some() {
used_options.push("ignore-init-module-imports");
}

if top_level_options.logger_objects.is_some() {
used_options.push("logger-objects");
}

if top_level_options.select.is_some() {
used_options.push("select");
}

if top_level_options.explicit_preview_rules.is_some() {
used_options.push("explicit-preview-rules");
}

if top_level_options.task_tags.is_some() {
used_options.push("task-tags");
}

if top_level_options.typing_modules.is_some() {
used_options.push("typing-modules");
}

if top_level_options.unfixable.is_some() {
used_options.push("unfixable");
}

if top_level_options.flake8_annotations.is_some() {
used_options.push("flake8-annotations");
}

if top_level_options.flake8_bandit.is_some() {
used_options.push("flake8-bandit");
}

if top_level_options.flake8_bugbear.is_some() {
used_options.push("flake8-bugbear");
}

if top_level_options.flake8_builtins.is_some() {
used_options.push("flake8-builtins");
}

if top_level_options.flake8_comprehensions.is_some() {
used_options.push("flake8-comprehensions");
}

if top_level_options.flake8_copyright.is_some() {
used_options.push("flake8-copyright");
}

if top_level_options.flake8_errmsg.is_some() {
used_options.push("flake8-errmsg");
}

if top_level_options.flake8_quotes.is_some() {
used_options.push("flake8-quotes");
}

if top_level_options.flake8_self.is_some() {
used_options.push("flake8-self");
}

if top_level_options.flake8_tidy_imports.is_some() {
used_options.push("flake8-tidy-imports");
}

if top_level_options.flake8_type_checking.is_some() {
used_options.push("flake8-type-checking");
}

if top_level_options.flake8_gettext.is_some() {
used_options.push("flake8-gettext");
}

if top_level_options.flake8_implicit_str_concat.is_some() {
used_options.push("flake8-implicit-str-concat");
}

if top_level_options.flake8_import_conventions.is_some() {
used_options.push("flake8-import-conventions");
}

if top_level_options.flake8_pytest_style.is_some() {
used_options.push("flake8-pytest-style");
}

if top_level_options.flake8_unused_arguments.is_some() {
used_options.push("flake8-unused-arguments");
}

if top_level_options.isort.is_some() {
used_options.push("isort");
}

if top_level_options.mccabe.is_some() {
used_options.push("mccabe");
}

if top_level_options.pep8_naming.is_some() {
used_options.push("pep8-naming");
}

if top_level_options.pycodestyle.is_some() {
used_options.push("pycodestyle");
}

if top_level_options.pydocstyle.is_some() {
used_options.push("pydocstyle");
}

if top_level_options.pyflakes.is_some() {
used_options.push("pyflakes");
}

if top_level_options.pylint.is_some() {
used_options.push("pylint");
}

if top_level_options.pyupgrade.is_some() {
used_options.push("pyupgrade");
}

if top_level_options.per_file_ignores.is_some() {
used_options.push("per-file-ignores");
}

if top_level_options.extend_per_file_ignores.is_some() {
used_options.push("extend-per-file-ignores");
}

if used_options.is_empty() {
return;
}

let options_mapping = used_options
.iter()
.map(|option| format!("- '{option}' -> 'lint.{option}'"))
.join("\n ");

warn_user!(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit unfortunate that we don't know the configuration file name (relative to the project directory)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to get it... Want me to try?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to do it. It can be done as a separate PR because I'm fairly certain we already emit other warnings without mentioning the configuration file name.

"The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your configuration:\n {options_mapping}\n\n",
);
}

#[cfg(test)]
mod tests {
use crate::configuration::{LintConfiguration, RuleSelection};
Expand Down
4 changes: 1 addition & 3 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ pub struct LintOptions {
/// Newtype wrapper for [`LintCommonOptions`] that allows customizing the JSON schema and omitting the fields from the [`OptionsMetadata`].
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(transparent)]
pub struct DeprecatedTopLevelLintOptions {
pub common: LintCommonOptions,
}
pub struct DeprecatedTopLevelLintOptions(pub LintCommonOptions);

impl OptionsMetadata for DeprecatedTopLevelLintOptions {
fn record(_visit: &mut dyn Visit) {
Expand Down
Loading