Skip to content

Commit

Permalink
Remove deprecated top-level lint settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 24, 2024
1 parent 32ccc38 commit 6f9f694
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 1,103 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool.ruff]
[tool.ruff.lint]
select = []
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tool.ruff]
include = ["a.py", "subdirectory/c.py"]
include = ["a.py", "subdirectory/c.py"]
1 change: 0 additions & 1 deletion crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ impl ConfigArguments {
.unwrap_or_else(|option| option.deref().clone());
overrides = overrides.combine(Configuration::from_options(
overridden_option,
None,
&path_dedot::CWD,
)?);
}
Expand Down
8 changes: 2 additions & 6 deletions crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ fn exclude_stdin() -> Result<()> {
fs::write(
&ruff_toml,
r#"
[lint]
extend-select = ["B", "Q"]
ignore = ["Q000", "Q001", "Q002", "Q003"]
Expand All @@ -683,9 +684,6 @@ if __name__ == '__main__':
say_hy("dear Ruff contributor")
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
- 'ignore' -> 'lint.ignore'
"###);
Ok(())
}
Expand All @@ -697,6 +695,7 @@ fn force_exclude_stdin() -> Result<()> {
fs::write(
&ruff_toml,
r#"
[lint]
extend-select = ["B", "Q"]
ignore = ["Q000", "Q001", "Q002", "Q003"]
Expand Down Expand Up @@ -724,9 +723,6 @@ if __name__ == '__main__':
say_hy("dear Ruff contributor")
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
- 'ignore' -> 'lint.ignore'
"###);
Ok(())
}
Expand Down
176 changes: 10 additions & 166 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,6 @@ fn tempdir_filter(tempdir: &TempDir) -> String {
format!(r"{}\\?/?", escape(tempdir.path().to_str().unwrap()))
}

#[test]
fn top_level_options() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
extend-select = ["B", "Q"]
[flake8-quotes]
inline-quotes = "single"
"#,
)?;

insta::with_settings!({
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(&ruff_toml)
.args(["--stdin-filename", "test.py"])
.arg("-")
.pass_stdin(r#"a = "abcba".strip("aba")"#), @r###"
success: false
exit_code: 1
----- stdout -----
test.py:1:5: Q000 [*] Double quotes found but single quotes preferred
test.py:1:5: B005 Using `.strip()` with multi-character strings is misleading
test.py:1:19: Q000 [*] Double quotes found but single quotes preferred
Found 3 errors.
[*] 2 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `[TMP]/ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
- 'flake8-quotes' -> 'lint.flake8-quotes'
"###);
});

Ok(())
}

#[test]
fn lint_options() -> Result<()> {
let tempdir = TempDir::new()?;
Expand Down Expand Up @@ -101,106 +58,18 @@ inline-quotes = "single"
Ok(())
}

/// Tests that configurations from the top-level and `lint` section are merged together.
#[test]
fn mixed_levels() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
extend-select = ["B", "Q"]
[lint.flake8-quotes]
inline-quotes = "single"
"#,
)?;

insta::with_settings!({
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(&ruff_toml)
.arg("-")
.pass_stdin(r#"a = "abcba".strip("aba")"#), @r###"
success: false
exit_code: 1
----- stdout -----
-:1:5: Q000 [*] Double quotes found but single quotes preferred
-:1:5: B005 Using `.strip()` with multi-character strings is misleading
-:1:19: Q000 [*] Double quotes found but single quotes preferred
Found 3 errors.
[*] 2 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `[TMP]/ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
"###);
});

Ok(())
}

/// Tests that options in the `lint` section have higher precedence than top-level options (because they are more specific).
#[test]
fn precedence() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
[lint]
extend-select = ["B", "Q"]
[flake8-quotes]
inline-quotes = "double"
[lint.flake8-quotes]
inline-quotes = "single"
"#,
)?;

insta::with_settings!({
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(&ruff_toml)
.arg("-")
.pass_stdin(r#"a = "abcba".strip("aba")"#), @r###"
success: false
exit_code: 1
----- stdout -----
-:1:5: Q000 [*] Double quotes found but single quotes preferred
-:1:5: B005 Using `.strip()` with multi-character strings is misleading
-:1:19: Q000 [*] Double quotes found but single quotes preferred
Found 3 errors.
[*] 2 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `[TMP]/ruff.toml`:
- 'flake8-quotes' -> 'lint.flake8-quotes'
"###);
});

Ok(())
}

#[test]
fn exclude() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
extend-select = ["B", "Q"]
extend-exclude = ["out"]
[lint]
exclude = ["test.py", "generated.py"]
extend-select = ["B", "Q"]
[lint.flake8-quotes]
inline-quotes = "single"
Expand Down Expand Up @@ -262,8 +131,6 @@ OTHER = "OTHER"
[*] 3 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
"###);
});

Expand All @@ -277,9 +144,9 @@ fn exclude_stdin() -> Result<()> {
fs::write(
&ruff_toml,
r#"
extend-select = ["B", "Q"]
[lint]
extend-select = ["B", "Q"]
exclude = ["generated.py"]
[lint.flake8-quotes]
Expand Down Expand Up @@ -311,8 +178,6 @@ if __name__ == "__main__":
[*] 2 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
"###);
});

Expand All @@ -327,9 +192,11 @@ fn line_too_long_width_override() -> Result<()> {
&ruff_toml,
r#"
line-length = 80
[lint]
select = ["E501"]
[pycodestyle]
[lint.pycodestyle]
max-line-length = 100
"#,
)?;
Expand All @@ -356,9 +223,6 @@ _ = "---------------------------------------------------------------------------
Found 1 error.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `[TMP]/ruff.toml`:
- 'select' -> 'lint.select'
- 'pycodestyle' -> 'lint.pycodestyle'
"###);
});

Expand All @@ -372,6 +236,7 @@ fn per_file_ignores_stdin() -> Result<()> {
fs::write(
&ruff_toml,
r#"
[lint]
extend-select = ["B", "Q"]
[lint.flake8-quotes]
Expand Down Expand Up @@ -405,8 +270,6 @@ if __name__ == "__main__":
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
"###);
});

Expand All @@ -420,6 +283,7 @@ fn extend_per_file_ignores_stdin() -> Result<()> {
fs::write(
&ruff_toml,
r#"
[lint]
extend-select = ["B", "Q"]
[lint.flake8-quotes]
Expand Down Expand Up @@ -453,8 +317,6 @@ if __name__ == "__main__":
[*] 1 fixable with the `--fix` option.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `ruff.toml`:
- 'extend-select' -> 'lint.extend-select'
"###);
});

Expand Down Expand Up @@ -698,14 +560,14 @@ x = "longer_than_90_charactersssssssssssssssssssssssssssssssssssssssssssssssssss
fn valid_toml_but_nonexistent_option_provided_via_config_argument() {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.args([".", "--config", "extend-select=['F481']"]), // No such code as F481!
.args([".", "--config", "lint.extend-select=['F481']"]), // No such code as F481!
@r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: invalid value 'extend-select=['F481']' for '--config <CONFIG_OPTION>'
error: invalid value 'lint.extend-select=['F481']' for '--config <CONFIG_OPTION>'
tip: A `--config` flag must either be a path to a `.toml` configuration file
or a TOML `<KEY> = <VALUE>` pair overriding a specific configuration
Expand All @@ -714,6 +576,7 @@ fn valid_toml_but_nonexistent_option_provided_via_config_argument() {
Could not parse the supplied argument as a `ruff.toml` configuration option:
Unknown rule selector: `F481`
in `lint.extend-select`
For more information, try '--help'.
"###);
Expand Down Expand Up @@ -841,25 +704,6 @@ fn complex_config_setting_overridden_via_cli() -> Result<()> {
Ok(())
}

#[test]
fn deprecated_config_option_overridden_via_cli() {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.args(["--config", "select=['N801']", "-"])
.pass_stdin("class lowercase: ..."),
@r###"
success: false
exit_code: 1
----- stdout -----
-:1:7: N801 Class name `lowercase` should use CapWords convention
Found 1 error.
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in your `--config` CLI arguments:
- 'select' -> 'lint.select'
"###);
}

#[test]
fn extension() -> Result<()> {
let tempdir = TempDir::new()?;
Expand Down
2 changes: 0 additions & 2 deletions crates/ruff/tests/resolve_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ fn check_project_include_defaults() {
[BASEPATH]/include-test/subdirectory/c.py
----- stderr -----
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `nested-project/pyproject.toml`:
- 'select' -> 'lint.select'
"###);
});
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,5 @@ fn open_configuration_file(
) -> crate::Result<Configuration> {
let options = ruff_workspace::pyproject::load_options(config_path)?;

Configuration::from_options(options, Some(config_path), project_root)
Configuration::from_options(options, project_root)
}
Loading

0 comments on commit 6f9f694

Please sign in to comment.