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

[pydocstyle] Split on first whitespace character (D403) #15082

Merged
merged 2 commits into from
Dec 20, 2024

Conversation

my1e5
Copy link
Contributor

@my1e5 my1e5 commented Dec 20, 2024

Summary

This PR fixes an issue where Ruff's D403 rule (first-word-uncapitalized) was not detecting some single-word edge cases that are picked up by pydocstyle.

The change involves extracting the first word of the docstring by identifying the first whitespace character. This is consistent with pydocstyle which uses .split() - see https://github.com/PyCQA/pydocstyle/blob/8d0cdfc93e86e096bb5753f07dc5c7c373e63837/src/pydocstyle/checker.py#L581C13-L581C64

Example

Here is a playground example - https://play.ruff.rs/eab9ea59-92cf-4e44-b1a9-b54b7f69b178

def example1():
    """foo"""

def example2():
    """foo
    
    Hello world!
    """

def example3():
    """foo bar

    Hello world!
    """

def example4():
    """
    foo
    """

def example5():
    """
    foo bar
    """

pydocstyle detects all five cases:

$ pydocstyle test.py --select D403
dev/test.py:2 in public function `example1`:
        D403: First word of the first line should be properly capitalized ('Foo', not 'foo')
dev/test.py:5 in public function `example2`:
        D403: First word of the first line should be properly capitalized ('Foo', not 'foo')
dev/test.py:11 in public function `example3`:
        D403: First word of the first line should be properly capitalized ('Foo', not 'foo')
dev/test.py:17 in public function `example4`:
        D403: First word of the first line should be properly capitalized ('Foo', not 'foo')
dev/test.py:22 in public function `example5`:
        D403: First word of the first line should be properly capitalized ('Foo', not 'foo')

Ruff (0.8.4) fails to catch example2 and example4.

Test Plan

  • Added two new test cases to cover the previously missed single-word docstring cases.

@MichaReiser MichaReiser requested a review from dylwil3 December 20, 2024 14:47
Copy link
Contributor

github-actions bot commented Dec 20, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@my1e5
Copy link
Contributor Author

my1e5 commented Dec 20, 2024

Closes #13167

Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! This looks good to me, thank you for your contribution!

@my1e5 my1e5 requested a review from dylwil3 December 20, 2024 17:08
@dylwil3
Copy link
Collaborator

dylwil3 commented Dec 20, 2024

Wonderful, thanks so much for your contribution!

@dylwil3 dylwil3 merged commit d3f51cf into astral-sh:main Dec 20, 2024
21 checks passed
@dylwil3 dylwil3 added the rule Implementing or modifying a lint rule label Dec 20, 2024
@my1e5 my1e5 deleted the d403-split-on-whitespace branch December 20, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants