Add per-file-target-version option (#16257)

## Summary

This PR is another step in preparing to detect syntax errors in the
parser. It introduces the new `per-file-target-version` top-level
configuration option, which holds a mapping of compiled glob patterns to
Python versions. I intend to use the
`LinterSettings::resolve_target_version` method here to pass to the
parser:


f50849aeef/crates/ruff_linter/src/linter.rs (L491-L493)

## Test Plan

I added two new CLI tests to show that the `per-file-target-version` is
respected in both the formatter and the linter.
This commit is contained in:
Brent Westbrook 2025-02-24 08:47:13 -05:00 committed by GitHub
parent 42a5f5ef6a
commit e7a6c19e3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
78 changed files with 820 additions and 274 deletions

View file

@ -104,6 +104,8 @@ pub fn check_path(
));
}
let target_version = settings.resolve_target_version(path);
// Run the filesystem-based rules.
if settings
.rules
@ -116,6 +118,7 @@ pub fn check_path(
locator,
comment_ranges,
settings,
target_version,
));
}
@ -158,6 +161,7 @@ pub fn check_path(
source_type,
cell_offsets,
notebook_index,
target_version,
));
}
if use_imports {
@ -171,6 +175,7 @@ pub fn check_path(
package,
source_type,
cell_offsets,
target_version,
);
diagnostics.extend(import_diagnostics);