mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Add lint
section to Ruff configuration
## Summary
This PR adds a new `lint` section to the configuration that groups all linter-specific settings. The existing top-level configurations continue to work without any warning because the `lint.*` settings are experimental.
The configuration merges the top level and `lint.*` settings where the settings in `lint` have higher precedence (override the top-level settings). The reasoning behind this is that the settings in `lint.` are more specific and more specific settings should override less specific settings.
I decided against showing the new `lint.*` options on our website because it would make the page extremely long (it's technically easy to do, just attribute `lint` with `[option_group`]). We may want to explore adding an `alias` field to the `option` attribute and show the alias on the website along with its regular name.
## Test Plan
* I added new integration tests
* I verified that the generated `options.md` is identical
* Verified the default settings in the playground

This commit is contained in:
parent
15f3d8c8e0
commit
0c65d0c8a6
11 changed files with 1301 additions and 611 deletions
|
@ -161,7 +161,7 @@ mod tests {
|
|||
use ruff_linter::line_width::LineLength;
|
||||
use ruff_linter::settings::types::PatternPrefixPair;
|
||||
|
||||
use crate::options::Options;
|
||||
use crate::options::{LintOptions, Options};
|
||||
use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools};
|
||||
use crate::tests::test_resource_path;
|
||||
|
||||
|
@ -236,7 +236,10 @@ select = ["E501"]
|
|||
pyproject.tool,
|
||||
Some(Tools {
|
||||
ruff: Some(Options {
|
||||
select: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
lint_top_level: LintOptions {
|
||||
select: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
..LintOptions::default()
|
||||
},
|
||||
..Options::default()
|
||||
})
|
||||
})
|
||||
|
@ -254,8 +257,11 @@ ignore = ["E501"]
|
|||
pyproject.tool,
|
||||
Some(Tools {
|
||||
ruff: Some(Options {
|
||||
extend_select: Some(vec![codes::Ruff::_100.into()]),
|
||||
ignore: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
lint_top_level: LintOptions {
|
||||
extend_select: Some(vec![codes::Ruff::_100.into()]),
|
||||
ignore: Some(vec![codes::Pycodestyle::E501.into()]),
|
||||
..LintOptions::default()
|
||||
},
|
||||
..Options::default()
|
||||
})
|
||||
})
|
||||
|
@ -308,10 +314,14 @@ other-attribute = 1
|
|||
"migrations".to_string(),
|
||||
"with_excluded_file/other_excluded_file.py".to_string(),
|
||||
]),
|
||||
per_file_ignores: Some(FxHashMap::from_iter([(
|
||||
"__init__.py".to_string(),
|
||||
vec![codes::Pyflakes::_401.into()]
|
||||
)])),
|
||||
|
||||
lint_top_level: LintOptions {
|
||||
per_file_ignores: Some(FxHashMap::from_iter([(
|
||||
"__init__.py".to_string(),
|
||||
vec![codes::Pyflakes::_401.into()]
|
||||
)])),
|
||||
..LintOptions::default()
|
||||
},
|
||||
..Options::default()
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue