mirror of https://github.com/astral-sh/ruff
Avoid multiline quotes warning with `quote-style = preserve` (#11490)
## Summary Closes https://github.com/astral-sh/ruff/issues/11063.
This commit is contained in:
parent
9ff18bf9d3
commit
5bb9720a10
|
|
@ -857,12 +857,20 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
|
||||||
|
|
||||||
if setting.linter.rules.enabled(Rule::BadQuotesMultilineString)
|
if setting.linter.rules.enabled(Rule::BadQuotesMultilineString)
|
||||||
&& setting.linter.flake8_quotes.multiline_quotes == Quote::Single
|
&& setting.linter.flake8_quotes.multiline_quotes == Quote::Single
|
||||||
|
&& matches!(
|
||||||
|
setting.formatter.quote_style,
|
||||||
|
QuoteStyle::Single | QuoteStyle::Double
|
||||||
|
)
|
||||||
{
|
{
|
||||||
warn_user_once!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q001` when using the formatter, which enforces double quotes for multiline strings. Alternatively, set the `flake8-quotes.multiline-quotes` option to `\"double\"`.`");
|
warn_user_once!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q001` when using the formatter, which enforces double quotes for multiline strings. Alternatively, set the `flake8-quotes.multiline-quotes` option to `\"double\"`.`");
|
||||||
}
|
}
|
||||||
|
|
||||||
if setting.linter.rules.enabled(Rule::BadQuotesDocstring)
|
if setting.linter.rules.enabled(Rule::BadQuotesDocstring)
|
||||||
&& setting.linter.flake8_quotes.docstring_quotes == Quote::Single
|
&& setting.linter.flake8_quotes.docstring_quotes == Quote::Single
|
||||||
|
&& matches!(
|
||||||
|
setting.formatter.quote_style,
|
||||||
|
QuoteStyle::Single | QuoteStyle::Double
|
||||||
|
)
|
||||||
{
|
{
|
||||||
warn_user_once!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q002` when using the formatter, which enforces double quotes for docstrings. Alternatively, set the `flake8-quotes.docstring-quotes` option to `\"double\"`.`");
|
warn_user_once!("The `flake8-quotes.multiline-quotes=\"single\"` option is incompatible with the formatter. We recommend disabling `Q002` when using the formatter, which enforces double quotes for docstrings. Alternatively, set the `flake8-quotes.docstring-quotes` option to `\"double\"`.`");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1038,6 +1038,48 @@ def say_hy(name: str):
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn valid_linter_options_preserve() -> Result<()> {
|
||||||
|
let tempdir = TempDir::new()?;
|
||||||
|
let ruff_toml = tempdir.path().join("ruff.toml");
|
||||||
|
fs::write(
|
||||||
|
&ruff_toml,
|
||||||
|
r#"
|
||||||
|
[lint]
|
||||||
|
select = ["Q"]
|
||||||
|
|
||||||
|
[lint.flake8-quotes]
|
||||||
|
inline-quotes = "single"
|
||||||
|
docstring-quotes = "single"
|
||||||
|
multiline-quotes = "single"
|
||||||
|
|
||||||
|
[format]
|
||||||
|
quote-style = "preserve"
|
||||||
|
"#,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let test_path = tempdir.path().join("test.py");
|
||||||
|
fs::write(
|
||||||
|
&test_path,
|
||||||
|
r#"
|
||||||
|
def say_hy(name: str):
|
||||||
|
print(f"Hy {name}")"#,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||||
|
.args(["format", "--no-cache", "--config"])
|
||||||
|
.arg(&ruff_toml)
|
||||||
|
.arg(test_path), @r###"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
1 file reformatted
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
"###);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn all_rules_default_options() -> Result<()> {
|
fn all_rules_default_options() -> Result<()> {
|
||||||
let tempdir = TempDir::new()?;
|
let tempdir = TempDir::new()?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue