Skip to content

Commit

Permalink
Fix condition
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 8, 2024
1 parent 247539b commit c53fdb0
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 14 deletions.
8 changes: 2 additions & 6 deletions crates/ruff_linter/src/docstrings/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn is_docstring_section(
// args: The arguments to the function.
// """
// ```
// or if the style uses Numpy convention and argument name is the same as the section name and argument type is not specified:
// Or `parameters` in:
// ```python
// def func(parameters: tuple[int]):
// """Toggle the gizmo.
Expand All @@ -474,15 +474,11 @@ fn is_docstring_section(
// continue to treat it as a section header.
if let Some(previous_section) = previous_section {
let verbatim = &line[TextRange::at(indent_size, section_name_size)];
if previous_section.indent_size < indent_size {
if previous_section.kind == section_kind || previous_section.indent_size < indent_size {
if section_kind.as_str() != verbatim {
return false;
}
}
// sub-section header should be lower case
if verbatim.chars().next().map(char::is_lowercase).is_some() {
return false;
}
}

true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,27 @@ sections.py:144:5: D214 [*] Section is over-indented ("Returns")
148 148 | A value of some sort.
149 149 |

sections.py:589:5: D214 [*] Section is over-indented ("Returns")
|
588 | def titlecase_sub_section_header():
589 | """Below, `Returns:` should be considered a section header.
| _____^
590 | |
591 | | Args:
592 | | Here's a note.
593 | |
594 | | Returns:
595 | | """
| |_______^ D214
|
= help: Remove over-indentation from "Returns"

Safe fix
591 591 | Args:
592 592 | Here's a note.
593 593 |
594 |- Returns:
594 |+ Returns:
595 595 | """
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ sections.py:30:5: D406 [*] Section name should end with a newline ("Returns")
34 34 | A value of some sort.
35 35 |

sections.py:216:5: D406 [*] Section name should end with a newline ("Raises")
|
214 | @expect("D407: Missing dashed underline after section ('Raises')")
215 | def multiple_sections(): # noqa: D416
216 | """Toggle the gizmo.
| _____^
217 | |
218 | | Short summary
219 | | -------------
220 | |
221 | | This is the function's description, which will also specify what it
222 | | returns.
223 | |
224 | | Returns
225 | | ------
226 | | Many many wonderful things.
227 | | Raises:
228 | | My attention.
229 | |
230 | | """
| |_______^ D406
|
= help: Add newline after "Raises"

ℹ Safe fix
224 224 | Returns
225 225 | ------
226 226 | Many many wonderful things.
227 |- Raises:
227 |+ Raises
228 228 | My attention.
229 229 |
230 230 | """

sections.py:512:9: D406 [*] Section name should end with a newline ("Parameters")
|
510 | @staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,39 @@ sections.py:65:5: D407 [*] Missing dashed underline after section ("Returns")
69 70 |
70 71 | @expect(_D213)

sections.py:216:5: D407 [*] Missing dashed underline after section ("Raises")
|
214 | @expect("D407: Missing dashed underline after section ('Raises')")
215 | def multiple_sections(): # noqa: D416
216 | """Toggle the gizmo.
| _____^
217 | |
218 | | Short summary
219 | | -------------
220 | |
221 | | This is the function's description, which will also specify what it
222 | | returns.
223 | |
224 | | Returns
225 | | ------
226 | | Many many wonderful things.
227 | | Raises:
228 | | My attention.
229 | |
230 | | """
| |_______^ D407
|
= help: Add dashed line under "Raises"

ℹ Safe fix
225 225 | ------
226 226 | Many many wonderful things.
227 227 | Raises:
228 |+ ------
228 229 | My attention.
229 230 |
230 231 | """

sections.py:261:5: D407 [*] Missing dashed underline after section ("Args")
|
259 | @expect("D414: Section has no content ('Returns')")
Expand Down Expand Up @@ -100,6 +133,64 @@ sections.py:261:5: D407 [*] Missing dashed underline after section ("Args")
265 266 |
266 267 | Returns:

sections.py:261:5: D407 [*] Missing dashed underline after section ("Returns")
|
259 | @expect("D414: Section has no content ('Returns')")
260 | def valid_google_style_section(): # noqa: D406, D407
261 | """Toggle the gizmo.
| _____^
262 | |
263 | | Args:
264 | | note: A random string.
265 | |
266 | | Returns:
267 | |
268 | | Raises:
269 | | RandomError: A random error that occurs randomly.
270 | |
271 | | """
| |_______^ D407
|
= help: Add dashed line under "Returns"

ℹ Safe fix
264 264 | note: A random string.
265 265 |
266 266 | Returns:
267 |+ -------
267 268 |
268 269 | Raises:
269 270 | RandomError: A random error that occurs randomly.

sections.py:261:5: D407 [*] Missing dashed underline after section ("Raises")
|
259 | @expect("D414: Section has no content ('Returns')")
260 | def valid_google_style_section(): # noqa: D406, D407
261 | """Toggle the gizmo.
| _____^
262 | |
263 | | Args:
264 | | note: A random string.
265 | |
266 | | Returns:
267 | |
268 | | Raises:
269 | | RandomError: A random error that occurs randomly.
270 | |
271 | | """
| |_______^ D407
|
= help: Add dashed line under "Raises"

ℹ Safe fix
266 266 | Returns:
267 267 |
268 268 | Raises:
269 |+ ------
269 270 | RandomError: A random error that occurs randomly.
270 271 |
271 272 | """

sections.py:278:5: D407 [*] Missing dashed underline after section ("Args")
|
276 | "('Args:', not 'Args')")
Expand Down Expand Up @@ -455,4 +546,26 @@ sections.py:589:5: D407 [*] Missing dashed underline after section ("Args")
593 594 |
594 595 | Returns:

sections.py:589:5: D407 [*] Missing dashed underline after section ("Returns")
|
588 | def titlecase_sub_section_header():
589 | """Below, `Returns:` should be considered a section header.
| _____^
590 | |
591 | | Args:
592 | | Here's a note.
593 | |
594 | | Returns:
595 | | """
| |_______^ D407
|
= help: Add dashed line under "Returns"

ℹ Safe fix
592 592 | Here's a note.
593 593 |
594 594 | Returns:
595 |+ -------
595 596 | """


Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,37 @@ sections.py:76:5: D410 [*] Missing blank line after section ("Returns")
81 82 | ------
82 83 |

sections.py:216:5: D410 [*] Missing blank line after section ("Returns")
|
214 | @expect("D407: Missing dashed underline after section ('Raises')")
215 | def multiple_sections(): # noqa: D416
216 | """Toggle the gizmo.
| _____^
217 | |
218 | | Short summary
219 | | -------------
220 | |
221 | | This is the function's description, which will also specify what it
222 | | returns.
223 | |
224 | | Returns
225 | | ------
226 | | Many many wonderful things.
227 | | Raises:
228 | | My attention.
229 | |
230 | | """
| |_______^ D410
|
= help: Add blank line after "Returns"

ℹ Safe fix
224 224 | Returns
225 225 | ------
226 226 | Many many wonderful things.
227 |+
227 228 | Raises:
228 229 | My attention.
229 230 |


Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,37 @@ sections.py:131:5: D411 [*] Missing blank line before section ("Returns")
135 136 | -------
136 137 | A value of some sort.

sections.py:216:5: D411 [*] Missing blank line before section ("Raises")
|
214 | @expect("D407: Missing dashed underline after section ('Raises')")
215 | def multiple_sections(): # noqa: D416
216 | """Toggle the gizmo.
| _____^
217 | |
218 | | Short summary
219 | | -------------
220 | |
221 | | This is the function's description, which will also specify what it
222 | | returns.
223 | |
224 | | Returns
225 | | ------
226 | | Many many wonderful things.
227 | | Raises:
228 | | My attention.
229 | |
230 | | """
| |_______^ D411
|
= help: Add blank line before "Raises"

ℹ Safe fix
224 224 | Returns
225 225 | ------
226 226 | Many many wonderful things.
227 |+
227 228 | Raises:
228 229 | My attention.
229 230 |


Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pydocstyle/mod.rs
---
D413.py:1:1: D413 [*] Missing blank line after last section ("Args")
D413.py:1:1: D413 [*] Missing blank line after last section ("Returns")
|
1 | / """Do something.
2 | |
Expand All @@ -14,7 +14,7 @@ D413.py:1:1: D413 [*] Missing blank line after last section ("Args")
9 | | """
| |___^ D413
|
= help: Add blank line after "Args"
= help: Add blank line after "Returns"

Safe fix
6 6 |
Expand All @@ -26,7 +26,7 @@ D413.py:1:1: D413 [*] Missing blank line after last section ("Args")
10 12 |
11 13 |

D413.py:13:5: D413 [*] Missing blank line after last section ("Args")
D413.py:13:5: D413 [*] Missing blank line after last section ("Returns")
|
12 | def func():
13 | """Do something.
Expand All @@ -41,7 +41,7 @@ D413.py:13:5: D413 [*] Missing blank line after last section ("Args")
21 | | """
| |_______^ D413
|
= help: Add blank line after "Args"
= help: Add blank line after "Returns"

Safe fix
18 18 |
Expand All @@ -52,7 +52,7 @@ D413.py:13:5: D413 [*] Missing blank line after last section ("Args")
22 23 |
23 24 |

D413.py:52:5: D413 [*] Missing blank line after last section ("Args")
D413.py:52:5: D413 [*] Missing blank line after last section ("Returns")
|
51 | def func():
52 | """Do something.
Expand All @@ -66,7 +66,7 @@ D413.py:52:5: D413 [*] Missing blank line after last section ("Args")
59 | | the value"""
| |____________________^ D413
|
= help: Add blank line after "Args"
= help: Add blank line after "Returns"

Safe fix
56 56 | with a hanging indent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ sections.py:579:5: D413 [*] Missing blank line after last section ("Args")
586 587 |
587 588 |

sections.py:589:5: D413 [*] Missing blank line after last section ("Args")
sections.py:589:5: D413 [*] Missing blank line after last section ("Returns")
|
588 | def titlecase_sub_section_header():
589 | """Below, `Returns:` should be considered a section header.
Expand All @@ -180,7 +180,7 @@ sections.py:589:5: D413 [*] Missing blank line after last section ("Args")
595 | | """
| |_______^ D413
|
= help: Add blank line after "Args"
= help: Add blank line after "Returns"

Safe fix
592 592 | Here's a note.
Expand Down
Loading

0 comments on commit c53fdb0

Please sign in to comment.