Skip to content

Duplicate E712 diagnostics #17582

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

Closed
whiskeyboy9 opened this issue Apr 23, 2025 · 3 comments · Fixed by #17651
Closed

Duplicate E712 diagnostics #17582

whiskeyboy9 opened this issue Apr 23, 2025 · 3 comments · Fixed by #17651
Labels
rule Implementing or modifying a lint rule

Comments

@whiskeyboy9
Copy link

whiskeyboy9 commented Apr 23, 2025

Duplicate diagnostics for RUF001 in VS Code

Describe the bug
I am seeing the same diagnostic reported twice in the VS Code "Problems" tab when using the Ruff extension. Specifically, the RUF001: Avoid equality comparisons to True; use is True for truth checks error appears two times for the same line of code.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a Python project using Poetry.
  2. Add ruff to the development dependencies (poetry add ruff@latest --group dev).
  3. Ensure the Ruff VS Code extension is installed and enabled.
  4. Create a Python file with code that triggers the RUF001 rule, e.g., if variable == True:.
  5. Open the file in VS Code.
  6. Observe the "Problems" tab where the RUF001 diagnostic is listed twice for the same location.

Expected behavior
I would expect the diagnostic for the RUF001 error to appear only once in the "Problems" tab.

Screenshots
Image showing duplicated errors

Environment

  • VS Code:
    Version: 1.99.3 (user setup)
    Commit: 17baf841131aa23349f217ca7c570c76ee87b957
    Date: 2025-04-15T23:18:46.076Z (1 wk ago)
    Electron: 34.3.2
    ElectronBuildId: 11161073
    Chromium: 132.0.6834.210
    Node.js: 20.18.3
    V8: 13.2.152.41-electron.0
    OS: Windows_NT x64 10.0.19045
    
  • Ruff VS Code Extension:
    Installation
    Identifier: charliermarsh.ruff
    Version: 2025.22.0
    Last Updated: 2025-04-23, 13:33:23
    Size: 33.03MB
    
  • Ruff Version (from log): 0.11.6
  • Python Version (from log interpreter path): Likely 3.11 (based on environment setup with poetry and python = "^3.11")
  • Package Manager: Poetry

Relevant Configuration

.venv\Scripts\python.exe

pyproject.toml:

[tool.poetry]
name = "test_cicd"
version = "0.0.1"
description = "testing cicd pipelines"
authors = [""]
readme = "README.md"
packages = [{include = "dummy", from = "src"}]

[tool.poetry.dependencies]
python = "^3.11"
pydantic = "^2.6.4"
python-dotenv = "^1.0.1"

numpy = "^2.1.1"
pandas = "^2.2.3"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
ipykernel = "^6.29"
pytest = "^8.1"
ruff = "^0.11.6"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = [
  ".", "src",
]

[tool.ruff]
target-version = "py311"
line-length = 120

[tool.ruff.lint] # Add this section
    # select = ["E", "F"]
    # ignore = ["E501"] # Example
    ignore = [
        "E501", # line too long, handled by black
        "B008", # do not perform function calls in argument defaults
        "C901", # too complex
    ]

    select = [
        "E", # pycodestyle errors
        "W", # pycodestyle warnings
        "F", # pyflakes
        "I", # isort
        "C", # flake8-comprehensions
        "B", # flake8-bugbear
        "SIM" # simplify
    ]
@ntBre
Copy link
Contributor

ntBre commented Apr 23, 2025

Thanks for the report! I don't think this is a duplicate diagnostic. You're getting one diagnostic for each True value, but each diagnostic highlights the whole comparison expression. If you had PLR0133 enabled, you'd get a third diagnostic with the same range: https://play.ruff.rs/68219349-d23f-45a8-91b3-1154d97b805f

We could arguably limit the ranges to each True separately, but I think it generally makes sense to mark the whole comparison.

@MichaReiser
Copy link
Member

We could try to be a bit more clever and avoid the second diagnostic if both sides are True?

@ntBre
Copy link
Contributor

ntBre commented Apr 23, 2025

That sounds reasonable to me. I'll transfer this to the ruff repo because it reproduces in the playground and CLI too.

@ntBre ntBre transferred this issue from astral-sh/ruff-vscode Apr 23, 2025
@ntBre ntBre changed the title duplicated diagnostics in ruff - vscode Duplicate E712 diagnostics Apr 23, 2025
@ntBre ntBre added the rule Implementing or modifying a lint rule label Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants