Skip to content
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

Merged
merged 29 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d01969c
Update CLI to respect fix applicability
evanrittenhouse Oct 2, 2023
74acdf5
Fixups for CI
zanieb Oct 2, 2023
85b5efe
Update CLI documentation for fixes
zanieb Oct 3, 2023
7c05fb5
Use `self.flags.intersects` consistently
zanieb Oct 3, 2023
87def58
Revert change to notebook cell iteration
zanieb Oct 3, 2023
6577833
Remove stale todo from test
zanieb Oct 3, 2023
d004ddc
Cleanup internal commentary on the fix rules
zanieb Oct 3, 2023
96b8ce1
Refactor `fix_file` implementation to use `Fix.applies`
zanieb Oct 3, 2023
9949fa0
Use different symbols for fix messages depending on applicability
zanieb Oct 3, 2023
ee903bf
Update snapshots to reflect changes in fix messages
zanieb Oct 3, 2023
b24d9dd
Remove comment detailing ordering
zanieb Oct 4, 2023
a5ef7d6
Refactor `RuleCodeAndBody.fmt` to avoid using `unwrap`
zanieb Oct 4, 2023
cb6c25e
Do not display fixes with manual applicability
zanieb Oct 4, 2023
8683340
Rename `--suggested-fix` to `--unsafe-fixes` and fix interaction with…
zanieb Oct 4, 2023
d3f0558
Improve messaging around unsafe fixes
zanieb Oct 4, 2023
d35d68d
Refactor `UnsafeFixes` out of `FixMode`
zanieb Oct 5, 2023
953ee4a
Merge branch 'main' into zanie/applicability
zanieb Oct 5, 2023
98c2c29
Update order of applicability levels for `Ord`
zanieb Oct 5, 2023
f57b853
Fix merge compile errors
zanieb Oct 5, 2023
a57e3d3
Refactor unsafe fix display to avoid using flags
zanieb Oct 5, 2023
d3cb905
Fix unsafe fixes in grouped emitter
zanieb Oct 5, 2023
2a5f454
Refactor `FixableStatistics`
zanieb Oct 5, 2023
8d89499
Lint
zanieb Oct 5, 2023
b72ab24
Fixup `CheckCommand`
zanieb Oct 5, 2023
356f409
`FixableStatistics` -> `FixableSummary`
zanieb Oct 5, 2023
1bbc858
Wrap --fix and --unsafe-fixes in code quotes
zanieb Oct 5, 2023
b6e3a9a
Clean up integration tests
zanieb Oct 5, 2023
47b146b
Commit missing snapshot
zanieb Oct 5, 2023
859ac7d
Avoid reading `unsafe_fixes` from nested configuration files
zanieb Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ pub enum Command {
pub struct CheckCommand {
/// List of files or directories to check.
pub files: Vec<PathBuf>,
/// Attempt to automatically fix lint violations.
/// Use `--no-fix` to disable.
/// Apply fixes to resolve lint violations.
/// Use `--no-fix` to disable or `--unsafe-fixes` to include suggested fixes.
#[arg(long, overrides_with("no_fix"))]
fix: bool,
#[clap(long, overrides_with("fix"), hide = true)]
/// Include fixes that may not retain the original intent of the code.
#[arg(long)]
unsafe_fixes: bool,
#[clap(long, overrides_with_all(["fix"]), hide = true)]
no_fix: bool,
/// Show violations with source code.
/// Use `--no-show-source` to disable.
Expand All @@ -100,8 +103,8 @@ pub struct CheckCommand {
/// Run in watch mode by re-running whenever files change.
#[arg(short, long)]
pub watch: bool,
/// Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`.
/// Use `--no-fix-only` to disable.
/// Apply fixes to resolve lint violations, but don't report on leftover violations. Implies `--fix`.
/// Use `--no-fix-only` to disable or `--unsafe-fixes` to include suggested fixes.
#[arg(long, overrides_with("no_fix_only"))]
fix_only: bool,
#[clap(long, overrides_with("fix_only"), hide = true)]
Expand Down Expand Up @@ -497,6 +500,7 @@ impl CheckCommand {
cache_dir: self.cache_dir,
fix: resolve_bool_arg(self.fix, self.no_fix),
fix_only: resolve_bool_arg(self.fix_only, self.no_fix_only),
unsafe_fixes: Some(self.unsafe_fixes),
force_exclude: resolve_bool_arg(self.force_exclude, self.no_force_exclude),
output_format: self.output_format.or(self.format),
show_fixes: resolve_bool_arg(self.show_fixes, self.no_show_fixes),
Expand Down Expand Up @@ -599,6 +603,7 @@ pub struct CliOverrides {
pub cache_dir: Option<PathBuf>,
pub fix: Option<bool>,
pub fix_only: Option<bool>,
pub unsafe_fixes: Option<bool>,
pub force_exclude: Option<bool>,
pub output_format: Option<SerializationFormat>,
pub show_fixes: Option<bool>,
Expand All @@ -624,6 +629,9 @@ impl ConfigurationTransformer for CliOverrides {
if let Some(fix_only) = &self.fix_only {
config.fix_only = Some(*fix_only);
}
if self.unsafe_fixes.is_some() {
config.unsafe_fixes = self.unsafe_fixes;
}
config.lint.rule_selections.push(RuleSelection {
select: self.select.clone(),
ignore: self
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_cli/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ mod tests {
&settings.linter,
Some(&cache),
flags::Noqa::Enabled,
flags::FixMode::Generate,
flags::FixMode::Generate(flags::UnsafeFixes::Enabled),
)
.unwrap();
if diagnostics
Expand Down Expand Up @@ -454,7 +454,7 @@ mod tests {
&settings.linter,
Some(&cache),
flags::Noqa::Enabled,
flags::FixMode::Generate,
flags::FixMode::Generate(flags::UnsafeFixes::Enabled),
)
.unwrap();
}
Expand Down Expand Up @@ -711,7 +711,7 @@ mod tests {
&self.settings.linter,
Some(cache),
flags::Noqa::Enabled,
flags::FixMode::Generate,
flags::FixMode::Generate(flags::UnsafeFixes::Enabled),
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ mod test {
&CliOverrides::default(),
flags::Cache::Disabled,
flags::Noqa::Disabled,
flags::FixMode::Generate,
flags::FixMode::Generate(flags::UnsafeFixes::Enabled),
)
.unwrap();
let mut output = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/commands/check_stdin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) fn check_stdin(
let mut diagnostics = lint_stdin(
filename,
package_root,
stdin,
&stdin,
&pyproject_config.settings,
noqa,
fix_mode,
Expand Down
Loading