File tree Expand file tree Collapse file tree 4 files changed +89
-4
lines changed
resources/test/fixtures/pydocstyle Expand file tree Collapse file tree 4 files changed +89
-4
lines changed Original file line number Diff line number Diff line change
1
+ """A module docstring with D214 violations
2
+
3
+ Returns
4
+ -----
5
+ valid returns
6
+
7
+ Args
8
+ -----
9
+ valid args
10
+ """
11
+
12
+ import os
13
+ from .expected import Expectation
14
+
15
+ expectation = Expectation ()
16
+ expect = expectation .expect
17
+
18
+ expect (os .path .normcase (__file__ if __file__ [- 1 ] != 'c' else __file__ [:- 1 ]),
19
+ "D214: Section is over-indented ('Returns')" )
20
+ expect (os .path .normcase (__file__ if __file__ [- 1 ] != 'c' else __file__ [:- 1 ]),
21
+ "D214: Section is over-indented ('Args')" )
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ mod tests {
68
68
#[ test_case( Rule :: UndocumentedPublicPackage , Path :: new( "D104/__init__.py" ) ; "D104_1" ) ]
69
69
#[ test_case( Rule :: SectionNameEndsInColon , Path :: new( "D.py" ) ; "D416" ) ]
70
70
#[ test_case( Rule :: SectionNotOverIndented , Path :: new( "sections.py" ) ; "D214" ) ]
71
+ #[ test_case( Rule :: SectionNotOverIndented , Path :: new( "D214_module.py" ) ; "D214_module" ) ]
71
72
#[ test_case( Rule :: SectionUnderlineAfterName , Path :: new( "sections.py" ) ; "D408" ) ]
72
73
#[ test_case( Rule :: SectionUnderlineMatchesSectionLength , Path :: new( "sections.py" ) ; "D409" ) ]
73
74
#[ test_case( Rule :: SectionUnderlineNotOverIndented , Path :: new( "sections.py" ) ; "D215" ) ]
Original file line number Diff line number Diff line change @@ -619,10 +619,14 @@ fn common_section(
619
619
) ;
620
620
if checker. patch ( diagnostic. kind . rule ( ) ) {
621
621
// Replace the existing indentation with whitespace of the appropriate length.
622
- diagnostic. set_fix ( Edit :: range_replacement (
623
- whitespace:: clean ( docstring. indentation ) ,
624
- TextRange :: at ( context. range ( ) . start ( ) , leading_space. text_len ( ) ) ,
625
- ) ) ;
622
+ let content = whitespace:: clean ( docstring. indentation ) ;
623
+ let fix_range = TextRange :: at ( context. range ( ) . start ( ) , leading_space. text_len ( ) ) ;
624
+
625
+ diagnostic. set_fix ( if content. is_empty ( ) {
626
+ Edit :: range_deletion ( fix_range)
627
+ } else {
628
+ Edit :: range_replacement ( content, fix_range)
629
+ } ) ;
626
630
} ;
627
631
checker. diagnostics . push ( diagnostic) ;
628
632
}
Original file line number Diff line number Diff line change
1
+ -- -
2
+ source : crates / ruff / src / rules / pydocstyle / mod .rs
3
+ -- -
4
+ D214_module .py :1 :1 : D214 [* ] Section is over - indented (" Returns" )
5
+ |
6
+ 1 | / " " " A module docstring with D214 violations
7
+ 2 | |
8
+ 3 | | Returns
9
+ 4 | | ---- -
10
+ 5 | | valid returns
11
+ 6 | |
12
+ 7 | | Args
13
+ 8 | | ---- -
14
+ 9 | | valid args
15
+ 10 | | " " "
16
+ | |___^ D214
17
+ 11 |
18
+ 12 | import os
19
+ |
20
+ = help : Remove over - indentation from " Returns"
21
+
22
+ ℹ Suggested fix
23
+ 1 1 | " " " A module docstring with D214 violations
24
+ 2 2 |
25
+ 3 | - Returns
26
+ 3 | + Returns
27
+ 4 4 | ---- -
28
+ 5 5 | valid returns
29
+ 6 6 |
30
+
31
+ D214_module .py :1 :1 : D214 [* ] Section is over - indented (" Args" )
32
+ |
33
+ 1 | / " " " A module docstring with D214 violations
34
+ 2 | |
35
+ 3 | | Returns
36
+ 4 | | ---- -
37
+ 5 | | valid returns
38
+ 6 | |
39
+ 7 | | Args
40
+ 8 | | ---- -
41
+ 9 | | valid args
42
+ 10 | | " " "
43
+ | |___^ D214
44
+ 11 |
45
+ 12 | import os
46
+ |
47
+ = help : Remove over - indentation from " Args"
48
+
49
+ ℹ Suggested fix
50
+ 4 4 | ---- -
51
+ 5 5 | valid returns
52
+ 6 6 |
53
+ 7 | - Args
54
+ 7 | + Args
55
+ 8 8 | ---- -
56
+ 9 9 | valid args
57
+ 10 10 | " " "
58
+
59
+
You can’t perform that action at this time.
0 commit comments