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

E203: Incompatible with formatter when closing ] is on its own line #10973

Closed
antolu opened this issue Apr 15, 2024 · 9 comments
Closed

E203: Incompatible with formatter when closing ] is on its own line #10973

antolu opened this issue Apr 15, 2024 · 9 comments
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features

Comments

@antolu
Copy link

antolu commented Apr 15, 2024

Ruff version: 0.1.7
OS: MacOS / ArchLinux / RHEL
Python: 3.11.5

I put both ruff and ruff format in my pre-commit hooks as follows:

  - repo: https://github.com/charliermarsh/ruff-pre-commit
    rev: "v0.3.7"
    hooks:
      - id: ruff
        args: [--fix, --exit-non-zero-on-fix]
      - id: ruff-format

Ruff config


[tool.ruff]

exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".hg",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "venv",
    ".venv",
    "transformertf/hysteresis"
]

line-length = 88
target-version = "py311"

preview = true
unsafe-fixes = true

[tool.ruff.lint]
# All rules can be found here: https://docs.astral.sh/ruff/rules/
select = [
    "F",   # pyflakes
    "E",   # error  (pycodestyle)
    "W",   # warning (pycodestyle)
    "I",   # isort
    "N",   # naming  (pep8)
    "UP",  # pyupgrade
    "PLC", # convention  (pylint)
    "PLE", # error  (pylint)
    "PLW", # warning  (pylint)
    # "D",  # docstring (pydocstyle),  # not enabled by default
    "PD",   # pandas
    "TRY",  # tryceratops
    "NPY",  # numpy
    "PERF", # perflint
    "RUF",  # ruff
    # v flake8 v
    "B",
    "C4",
    "FBT",
    "A",
    "EM",
    "ISC",
    "FA",
    "G",
    "PIE",
    "PYI",
    "PT",
    "Q",
    "RSE",
    "RET",
    "SLF",
    "SIM",
]
fixable = ["ALL"]
ignore = ["E501", "W505", "ISC001", "PD901", "PLW2901", "N812", "N806", "G004"]

[tool.ruff.format]
preview = true

When running the hooks the check --fix seems to do something that format reverts.
image

Seems to be ruff format wanting to add space before colon:
image
image

@antolu antolu closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@antolu antolu reopened this Apr 15, 2024
@charliermarsh
Copy link
Member

Does ruff check --fix then remove the colon?

@charliermarsh
Copy link
Member

Can you include the full contents of the file needed to reproduce this?

@MichaReiser
Copy link
Member

Note: I haven't been able to reproduce this by pasting the visible code into the playground. https://play.ruff.rs/f218da06-df69-4979-bd30-aea8d1572447

@antolu
Copy link
Author

antolu commented Apr 16, 2024

I was able to reproduce it by putting my code in the playground and putting in some of my settings (even without those, I believe): https://play.ruff.rs/d0579912-6c11-41df-b509-78a79b416881. See line 201

Great tool btw! I think the "share" button does not actually copy the link in Safari though...

@MichaReiser
Copy link
Member

Thank you. That was very helpful!

Okay I think I have a minimal repro. The linter only warns about the whitespace if the closing bracket is on its own line.

https://play.ruff.rs/bc811d2d-2386-4859-a948-dd9682df55e0

@MichaReiser MichaReiser transferred this issue from astral-sh/ruff-pre-commit Apr 16, 2024
@MichaReiser MichaReiser added bug Something isn't working preview Related to preview mode features labels Apr 16, 2024
@MichaReiser MichaReiser changed the title ruff check --fix --preview --unsafe-fixes conflicts with ruff format E203: Incompatible with formatter when closing ] is on its own line Apr 16, 2024
@MichaReiser MichaReiser added the help wanted Contributions especially welcome label Apr 16, 2024
charliermarsh pushed a commit that referenced this issue Jun 8, 2024
## Summary

The fix for E203 now produces the same result as ruff format in cases
where a slice ends on a colon and the closing square bracket is on the
following line.

Refers to #10973

## Test Plan

The minimal reproduction case in the ticket was added as test case
producing no error. Additional cases with multiple spaces or a tab
before the colon where added to make sure that the rule still finds
these.
@dhruvmanila
Copy link
Member

@MichaReiser Is this resolved by #10999 ?

@MichaReiser
Copy link
Member

Yeah I think so. At least it no longer shows up in the playground.

@dhruvmanila
Copy link
Member

Yeah I think so. At least it no longer shows up in the playground.

I don't think the linked PR is released yet unless you're running it locally 😅

@MichaReiser
Copy link
Member

I'm just gonna pretend that I tested it locally... But yes, the error no longer shows locally (but still does on play.ruff)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions especially welcome preview Related to preview mode features
Projects
None yet
Development

No branches or pull requests

4 participants