Skip to content

Commit

Permalink
Ignore preview status for fixable and unfixable selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 16, 2024
1 parent f9331c7 commit 37f42fa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
68 changes: 66 additions & 2 deletions crates/ruff_cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,9 @@ fn nursery_direct() {
success: false
exit_code: 1
----- stdout -----
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 1 error.
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: Selection of nursery rule `E225` without the `--preview` flag is deprecated.
Expand All @@ -859,8 +860,9 @@ fn nursery_group_selector() {
exit_code: 1
----- stdout -----
-:1:1: CPY001 Missing copyright notice at top of file
-:1:2: E225 Missing whitespace around operator
-:1:2: E225 [*] Missing whitespace around operator
Found 2 errors.
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: The `NURSERY` selector has been deprecated. Use the `--preview` flag instead.
Expand Down Expand Up @@ -1656,3 +1658,65 @@ def log(x, base) -> float:
);
Ok(())
}

#[test]
fn fix_preview() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
[lint]
preview = true
explicit-preview-rules = true
select = ["RUF017"]
"#,
)?;

let mut cmd = RuffCheck::default().config(&ruff_toml).build();
assert_cmd_snapshot!(cmd
.pass_stdin("x = [1, 2, 3]\ny = [4, 5, 6]\nsum([x, y], [])"),
@r###"
success: false
exit_code: 1
----- stdout -----
-:3:1: RUF017 Avoid quadratic list summation
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).
----- stderr -----
"###);

Ok(())
}

#[test]
fn unfixable_preview() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
[lint]
preview = true
explicit-preview-rules = true
select = ["RUF017"]
unfixable = ["RUF"]
"#,
)?;

let mut cmd = RuffCheck::default().config(&ruff_toml).build();
assert_cmd_snapshot!(cmd
.pass_stdin("x = [1, 2, 3]\ny = [4, 5, 6]\nsum([x, y], [])"),
@r###"
success: false
exit_code: 1
----- stdout -----
-:3:1: RUF017 Avoid quadratic list summation
Found 1 error.
----- stderr -----
"###);

Ok(())
}
6 changes: 3 additions & 3 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ impl LintConfiguration {
.collect();

// The fixable set keeps track of which rules are fixable.
let mut fixable_set: RuleSet = RuleSelector::All.rules(&preview).collect();
let mut fixable_set: RuleSet = RuleSelector::All.all_rules().collect();

// Ignores normally only subtract from the current set of selected
// rules. By that logic the ignore in `select = [], ignore = ["E501"]`
Expand Down Expand Up @@ -786,7 +786,7 @@ impl LintConfiguration {
.chain(selection.extend_fixable.iter())
.filter(|s| s.specificity() == spec)
{
for rule in selector.rules(&preview) {
for rule in selector.all_rules() {
fixable_map_updates.insert(rule, true);
}
}
Expand All @@ -796,7 +796,7 @@ impl LintConfiguration {
.chain(carriedover_unfixables.into_iter().flatten())
.filter(|s| s.specificity() == spec)
{
for rule in selector.rules(&preview) {
for rule in selector.all_rules() {
fixable_map_updates.insert(rule, false);
}
}
Expand Down

0 comments on commit 37f42fa

Please sign in to comment.