mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Support new extend-per-file-ignores
setting (#4265)
This commit is contained in:
parent
837e70677b
commit
41a681531d
7 changed files with 62 additions and 8 deletions
|
@ -48,6 +48,7 @@ pub struct Configuration {
|
|||
pub extend: Option<PathBuf>,
|
||||
pub extend_exclude: Vec<FilePattern>,
|
||||
pub extend_include: Vec<FilePattern>,
|
||||
pub extend_per_file_ignores: Vec<PerFileIgnore>,
|
||||
pub external: Option<Vec<String>>,
|
||||
pub fix: Option<bool>,
|
||||
pub fix_only: Option<bool>,
|
||||
|
@ -166,6 +167,17 @@ impl Configuration {
|
|||
.collect()
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
extend_per_file_ignores: options
|
||||
.extend_per_file_ignores
|
||||
.map(|per_file_ignores| {
|
||||
per_file_ignores
|
||||
.into_iter()
|
||||
.map(|(pattern, prefixes)| {
|
||||
PerFileIgnore::new(pattern, &prefixes, Some(project_root))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
external: options.external,
|
||||
fix: options.fix,
|
||||
fix_only: options.fix_only,
|
||||
|
@ -254,6 +266,11 @@ impl Configuration {
|
|||
.into_iter()
|
||||
.chain(self.extend_include.into_iter())
|
||||
.collect(),
|
||||
extend_per_file_ignores: config
|
||||
.extend_per_file_ignores
|
||||
.into_iter()
|
||||
.chain(self.extend_per_file_ignores.into_iter())
|
||||
.collect(),
|
||||
external: self.external.or(config.external),
|
||||
fix: self.fix.or(config.fix),
|
||||
fix_only: self.fix_only.or(config.fix_only),
|
||||
|
|
|
@ -163,7 +163,12 @@ impl Settings {
|
|||
line_length: config.line_length.unwrap_or(defaults::LINE_LENGTH),
|
||||
namespace_packages: config.namespace_packages.unwrap_or_default(),
|
||||
per_file_ignores: resolve_per_file_ignores(
|
||||
config.per_file_ignores.unwrap_or_default(),
|
||||
config
|
||||
.per_file_ignores
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.chain(config.extend_per_file_ignores)
|
||||
.collect(),
|
||||
)?,
|
||||
respect_gitignore: config.respect_gitignore.unwrap_or(true),
|
||||
src: config
|
||||
|
|
|
@ -541,4 +541,16 @@ pub struct Options {
|
|||
/// A list of mappings from file pattern to rule codes or prefixes to
|
||||
/// exclude, when considering any matching files.
|
||||
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
|
||||
#[option(
|
||||
default = "{}",
|
||||
value_type = "dict[str, list[RuleSelector]]",
|
||||
example = r#"
|
||||
# Also ignore `E401` in all `__init__.py` files.
|
||||
[tool.ruff.extend-per-file-ignores]
|
||||
"__init__.py" = ["E402"]
|
||||
"#
|
||||
)]
|
||||
/// A list of mappings from file pattern to rule codes or prefixes to
|
||||
/// exclude, in addition to any rules excluded by `per-file-ignores`.
|
||||
pub extend_per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
|
||||
}
|
||||
|
|
|
@ -133,8 +133,8 @@ pub struct CheckArgs {
|
|||
hide_possible_values = true
|
||||
)]
|
||||
pub ignore: Option<Vec<RuleSelector>>,
|
||||
/// Like --select, but adds additional rule codes on top of the selected
|
||||
/// ones.
|
||||
/// Like --select, but adds additional rule codes on top of those already
|
||||
/// specified.
|
||||
#[arg(
|
||||
long,
|
||||
value_delimiter = ',',
|
||||
|
@ -154,9 +154,13 @@ pub struct CheckArgs {
|
|||
hide = true
|
||||
)]
|
||||
pub extend_ignore: Option<Vec<RuleSelector>>,
|
||||
/// List of mappings from file pattern to code to exclude
|
||||
/// List of mappings from file pattern to code to exclude.
|
||||
#[arg(long, value_delimiter = ',', help_heading = "Rule selection")]
|
||||
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||
/// Like `--per-file-ignores`, but adds additional ignores on top of
|
||||
/// those already specified.
|
||||
#[arg(long, value_delimiter = ',', help_heading = "Rule selection")]
|
||||
pub extend_per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||
/// List of paths, used to omit files and/or directories from analysis.
|
||||
#[arg(
|
||||
long,
|
||||
|
@ -196,8 +200,8 @@ pub struct CheckArgs {
|
|||
hide_possible_values = true
|
||||
)]
|
||||
pub unfixable: Option<Vec<RuleSelector>>,
|
||||
/// Like --fixable, but adds additional rule codes on top of the fixable
|
||||
/// ones.
|
||||
/// Like --fixable, but adds additional rule codes on top of those already
|
||||
/// specified.
|
||||
#[arg(
|
||||
long,
|
||||
value_delimiter = ',',
|
||||
|
|
|
@ -111,6 +111,7 @@ pub fn defaultSettings() -> Result<JsValue, JsValue> {
|
|||
extend: None,
|
||||
extend_exclude: None,
|
||||
extend_include: None,
|
||||
extend_per_file_ignores: None,
|
||||
fix: None,
|
||||
fix_only: None,
|
||||
fixable: None,
|
||||
|
|
|
@ -232,15 +232,17 @@ Rule selection:
|
|||
--ignore <RULE_CODE>
|
||||
Comma-separated list of rule codes to disable
|
||||
--extend-select <RULE_CODE>
|
||||
Like --select, but adds additional rule codes on top of the selected ones
|
||||
Like --select, but adds additional rule codes on top of those already specified
|
||||
--per-file-ignores <PER_FILE_IGNORES>
|
||||
List of mappings from file pattern to code to exclude
|
||||
--extend-per-file-ignores <EXTEND_PER_FILE_IGNORES>
|
||||
Like `--per-file-ignores`, but adds additional ignores on top of those already specified
|
||||
--fixable <RULE_CODE>
|
||||
List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||
--unfixable <RULE_CODE>
|
||||
List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||
--extend-fixable <RULE_CODE>
|
||||
Like --fixable, but adds additional rule codes on top of the fixable ones
|
||||
Like --fixable, but adds additional rule codes on top of those already specified
|
||||
|
||||
File selection:
|
||||
--exclude <FILE_PATTERN> List of paths, used to omit files and/or directories from analysis
|
||||
|
|
13
ruff.schema.json
generated
13
ruff.schema.json
generated
|
@ -86,6 +86,19 @@
|
|||
"type": "string"
|
||||
}
|
||||
},
|
||||
"extend-per-file-ignores": {
|
||||
"description": "A list of mappings from file pattern to rule codes or prefixes to exclude, in addition to any rules excluded by `per-file-ignores`.",
|
||||
"type": [
|
||||
"object",
|
||||
"null"
|
||||
],
|
||||
"additionalProperties": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/RuleSelector"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extend-select": {
|
||||
"description": "A list of rule codes or prefixes to enable, in addition to those specified by `select`.",
|
||||
"type": [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue