Skip to content

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

@antolu

Description

@antolu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcomepreviewRelated to preview mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions