mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:15:12 +00:00
Avoid parsing the root configuration twice (#10625)
This commit is contained in:
parent
068e22d382
commit
376fb71a7f
3 changed files with 37 additions and 30 deletions
|
@ -207,6 +207,15 @@ impl RuleSet {
|
||||||
*self = set.union(&RuleSet::from_rule(rule));
|
*self = set.union(&RuleSet::from_rule(rule));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn set(&mut self, rule: Rule, enabled: bool) {
|
||||||
|
if enabled {
|
||||||
|
self.insert(rule);
|
||||||
|
} else {
|
||||||
|
self.remove(rule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes `rule` from the set.
|
/// Removes `rule` from the set.
|
||||||
///
|
///
|
||||||
/// ## Examples
|
/// ## Examples
|
||||||
|
|
|
@ -867,11 +867,7 @@ impl LintConfiguration {
|
||||||
} else {
|
} else {
|
||||||
// Otherwise we apply the updates on top of the existing select_set.
|
// Otherwise we apply the updates on top of the existing select_set.
|
||||||
for (rule, enabled) in select_map_updates {
|
for (rule, enabled) in select_map_updates {
|
||||||
if enabled {
|
select_set.set(rule, enabled);
|
||||||
select_set.insert(rule);
|
|
||||||
} else {
|
|
||||||
select_set.remove(rule);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for rule in docstring_override_updates {
|
for rule in docstring_override_updates {
|
||||||
|
@ -894,11 +890,7 @@ impl LintConfiguration {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (rule, enabled) in fixable_map_updates {
|
for (rule, enabled) in fixable_map_updates {
|
||||||
if enabled {
|
fixable_set.set(rule, enabled);
|
||||||
fixable_set.insert(rule);
|
|
||||||
} else {
|
|
||||||
fixable_set.remove(rule);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1095,31 +1087,27 @@ impl LintConfiguration {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn combine(self, config: Self) -> Self {
|
pub fn combine(self, config: Self) -> Self {
|
||||||
|
let mut rule_selections = config.rule_selections;
|
||||||
|
rule_selections.extend(self.rule_selections);
|
||||||
|
|
||||||
|
let mut extend_safe_fixes = config.extend_safe_fixes;
|
||||||
|
extend_safe_fixes.extend(self.extend_safe_fixes);
|
||||||
|
|
||||||
|
let mut extend_unsafe_fixes = config.extend_unsafe_fixes;
|
||||||
|
extend_unsafe_fixes.extend(self.extend_unsafe_fixes);
|
||||||
|
|
||||||
|
let mut extend_per_file_ignores = config.extend_per_file_ignores;
|
||||||
|
extend_per_file_ignores.extend(self.extend_per_file_ignores);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
exclude: self.exclude.or(config.exclude),
|
exclude: self.exclude.or(config.exclude),
|
||||||
preview: self.preview.or(config.preview),
|
preview: self.preview.or(config.preview),
|
||||||
rule_selections: config
|
rule_selections,
|
||||||
.rule_selections
|
extend_safe_fixes,
|
||||||
.into_iter()
|
extend_unsafe_fixes,
|
||||||
.chain(self.rule_selections)
|
|
||||||
.collect(),
|
|
||||||
extend_safe_fixes: config
|
|
||||||
.extend_safe_fixes
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.extend_safe_fixes)
|
|
||||||
.collect(),
|
|
||||||
extend_unsafe_fixes: config
|
|
||||||
.extend_unsafe_fixes
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.extend_unsafe_fixes)
|
|
||||||
.collect(),
|
|
||||||
allowed_confusables: self.allowed_confusables.or(config.allowed_confusables),
|
allowed_confusables: self.allowed_confusables.or(config.allowed_confusables),
|
||||||
dummy_variable_rgx: self.dummy_variable_rgx.or(config.dummy_variable_rgx),
|
dummy_variable_rgx: self.dummy_variable_rgx.or(config.dummy_variable_rgx),
|
||||||
extend_per_file_ignores: config
|
extend_per_file_ignores,
|
||||||
.extend_per_file_ignores
|
|
||||||
.into_iter()
|
|
||||||
.chain(self.extend_per_file_ignores)
|
|
||||||
.collect(),
|
|
||||||
external: self.external.or(config.external),
|
external: self.external.or(config.external),
|
||||||
ignore_init_module_imports: self
|
ignore_init_module_imports: self
|
||||||
.ignore_init_module_imports
|
.ignore_init_module_imports
|
||||||
|
|
|
@ -335,6 +335,12 @@ pub fn python_files_in_path<'a>(
|
||||||
// Search for `pyproject.toml` files in all parent directories.
|
// Search for `pyproject.toml` files in all parent directories.
|
||||||
let mut resolver = Resolver::new(pyproject_config);
|
let mut resolver = Resolver::new(pyproject_config);
|
||||||
let mut seen = FxHashSet::default();
|
let mut seen = FxHashSet::default();
|
||||||
|
|
||||||
|
// Insert the path to the root configuration to avoid parsing the configuration a second time.
|
||||||
|
if let Some(config_path) = &pyproject_config.path {
|
||||||
|
seen.insert(config_path.parent().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
if resolver.is_hierarchical() {
|
if resolver.is_hierarchical() {
|
||||||
for path in &paths {
|
for path in &paths {
|
||||||
for ancestor in path.ancestors() {
|
for ancestor in path.ancestors() {
|
||||||
|
@ -343,8 +349,12 @@ pub fn python_files_in_path<'a>(
|
||||||
let (root, settings) =
|
let (root, settings) =
|
||||||
resolve_scoped_settings(&pyproject, Relativity::Parent, transformer)?;
|
resolve_scoped_settings(&pyproject, Relativity::Parent, transformer)?;
|
||||||
resolver.add(root, settings);
|
resolver.add(root, settings);
|
||||||
|
// We found the closest configuration.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// We already visited this ancestor, we can stop here.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue