ruff/crates/ruff_linter/resources/test/fixtures/pydocstyle/D403.py
my1e5 d3f51cf3a6
[pydocstyle] Split on first whitespace character (D403) (#15082)
## 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
8d0cdfc93e/src/pydocstyle/checker.py (L581C13-L581C64)

## Example

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

```py
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:
```bash
$ 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.
2024-12-20 12:55:50 -06:00

89 lines
No EOL
1.4 KiB
Python

def bad_function():
"""this docstring is not capitalized"""
def good_function():
"""This docstring is capitalized."""
def other_function():
"""
This docstring is capitalized."""
def another_function():
""" This docstring is capitalized."""
def utf8_function():
"""éste docstring is capitalized."""
def uppercase_char_not_possible():
"""'args' is not capitalized."""
def non_alphabetic():
"""th!is is not capitalized."""
def non_ascii():
"""th•s is not capitalized."""
def all_caps():
"""th•s is not capitalized."""
def single_word():
"""singleword."""
def single_word_no_dot():
"""singleword"""
def first_word_lots_of_whitespace():
"""
here is the start of my docstring!
What do you think?
"""
def single_word_newline():
"""singleword
"""
def single_word_dot_newline():
"""singleword.
"""
def single_word_second_line():
"""
singleword
"""
def single_word_dot_second_line():
"""
singleword.
"""
def single_word_then_more_text():
"""singleword
This is more text.
"""
def single_word_dot_then_more_text():
"""singleword.
This is more text.
"""
def single_word_second_line_then_more_text():
"""
singleword
This is more text.
"""
def single_word_dot_second_line_then_more_text():
"""
singleword.
This is more text.
"""