mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Remove formatter incompatibility warning for ISC001 (#15123)
This commit is contained in:
parent
424b720c19
commit
b76d05e283
4 changed files with 29 additions and 36 deletions
|
@ -233,7 +233,7 @@ pub(crate) fn format(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format the file at the given [`Path`].
|
/// Format the file at the given [`Path`].
|
||||||
#[tracing::instrument(level="debug", skip_all, fields(path = %path.display()))]
|
#[tracing::instrument(level = "debug", skip_all, fields(path = %path.display()))]
|
||||||
pub(crate) fn format_path(
|
pub(crate) fn format_path(
|
||||||
path: &Path,
|
path: &Path,
|
||||||
settings: &FormatterSettings,
|
settings: &FormatterSettings,
|
||||||
|
@ -788,8 +788,6 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
|
||||||
let mut incompatible_rules = FxHashSet::default();
|
let mut incompatible_rules = FxHashSet::default();
|
||||||
for setting in resolver.settings() {
|
for setting in resolver.settings() {
|
||||||
for rule in [
|
for rule in [
|
||||||
// The formatter might collapse implicit string concatenation on a single line.
|
|
||||||
Rule::SingleLineImplicitStringConcatenation,
|
|
||||||
// Flags missing trailing commas when all arguments are on its own line:
|
// Flags missing trailing commas when all arguments are on its own line:
|
||||||
// ```python
|
// ```python
|
||||||
// def args(
|
// def args(
|
||||||
|
@ -829,6 +827,19 @@ pub(super) fn warn_incompatible_formatter_settings(resolver: &Resolver) {
|
||||||
warn_user_once!("The `format.indent-style=\"tab\"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `\"space\"`.");
|
warn_user_once!("The `format.indent-style=\"tab\"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `\"space\"`.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !setting
|
||||||
|
.linter
|
||||||
|
.rules
|
||||||
|
.enabled(Rule::SingleLineImplicitStringConcatenation)
|
||||||
|
&& setting
|
||||||
|
.linter
|
||||||
|
.rules
|
||||||
|
.enabled(Rule::MultiLineImplicitStringConcatenation)
|
||||||
|
&& !setting.linter.flake8_implicit_str_concat.allow_multiline
|
||||||
|
{
|
||||||
|
warn_user_once!("The `lint.flake8-implicit-str-concat.allow-multiline = false` option is incompatible with the formatter unless `ISC001` is enabled. We recommend enabling `ISC001` or setting `allow-multiline=true`.");
|
||||||
|
}
|
||||||
|
|
||||||
// Validate all rules that rely on tab styles.
|
// Validate all rules that rely on tab styles.
|
||||||
if setting.linter.rules.enabled(Rule::DocstringTabIndentation)
|
if setting.linter.rules.enabled(Rule::DocstringTabIndentation)
|
||||||
&& setting.formatter.indent_style.is_tab()
|
&& setting.formatter.indent_style.is_tab()
|
||||||
|
|
|
@ -877,7 +877,7 @@ indent-width = 2
|
||||||
|
|
||||||
[lint]
|
[lint]
|
||||||
select = ["ALL"]
|
select = ["ALL"]
|
||||||
ignore = ["D203", "D212"]
|
ignore = ["D203", "D212", "ISC001"]
|
||||||
|
|
||||||
[lint.isort]
|
[lint.isort]
|
||||||
lines-after-imports = 3
|
lines-after-imports = 3
|
||||||
|
@ -891,6 +891,9 @@ inline-quotes = "single"
|
||||||
docstring-quotes = "single"
|
docstring-quotes = "single"
|
||||||
multiline-quotes = "single"
|
multiline-quotes = "single"
|
||||||
|
|
||||||
|
[lint.flake8-implicit-str-concat]
|
||||||
|
allow-multiline = false
|
||||||
|
|
||||||
[format]
|
[format]
|
||||||
skip-magic-trailing-comma = true
|
skip-magic-trailing-comma = true
|
||||||
indent-style = "tab"
|
indent-style = "tab"
|
||||||
|
@ -915,8 +918,9 @@ def say_hy(name: str):
|
||||||
1 file reformatted
|
1 file reformatted
|
||||||
|
|
||||||
----- stderr -----
|
----- stderr -----
|
||||||
warning: The following rules may cause conflicts when used with the formatter: `COM812`, `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.
|
warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration.
|
||||||
warning: The `format.indent-style="tab"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
warning: The `format.indent-style="tab"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
||||||
|
warning: The `lint.flake8-implicit-str-concat.allow-multiline = false` option is incompatible with the formatter unless `ISC001` is enabled. We recommend enabling `ISC001` or setting `allow-multiline=true`.
|
||||||
warning: The `format.indent-style="tab"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
warning: The `format.indent-style="tab"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
||||||
warning: The `flake8-quotes.inline-quotes="single"` option is incompatible with the formatter's `format.quote-style="double"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `"single"` or `"double"`.
|
warning: The `flake8-quotes.inline-quotes="single"` option is incompatible with the formatter's `format.quote-style="double"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `"single"` or `"double"`.
|
||||||
warning: 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"`.`
|
warning: 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"`.`
|
||||||
|
@ -974,7 +978,7 @@ def say_hy(name: str):
|
||||||
print(f"Hy {name}")
|
print(f"Hy {name}")
|
||||||
|
|
||||||
----- stderr -----
|
----- stderr -----
|
||||||
warning: The following rules may cause conflicts when used with the formatter: `COM812`, `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.
|
warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration.
|
||||||
warning: The `format.indent-style="tab"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
warning: The `format.indent-style="tab"` option is incompatible with `W191`, which lints against all uses of tabs. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
||||||
warning: The `format.indent-style="tab"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
warning: The `format.indent-style="tab"` option is incompatible with `D206`, with requires space-based indentation. We recommend disabling these rules when using the formatter, which enforces a consistent indentation style. Alternatively, set the `format.indent-style` option to `"space"`.
|
||||||
warning: The `flake8-quotes.inline-quotes="single"` option is incompatible with the formatter's `format.quote-style="double"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `"single"` or `"double"`.
|
warning: The `flake8-quotes.inline-quotes="single"` option is incompatible with the formatter's `format.quote-style="double"`. We recommend disabling `Q000` and `Q003` when using the formatter, which enforces a consistent quote style. Alternatively, set both options to either `"single"` or `"double"`.
|
||||||
|
@ -1114,7 +1118,7 @@ def say_hy(name: str):
|
||||||
----- stderr -----
|
----- stderr -----
|
||||||
warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
|
warning: `incorrect-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `incorrect-blank-line-before-class`.
|
||||||
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
|
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
|
||||||
warning: The following rules may cause conflicts when used with the formatter: `COM812`, `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.
|
warning: The following rule may cause conflicts when used with the formatter: `COM812`. To avoid unexpected behavior, we recommend disabling this rule, either by removing it from the `select` or `extend-select` configuration, or adding it to the `ignore` configuration.
|
||||||
");
|
");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,21 +34,6 @@ use crate::Locator;
|
||||||
/// ```python
|
/// ```python
|
||||||
/// z = "The quick brown fox."
|
/// z = "The quick brown fox."
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// # Formatter compatibility
|
|
||||||
/// Use of this rule alongside the [formatter] must be handled with care.
|
|
||||||
/// Currently, the [formatter] can introduce new single-line implicitly
|
|
||||||
/// concatenated strings, therefore we suggest rerunning the linter and
|
|
||||||
/// [formatter] in the following order:
|
|
||||||
/// 1. Run the linter with this rule (`ISC001`) disabled
|
|
||||||
/// 2. Run the [formatter]
|
|
||||||
/// 3. Rerun the linter with this rule (`ISC001`) enabled
|
|
||||||
///
|
|
||||||
/// This is one of very few cases where the [formatter] can produce code that
|
|
||||||
/// contains lint violations. It is a known issue that should be resolved by the
|
|
||||||
/// new 2025 style guide.
|
|
||||||
///
|
|
||||||
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
|
||||||
#[derive(ViolationMetadata)]
|
#[derive(ViolationMetadata)]
|
||||||
pub(crate) struct SingleLineImplicitStringConcatenation;
|
pub(crate) struct SingleLineImplicitStringConcatenation;
|
||||||
|
|
||||||
|
@ -96,19 +81,13 @@ impl Violation for SingleLineImplicitStringConcatenation {
|
||||||
/// ## Options
|
/// ## Options
|
||||||
/// - `lint.flake8-implicit-str-concat.allow-multiline`
|
/// - `lint.flake8-implicit-str-concat.allow-multiline`
|
||||||
///
|
///
|
||||||
/// # Formatter compatibility
|
/// ## Formatter compatibility
|
||||||
/// Use of this rule alongside the [formatter] must be handled with care.
|
/// Using this rule with `allow-multiline = false` can be incompatible with the
|
||||||
/// Currently, the [formatter] can introduce new multi-line implicitly
|
/// formatter because the [formatter] can introduce new multi-line implicitly
|
||||||
/// concatenated strings, therefore we suggest rerunning the linter and
|
/// concatenated strings. We recommend to either:
|
||||||
/// [formatter] in the following order:
|
|
||||||
///
|
///
|
||||||
/// 1. Run the linter with this rule (`ISC002`) disabled
|
/// * Enable `ISC001` to disallow all implicit concatenated strings
|
||||||
/// 2. Run the [formatter]
|
/// * Setting `allow-multiline = true`
|
||||||
/// 3. Rerun the linter with this rule (`ISC002`) enabled
|
|
||||||
///
|
|
||||||
/// This is one of very few cases where the [formatter] can produce code that
|
|
||||||
/// contains lint violations. It is a known issue that should be resolved by the
|
|
||||||
/// new 2025 style guide.
|
|
||||||
///
|
///
|
||||||
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
|
/// [PEP 8]: https://peps.python.org/pep-0008/#maximum-line-length
|
||||||
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
||||||
|
|
|
@ -330,8 +330,7 @@ When using Ruff as a formatter, we recommend avoiding the following lint rules:
|
||||||
- [`avoidable-escaped-quote`](rules/avoidable-escaped-quote.md) (`Q003`)
|
- [`avoidable-escaped-quote`](rules/avoidable-escaped-quote.md) (`Q003`)
|
||||||
- [`missing-trailing-comma`](rules/missing-trailing-comma.md) (`COM812`)
|
- [`missing-trailing-comma`](rules/missing-trailing-comma.md) (`COM812`)
|
||||||
- [`prohibited-trailing-comma`](rules/prohibited-trailing-comma.md) (`COM819`)
|
- [`prohibited-trailing-comma`](rules/prohibited-trailing-comma.md) (`COM819`)
|
||||||
- [`single-line-implicit-string-concatenation`](rules/single-line-implicit-string-concatenation.md) (`ISC001`)
|
- [`multi-line-implicit-string-concatenation`](rules/multi-line-implicit-string-concatenation.md) (`ISC002`) if used without `ISC001` and `flake8-implicit-str-concat.allow-multiline = false`
|
||||||
- [`multi-line-implicit-string-concatenation`](rules/multi-line-implicit-string-concatenation.md) (`ISC002`)
|
|
||||||
|
|
||||||
While the [`line-too-long`](rules/line-too-long.md) (`E501`) rule _can_ be used alongside the
|
While the [`line-too-long`](rules/line-too-long.md) (`E501`) rule _can_ be used alongside the
|
||||||
formatter, the formatter only makes a best-effort attempt to wrap lines at the configured
|
formatter, the formatter only makes a best-effort attempt to wrap lines at the configured
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue