mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Only run pyproject.toml lint rules when enabled (#5578)
## Summary I was testing some changes on Airflow, and I realized that we _always_ run the `pyproject.toml` validation rules, even if they're not enabled. This PR gates them behind the appropriate enablement flags. ## Test Plan - Ran: `cargo run -p ruff_cli -- check ../airflow -n`. Verified that no RUF200 violations were raised. - Run: `cargo run -p ruff_cli -- check ../airflow -n --select RUF200`. Verified that two RUF200 violations were raised.
This commit is contained in:
parent
d0dae7e576
commit
a1c559eaa4
4 changed files with 50 additions and 25 deletions
|
@ -127,11 +127,20 @@ pub(crate) fn lint_path(
|
|||
|
||||
debug!("Checking: {}", path.display());
|
||||
|
||||
// We have to special case this here since the python tokenizer doesn't work with toml
|
||||
// We have to special case this here since the Python tokenizer doesn't work with TOML.
|
||||
if is_project_toml(path) {
|
||||
let contents = std::fs::read_to_string(path)?;
|
||||
let source_file = SourceFileBuilder::new(path.to_string_lossy(), contents).finish();
|
||||
let messages = lint_pyproject_toml(source_file)?;
|
||||
let messages = if settings
|
||||
.lib
|
||||
.rules
|
||||
.iter_enabled()
|
||||
.any(|rule_code| rule_code.lint_source().is_pyproject_toml())
|
||||
{
|
||||
let contents = std::fs::read_to_string(path)?;
|
||||
let source_file = SourceFileBuilder::new(path.to_string_lossy(), contents).finish();
|
||||
lint_pyproject_toml(source_file, &settings.lib)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
return Ok(Diagnostics {
|
||||
messages,
|
||||
..Diagnostics::default()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue