Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff format conflict warnings are shown twice #8271

Closed
yakMM opened this issue Oct 27, 2023 · 11 comments · Fixed by #8292
Closed

Ruff format conflict warnings are shown twice #8271

yakMM opened this issue Oct 27, 2023 · 11 comments · Fixed by #8292
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@yakMM
Copy link

yakMM commented Oct 27, 2023

Happening since ruff format stable was introduced afaik.

Tested on ruff 0.1.3:

Reproduction steps:

Create a python project with ruff, minimal config:

[tool.ruff]
select = ["ISC001"]

Run ruff format src

The warning is showing twice in the console:

warning: The following rules may cause conflicts when used with the formatter: `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.
warning: The following rules may cause conflicts when used with the formatter: `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.
@thernstig
Copy link

thernstig commented Oct 27, 2023

I have the same problem. But for another rule.

> ruff format --check .
warning: The following rules may cause conflicts when used with the formatter: 'D206'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.
warning: The following rules may cause conflicts when used with the formatter: 'D206'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.

(I know I should disable D206 due to, see https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules)

This is my Ruff config:

[tool.ruff]
cache-dir = "/tmp/.cache/ruff"
line-length = 120

# All uncommented lines should be fixed and enabled
select = [
  # These are a copy of the Ruff defaults
  # "F" is Pyflakes, "E" is pycodestyle
  "E4", "E7", "E9", "F",
  "A", # flake8-builtins
  # "B", # flake8-bugbear
  # "C4", # flake8-comprehensions
  "C90", # mccabe
  # "COM", # flake8-commas
  "D", # pydocstyle
  # "FIX", # flake8-fixme
  # "RUF100", # Ruff rule: Enforce that noqa directives are "valid"
  # "S", # flake8-bandit
  "TID", # flake8-tidy-imports
  # "Q", # flake8-quotes
]

# All these ignores should be fixed (except for Q000 which should stay)
ignore = [
  "COM812", # flake8-commas "Trailing comma missing"
  "D10",  # pydocstyle "Missing docstring in ..."
  "D203", # pydocstyle "one-blank-line-before-class" conflicting with D211
  "D205", # pydocstyle "1 blank line required between summary line and description"
  "D208", # pydocstyle "Docstring is over-indented"
  "D209", # pydocstyle "Multi-line docstring closing quotes should be on a separate line"
  "D211", # pydocstyle "no-blank-line-before-class" conflicting with D203
  "D212", # pydocstyle "multi-line-summary-second-line" conflicting with D213
  "D213", # pydocstyle "no-blank-line-before-class" conflicting with D212
  "D400", # pydocstyle "First line should end with a period"
  "D401", # pydocstyle "First line of docstring should be in imperative mood"
  "D404", # pydocstyle "First word of the docstring should not be "This""
  "D403", # pydocstyle "First word of the first line should be capitalized"
  "D407", # pydocstyle "Missing dashed underline after section ("Return")"
  "D415", # pydocstyle "First line should end with a period, question mark, or exclamation point"
  "D419", # pydocstyle "Docstring is empty"
  "E713", # pycodestyle "Test for membership should be `not in`"
  "Q000", # flake8-quotes "Single quotes found but double quotes preferred"
]

[tool.ruff.format]
quote-style = "single"

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Oct 27, 2023
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Oct 27, 2023
@MichaReiser
Copy link
Member

Thanks. I think that happens if you have multiple configurations in your project. We should only show it once.

@thernstig
Copy link

thernstig commented Oct 27, 2023

Thanks. I think that happens if you have multiple configurations in your project. We should only show it once.

@MichaReiser Do you mean multiple .toml files? I only have one, see above.

@MichaReiser
Copy link
Member

@thernstig I would expect this to happen if you have multiple ruff.toml or pyproject.toml. But maybe there's another case where we verify the same configuration twice.

@thernstig
Copy link

Got it, I can confirm I only have one.

@yakMM
Copy link
Author

yakMM commented Oct 27, 2023

@thernstig I would expect this to happen if you have multiple ruff.toml or pyproject.toml. But maybe there's another case where we verify the same configuration twice.

I have one too. Here is a minimal repo reproducing the bug: https://github.com/yakMM/test-double-warning

@charliermarsh charliermarsh self-assigned this Oct 27, 2023
charliermarsh added a commit that referenced this issue Oct 30, 2023
## Summary

Uses `warn_user_once!` instead of `warn!` to ensure that every warning
is shown exactly once, regardless of whether there are duplicates in the
list, or warnings that are raised by multiple configuration files.

Closes #8271.
@tylerlaprade
Copy link
Contributor

This still happens for the --preview warning:
image

@charliermarsh
Copy link
Member

👍 Yeah that's a separate code path and issue.

@AmineDjeghri
Copy link

AmineDjeghri commented May 3, 2024

Edit : i was using an old version of ruff in the pre-commit-config.yaml (0.1.2), i upgraded it to v0.4.2 and the warnings disapeared .

I have the same warning with D206 as @thernstig

warning: The following rules may cause conflicts when used with the formatter: 'D206'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.
warning: The following rules may cause conflicts when used with the formatter: 'D206'. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding then to the `ignore` configuration.

my pre-commit-config.yaml :

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
# ruff is for python files and is used with ruff.toml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.3.0
    hooks:
      - id: check-added-large-files
        args: ['--maxkb=3000']
      - id: check-toml
      - id: check-yaml
      - id: check-json
      - id: detect-private-key
      - id: end-of-file-fixer
      #      - id: requirements-txt-fixer
      #        exclude: ^requirements/.*$
      - id: trailing-whitespace
      - id: name-tests-test
        args: [ --pytest-test-first ]

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.2
    hooks:
      - id: ruff
        args: ['--fix']
      - id: ruff-format

my ruff.toml :

extend-include = ["*.ipynb"]
line-length = 100

# read more here https://docs.astral.sh/ruff/settings/#lintpydocstyle
[lint]
# Enable all `pydocstyle` rules, limiting to those that adhere to the Google convention via `convention = "google"`
select = [
    "D",
]
# On top of the Google convention, disable for ex `D417`, which requires documentation for every function parameter.
ignore = ["D100", "D103", "D417"]

[lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"

@zanieb
Copy link
Member

zanieb commented May 3, 2024

@AmineDjeghri are you just seeing this once for the linter and once for the formatter? Those pre-commit runs are fully separate from our perspective.

@AmineDjeghri
Copy link

AmineDjeghri commented May 3, 2024

it's fixed in the latest version v0.4.2 !
In my pre-commit-config.yaml, i forgot to update ruff . I was still using the 0.1.2 since i've copied the file from an old project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants