mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-29 03:02:14 +00:00
Refine the warnings about incompatible linter options (#8196)
## Summary Avoid warning about incompatible rules except if their configuration directly conflicts with the formatter. This should reduce the noise and potentially the need for https://github.com/astral-sh/ruff/issues/8175 and https://github.com/astral-sh/ruff/issues/8185 I also extended the rule and option documentation to mention any potential formatter incompatibilities or whether they're redundant when using the formatter. * `LineTooLong`: This is a use case we explicitly want to support. Don't warn about it * `TabIndentation`, `IndentWithSpaces`: Only warn if `indent-style="tab"` * `IndentationWithInvalidMultiple`, `IndentationWithInvalidMultipleComment`: Only warn if `indent-width != 4` * `OverIndented`: Don't warn, but mention that the rule is redundant * `BadQuotesInlineString`: Warn if quote setting is different from `format.quote-style` * `BadQuotesMultilineString`, `BadQuotesDocstring`: Warn if `quote != "double"` ## Test Plan I added a new integration test for the default configuration with `ALL`. `ruff format` now only shows two incompatible rules, which feels more reasonable.
This commit is contained in:
parent
be3307e9a6
commit
a4dd1e5fad
9 changed files with 247 additions and 49 deletions
|
|
@ -27,6 +27,13 @@ use crate::settings::LinterSettings;
|
|||
/// ```python
|
||||
/// foo = "bar's"
|
||||
/// ```
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter automatically removes unnecessary escapes, making the rule
|
||||
/// redundant.
|
||||
///
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct AvoidableEscapedQuote;
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,13 @@ use super::super::settings::Quote;
|
|||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.inline-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent quotes for inline strings, making the rule
|
||||
/// redundant.
|
||||
///
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct BadQuotesInlineString {
|
||||
preferred_quote: Quote,
|
||||
|
|
@ -81,6 +88,13 @@ impl AlwaysFixableViolation for BadQuotesInlineString {
|
|||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.multiline-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces double quotes for multiline strings, making the rule
|
||||
/// redundant.
|
||||
///
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct BadQuotesMultilineString {
|
||||
preferred_quote: Quote,
|
||||
|
|
@ -129,6 +143,13 @@ impl AlwaysFixableViolation for BadQuotesMultilineString {
|
|||
///
|
||||
/// ## Options
|
||||
/// - `flake8-quotes.docstring-quotes`
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces double quotes for docstrings, making the rule
|
||||
/// redundant.
|
||||
///
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct BadQuotesDocstring {
|
||||
preferred_quote: Quote,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,16 @@ use super::LogicalLine;
|
|||
/// a = 1
|
||||
/// ```
|
||||
///
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent indentation, making the rule redundant.
|
||||
///
|
||||
/// The rule is also incompatible with the [formatter] when using
|
||||
/// `indent-width` with a value other than `4`.
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#indentation
|
||||
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
||||
#[violation]
|
||||
pub struct IndentationWithInvalidMultiple {
|
||||
indent_size: usize,
|
||||
|
|
@ -55,7 +64,15 @@ impl Violation for IndentationWithInvalidMultiple {
|
|||
/// # a = 1
|
||||
/// ```
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent indentation, making the rule redundant.
|
||||
///
|
||||
/// The rule is also incompatible with the [formatter] when using
|
||||
/// `indent-width` with a value other than `4`.
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#indentation
|
||||
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
||||
#[violation]
|
||||
pub struct IndentationWithInvalidMultipleComment {
|
||||
indent_size: usize,
|
||||
|
|
|
|||
|
|
@ -26,7 +26,15 @@ use ruff_text_size::{TextLen, TextRange, TextSize};
|
|||
/// a = 1
|
||||
/// ```
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent indentation, making the rule redundant.
|
||||
///
|
||||
/// The rule is also incompatible with the [formatter] when using
|
||||
/// `format.indent-style="tab"`.
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct TabIndentation;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ use crate::registry::Rule;
|
|||
/// Checks for docstrings that are indented with tabs.
|
||||
///
|
||||
/// ## Why is this bad?
|
||||
/// [PEP 8](https://peps.python.org/pep-0008/#tabs-or-spaces) recommends using
|
||||
/// spaces over tabs for indentation.
|
||||
///
|
||||
/// [PEP 8] recommends using spaces over tabs for indentation.
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
|
|
@ -38,10 +36,20 @@ use crate::registry::Rule;
|
|||
/// """
|
||||
/// ```
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent indentation, making the rule redundant.
|
||||
///
|
||||
/// The rule is also incompatible with the [formatter] when using
|
||||
/// `format.indent-style="tab"`.
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
|
||||
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
|
||||
///
|
||||
/// [PEP 8]: https://peps.python.org/pep-0008/#tabs-or-spaces
|
||||
/// [formatter]: https://docs.astral.sh/ruff/formatter
|
||||
#[violation]
|
||||
pub struct IndentWithSpaces;
|
||||
|
||||
|
|
@ -126,12 +134,17 @@ impl AlwaysFixableViolation for UnderIndentation {
|
|||
/// """
|
||||
/// ```
|
||||
///
|
||||
/// ## Formatter compatibility
|
||||
/// We recommend against using this rule alongside the [formatter]. The
|
||||
/// formatter enforces consistent indentation, making the rule redundant.
|
||||
///
|
||||
/// ## References
|
||||
/// - [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257/)
|
||||
/// - [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)
|
||||
/// - [Google Python Style Guide - Docstrings](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings)
|
||||
///
|
||||
/// [PEP 257]: https://peps.python.org/pep-0257/
|
||||
/// [formatter]:https://docs.astral.sh/ruff/formatter/
|
||||
#[violation]
|
||||
pub struct OverIndentation;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue