-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update CLI to respect fix applicability #7769
Changes from 23 commits
d01969c
74acdf5
85b5efe
7c05fb5
87def58
6577833
d004ddc
96b8ce1
9949fa0
ee903bf
b24d9dd
a5ef7d6
cb6c25e
8683340
d3f0558
d35d68d
953ee4a
98c2c29
f57b853
a57e3d3
d3cb905
2a5f454
8d89499
b72ab24
356f409
1bbc858
b6e3a9a
47b146b
859ac7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ use anyhow::{Context, Result}; | |
use colored::Colorize; | ||
use filetime::FileTime; | ||
use log::{debug, error, warn}; | ||
use ruff_linter::settings::types::UnsafeFixes; | ||
use rustc_hash::FxHashMap; | ||
|
||
use ruff_diagnostics::Diagnostic; | ||
|
@@ -168,6 +169,7 @@ pub(crate) fn lint_path( | |
cache: Option<&Cache>, | ||
noqa: flags::Noqa, | ||
fix_mode: flags::FixMode, | ||
unsafe_fixes: UnsafeFixes, | ||
) -> Result<Diagnostics> { | ||
// Check the cache. | ||
// TODO(charlie): `fixer::Mode::Apply` and `fixer::Mode::Diff` both have | ||
|
@@ -244,8 +246,15 @@ pub(crate) fn lint_path( | |
result, | ||
transformed, | ||
fixed, | ||
}) = lint_fix(path, package, noqa, settings, &source_kind, source_type) | ||
{ | ||
}) = lint_fix( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted some changes around here to minimize the diff |
||
path, | ||
package, | ||
noqa, | ||
unsafe_fixes, | ||
settings, | ||
&source_kind, | ||
source_type, | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Konsti's suggestion (which it's totally up to you whether you take) was to do, like:
...to avoid having a long expanded call on the RHS of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I'll do that separately. I want to use |
||
if !fixed.is_empty() { | ||
match fix_mode { | ||
flags::FixMode::Apply => transformed.write(&mut File::create(path)?)?, | ||
|
@@ -355,6 +364,7 @@ pub(crate) fn lint_stdin( | |
path.unwrap_or_else(|| Path::new("-")), | ||
package, | ||
noqa, | ||
settings.unsafe_fixes, | ||
&settings.linter, | ||
&source_kind, | ||
source_type, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think accessing from
settings
here could lead to inconsistencies, since the Printer and Emitter and such will use the "global" value, but accessing fromsettings
here will read theunsafe-fixes
from a nested configuration file -- if I understand correctly.For example... if you had
unsafe-fixes = true
in apyproject.toml
at the top of the project, and thenunsafe-fixes = false
in apyproject.toml
in a subdirectory, wouldn't the CLI think you ran withunsafe-fixes
, where internally you would not run withunsafe-fixes
when analyzing files in the subdirectory?I suspect this should be passed down from the top-level like
fix_mode
for consistency throughout the execution.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm okay let me investigate that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah you're right! Good catch — I misunderstood that call hierarchy.