Skip to content

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

Description

@kubotty

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

Activity

  1. MichaReiser commented on Sep 6, 2024

    @MichaReiser
    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
  2. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    ruleImplementing or modifying a lint rule
    help wantedContributions especially welcome
    on Sep 6, 2024
  3. added
    docstringRelated to docstring linting, formatting, or rendering in Ruff or ty
    on Sep 6, 2024
  4. kubotty commented on Sep 11, 2024

    @kubotty
    Author

    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".

  5. ukyen8 commented on Sep 14, 2024

    @ukyen8
    Contributor

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

  6. dhruvmanila commented on Oct 3, 2024

    @dhruvmanila
    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

Metadata

Metadata

Assignees

Labels

bugAn issue describing something that isn't working, or a PR that fixes a bugdocstringRelated to docstring linting, formatting, or rendering in Ruff or tyhelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions