-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) ## Summary Add a setting to allow ignoring one line docstrings for the pydoclint rules. Resolves #13086 Part of #12434 ## Test Plan Run tests with setting enabled. --------- Co-authored-by: dylwil3 <dylwil3@gmail.com>
- Loading branch information
1 parent
177bf72
commit e84c824
Showing
10 changed files
with
407 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Settings for the `pydoclint` plugin. | ||
use crate::display_settings; | ||
use ruff_macros::CacheKey; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
#[derive(Debug, Clone, Default, CacheKey)] | ||
pub struct Settings { | ||
pub ignore_one_line_docstrings: bool, | ||
} | ||
|
||
impl Display for Settings { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
display_settings! { | ||
formatter = f, | ||
namespace = "linter.pydoclint", | ||
fields = [self.ignore_one_line_docstrings] | ||
} | ||
Ok(()) | ||
} | ||
} |
159 changes: 159 additions & 0 deletions
159
...ules__pydoclint__tests__docstring-missing-exception_DOC501_google.py_ignore_one_line.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pydoclint/mod.rs | ||
--- | ||
DOC501_google.py:34:5: DOC501 Raised exception `FasterThanLightError` missing from docstring | ||
| | ||
32 | # DOC501 | ||
33 | def calculate_speed(distance: float, time: float) -> float: | ||
34 | / """Calculate speed as distance divided by time. | ||
35 | | | ||
36 | | Args: | ||
37 | | distance: Distance traveled. | ||
38 | | time: Time spent traveling. | ||
39 | | | ||
40 | | Returns: | ||
41 | | Speed as distance divided by time. | ||
42 | | """ | ||
| |_______^ DOC501 | ||
43 | try: | ||
44 | return distance / time | ||
| | ||
= help: Add `FasterThanLightError` to the docstring | ||
|
||
DOC501_google.py:51:5: DOC501 Raised exception `ValueError` missing from docstring | ||
| | ||
49 | # DOC501 | ||
50 | def calculate_speed(distance: float, time: float) -> float: | ||
51 | / """Calculate speed as distance divided by time. | ||
52 | | | ||
53 | | Args: | ||
54 | | distance: Distance traveled. | ||
55 | | time: Time spent traveling. | ||
56 | | | ||
57 | | Returns: | ||
58 | | Speed as distance divided by time. | ||
59 | | """ | ||
| |_______^ DOC501 | ||
60 | try: | ||
61 | return distance / time | ||
| | ||
= help: Add `ValueError` to the docstring | ||
|
||
DOC501_google.py:51:5: DOC501 Raised exception `FasterThanLightError` missing from docstring | ||
| | ||
49 | # DOC501 | ||
50 | def calculate_speed(distance: float, time: float) -> float: | ||
51 | / """Calculate speed as distance divided by time. | ||
52 | | | ||
53 | | Args: | ||
54 | | distance: Distance traveled. | ||
55 | | time: Time spent traveling. | ||
56 | | | ||
57 | | Returns: | ||
58 | | Speed as distance divided by time. | ||
59 | | """ | ||
| |_______^ DOC501 | ||
60 | try: | ||
61 | return distance / time | ||
| | ||
= help: Add `FasterThanLightError` to the docstring | ||
|
||
DOC501_google.py:106:5: DOC501 Raised exception `AnotherError` missing from docstring | ||
| | ||
104 | # DOC501 | ||
105 | def calculate_speed(distance: float, time: float) -> float: | ||
106 | / """Calculate speed as distance divided by time. | ||
107 | | | ||
108 | | Args: | ||
109 | | distance: Distance traveled. | ||
110 | | time: Time spent traveling. | ||
111 | | | ||
112 | | Returns: | ||
113 | | Speed as distance divided by time. | ||
114 | | """ | ||
| |_______^ DOC501 | ||
115 | raise AnotherError | ||
| | ||
= help: Add `AnotherError` to the docstring | ||
|
||
DOC501_google.py:120:5: DOC501 Raised exception `AnotherError` missing from docstring | ||
| | ||
118 | # DOC501 | ||
119 | def calculate_speed(distance: float, time: float) -> float: | ||
120 | / """Calculate speed as distance divided by time. | ||
121 | | | ||
122 | | Args: | ||
123 | | distance: Distance traveled. | ||
124 | | time: Time spent traveling. | ||
125 | | | ||
126 | | Returns: | ||
127 | | Speed as distance divided by time. | ||
128 | | """ | ||
| |_______^ DOC501 | ||
129 | raise AnotherError() | ||
| | ||
= help: Add `AnotherError` to the docstring | ||
|
||
DOC501_google.py:134:5: DOC501 Raised exception `SomeError` missing from docstring | ||
| | ||
132 | # DOC501 | ||
133 | def foo(bar: int): | ||
134 | / """Foo. | ||
135 | | | ||
136 | | Args: | ||
137 | | bar: Bar. | ||
138 | | """ | ||
| |_______^ DOC501 | ||
139 | raise something.SomeError | ||
| | ||
= help: Add `SomeError` to the docstring | ||
|
||
DOC501_google.py:197:5: DOC501 Raised exception `ZeroDivisionError` missing from docstring | ||
| | ||
195 | # DOC501 | ||
196 | def calculate_speed(distance: float, time: float) -> float: | ||
197 | / """Calculate speed as distance divided by time. | ||
198 | | | ||
199 | | Args: | ||
200 | | distance: Distance traveled. | ||
201 | | time: Time spent traveling. | ||
202 | | | ||
203 | | Returns: | ||
204 | | Speed as distance divided by time. | ||
205 | | | ||
206 | | Raises: | ||
207 | | TypeError: if you didn't pass a number for both parameters | ||
208 | | """ | ||
| |_______^ DOC501 | ||
209 | try: | ||
210 | return distance / time | ||
| | ||
= help: Add `ZeroDivisionError` to the docstring | ||
|
||
DOC501_google.py:238:5: DOC501 Raised exception `TypeError` missing from docstring | ||
| | ||
237 | def foo(): | ||
238 | / """Foo. | ||
239 | | | ||
240 | | Returns: | ||
241 | | 42: int. | ||
242 | | """ | ||
| |_______^ DOC501 | ||
243 | if True: | ||
244 | raise TypeError # DOC501 | ||
| | ||
= help: Add `TypeError` to the docstring | ||
|
||
DOC501_google.py:238:5: DOC501 Raised exception `ValueError` missing from docstring | ||
| | ||
237 | def foo(): | ||
238 | / """Foo. | ||
239 | | | ||
240 | | Returns: | ||
241 | | 42: int. | ||
242 | | """ | ||
| |_______^ DOC501 | ||
243 | if True: | ||
244 | raise TypeError # DOC501 | ||
| | ||
= help: Add `ValueError` to the docstring |
76 changes: 76 additions & 0 deletions
76
..._rules__pydoclint__tests__docstring-missing-returns_DOC201_google.py_ignore_one_line.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pydoclint/mod.rs | ||
--- | ||
DOC201_google.py:3:5: DOC201 `return` is not documented in docstring | ||
| | ||
1 | # DOC201 | ||
2 | def foo(num: int) -> str: | ||
3 | / """ | ||
4 | | Do something | ||
5 | | | ||
6 | | Args: | ||
7 | | num (int): A number | ||
8 | | """ | ||
| |_______^ DOC201 | ||
9 | return 'test' | ||
| | ||
= help: Add a "Returns" section to the docstring | ||
|
||
DOC201_google.py:44:9: DOC201 `return` is not documented in docstring | ||
| | ||
42 | # DOC201 | ||
43 | def bar(self) -> str: | ||
44 | / """ | ||
45 | | Do something | ||
46 | | | ||
47 | | Args: | ||
48 | | num (int): A number | ||
49 | | """ | ||
| |___________^ DOC201 | ||
50 | return 'test' | ||
| | ||
= help: Add a "Returns" section to the docstring | ||
|
||
DOC201_google.py:178:5: DOC201 `return` is not documented in docstring | ||
| | ||
176 | # DOC201 - non-early return explicit None | ||
177 | def foo(x: int) -> int | None: | ||
178 | / """A very helpful docstring. | ||
179 | | | ||
180 | | Args: | ||
181 | | x (int): An integer. | ||
182 | | """ | ||
| |_______^ DOC201 | ||
183 | if x < 0: | ||
184 | return None | ||
| | ||
= help: Add a "Returns" section to the docstring | ||
|
||
DOC201_google.py:191:5: DOC201 `return` is not documented in docstring | ||
| | ||
189 | # DOC201 - non-early return explicit None w/o useful type annotations | ||
190 | def foo(x): | ||
191 | / """A very helpful docstring. | ||
192 | | | ||
193 | | Args: | ||
194 | | x (int): An integer. | ||
195 | | """ | ||
| |_______^ DOC201 | ||
196 | if x < 0: | ||
197 | return None | ||
| | ||
= help: Add a "Returns" section to the docstring | ||
|
||
DOC201_google.py:204:5: DOC201 `return` is not documented in docstring | ||
| | ||
202 | # DOC201 - only returns None, but return annotation is not None | ||
203 | def foo(s: str) -> str | None: | ||
204 | / """A very helpful docstring. | ||
205 | | | ||
206 | | Args: | ||
207 | | s (str): A string. | ||
208 | | """ | ||
| |_______^ DOC201 | ||
209 | return None | ||
| | ||
= help: Add a "Returns" section to the docstring |
32 changes: 32 additions & 0 deletions
32
...__rules__pydoclint__tests__docstring-missing-yields_DOC402_google.py_ignore_one_line.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/pydoclint/mod.rs | ||
--- | ||
DOC402_google.py:3:5: DOC402 `yield` is not documented in docstring | ||
| | ||
1 | # DOC402 | ||
2 | def foo(num: int) -> str: | ||
3 | / """ | ||
4 | | Do something | ||
5 | | | ||
6 | | Args: | ||
7 | | num (int): A number | ||
8 | | """ | ||
| |_______^ DOC402 | ||
9 | yield 'test' | ||
| | ||
= help: Add a "Yields" section to the docstring | ||
|
||
DOC402_google.py:44:9: DOC402 `yield` is not documented in docstring | ||
| | ||
42 | # DOC402 | ||
43 | def bar(self) -> str: | ||
44 | / """ | ||
45 | | Do something | ||
46 | | | ||
47 | | Args: | ||
48 | | num (int): A number | ||
49 | | """ | ||
| |___________^ DOC402 | ||
50 | yield 'test' | ||
| | ||
= help: Add a "Yields" section to the docstring |
Oops, something went wrong.