Skip to content

ruff check --fix isort rule I001 removes comments #12487

@kfot

Description

@kfot

ruff check --fix will remove the comment in such situation while it shouldn't be affected

image

Snippet:

class Transaction(object):
    """Implements the Transaction class."""

    def __init__(self, client, test_mode=False):
        from mylib import (
            MyClient,
            MyMgmtClient,
        )  # some comment

        ....

Pyproject:

[tool.ruff]
extend-include = ["*.ipynb"]
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]

line-length = 120

[tool.ruff.lint.isort]
known-first-party = ["mylib"]


[tool.ruff.lint]
select = [
    "A",  # prevent using keywords that clobber python builtins
    "B",  # bugbear: security warnings
    "D", # pydocstyle
    "I",  # isort
    "E",  # pycodestyle
    "F",  # pyflakes
    "ISC",  # implicit string concatenation
    "RUF",  # the ruff developer's own rules
]

ignore = [
    "B904",  # raise-without-from-inside-except: syntax not compatible with py2
    "D100", # Missing docstring in public module
    "D101", # Missing docstring in public class
    "D102", #  Missing docstring in public method
    "D103", #  Missing docstring in public function
    "D104", #  Missing docstring in public package
    "D105", # Missing docstring in magic method
    "E731",  # lambda-assignment: lambdas are substential in maintenance of py2/3 codebase
    "ISC001",  # conflicts with ruff format command
    "RUF005",  # collection-literal-concatenation: syntax not compatible with py2
    "RUF012", # mutable-class-default: typing is not available for py2
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"

Version
ruff 0.5.2

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingisortRelated to import sorting

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions