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

Unexpected changes occur when fixing D208 and D209 on the same line #13260

Closed
kubotty opened this issue Sep 6, 2024 · 4 comments
Closed

Unexpected changes occur when fixing D208 and D209 on the same line #13260

kubotty opened this issue Sep 6, 2024 · 4 comments
Assignees
Labels
bug Something isn't working docstring Related to docstring linting or formatting help wanted Contributions especially welcome rule Implementing or modifying a lint rule

Comments

@kubotty
Copy link

kubotty commented Sep 6, 2024

When ruff fixes both D208 (over-indentation) and D209 (new-line-after-last-paragraph) on the same line, it results in unexpected changes.
I share the minimum test case.

Target code:

def test_func(a: int) -> None:
    """Minimum test case.

    Parameters
    ----------
    a : int
        A parameter."""
    pass

Settings in pyproject.toml:

[tool.ruff]
show-fixes = true

[tool.ruff.lint]
select = ["D"]

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

Run above command:

ruff check target.py --fix

Expected results:

def test_func(a: int) -> None:
    """Minimum test case.

    Parameters
    ----------
    a : int
        A parameter.
    """
    pass

but, actual:

def test_func(a: int) -> None:
    """Minimum test case.

    Parameters
    ----------
    a : int
    A parameter.
    """
    pass
@MichaReiser
Copy link
Member

Thanks. I think the issue here is that D208 should not be raised because it also doesn't raise for:

def test_func(a: int) -> None:
    """Minimum test case.

    Parameters
    ----------
    a : int
        A parameter.
    """
    pass

@MichaReiser MichaReiser added bug Something isn't working rule Implementing or modifying a lint rule help wanted Contributions especially welcome labels Sep 6, 2024
@AlexWaygood AlexWaygood added the docstring Related to docstring linting or formatting label Sep 6, 2024
@kubotty
Copy link
Author

kubotty commented Sep 11, 2024

I added this sentence to pyproject.toml as a temporary solution in my project.

[tool.ruff.lint]
unfixable = [
    "D208",
]

I suggest treating D208 as "--unsafe-fixes".

@ukyen8
Copy link
Contributor

ukyen8 commented Sep 14, 2024

Hi, I would like to work on this if no one has taken it.

@dhruvmanila
Copy link
Member

@MichaReiser I'm closing this issue considering #13372 is merged but if that only solves a part of this issue, feel free to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docstring Related to docstring linting or formatting help wanted Contributions especially welcome rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

5 participants