Skip to content

Commit

Permalink
Avoid adding dashed line outside of docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 17, 2023
1 parent f5e5caa commit 4d83b1b
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 199 deletions.
9 changes: 9 additions & 0 deletions crates/ruff/resources/test/fixtures/pydocstyle/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ def no_underline_and_no_description(): # noqa: D416
"""


@expect(_D213)
@expect("D407: Missing dashed underline after section ('Returns')")
@expect("D414: Section has no content ('Returns')")
def no_underline_and_no_newline(): # noqa: D416
"""Toggle the gizmo.
Returns"""


@expect(_D213)
@expect("D410: Missing blank line after section ('Returns')")
@expect("D414: Section has no content ('Returns')")
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff/src/rules/pydocstyle/rules/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ fn blanks_and_section_underline(
// Add a dashed line (of the appropriate length) under the section header.
let content = format!(
"{}{}{}",
checker.stylist.line_ending().as_str(),
whitespace::clean(docstring.indentation),
"-".repeat(context.section_name.len()),
checker.stylist.line_ending().as_str()
);
diagnostic.amend(Fix::insertion(
content,
Location::new(
docstring.expr.location.row() + context.original_index + 1,
0,
docstring.expr.location.row() + context.original_index,
context.line.trim_end().chars().count(),
),
));
}
Expand Down Expand Up @@ -595,15 +595,15 @@ fn blanks_and_section_underline(
// Add a dashed line (of the appropriate length) under the section header.
let content = format!(
"{}{}{}",
checker.stylist.line_ending().as_str(),
whitespace::clean(docstring.indentation),
"-".repeat(context.section_name.len()),
checker.stylist.line_ending().as_str()
);
diagnostic.amend(Fix::insertion(
content,
Location::new(
docstring.expr.location.row() + context.original_index + 1,
0,
docstring.expr.location.row() + context.original_index,
context.line.trim_end().chars().count(),
),
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ expression: diagnostics
suggestion: "Remove over-indentation from \"Returns\""
fixable: true
location:
row: 135
row: 144
column: 4
end_location:
row: 141
row: 150
column: 7
fix:
content: " "
location:
row: 137
row: 146
column: 0
end_location:
row: 137
row: 146
column: 8
parent: ~

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ expression: diagnostics
suggestion: "Remove over-indentation from \"Returns\" underline"
fixable: true
location:
row: 147
row: 156
column: 4
end_location:
row: 153
row: 162
column: 7
fix:
content: " "
location:
row: 150
row: 159
column: 0
end_location:
row: 150
row: 159
column: 9
parent: ~
- kind:
Expand All @@ -28,18 +28,18 @@ expression: diagnostics
suggestion: "Remove over-indentation from \"Returns\" underline"
fixable: true
location:
row: 161
row: 170
column: 4
end_location:
row: 165
row: 174
column: 7
fix:
content: " "
location:
row: 164
row: 173
column: 0
end_location:
row: 164
row: 173
column: 9
parent: ~

Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ expression: diagnostics
suggestion: "Capitalize \"Short summary\""
fixable: true
location:
row: 207
row: 216
column: 4
end_location:
row: 221
row: 230
column: 7
fix:
content: Short Summary
location:
row: 209
row: 218
column: 4
end_location:
row: 209
row: 218
column: 17
parent: ~

Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ expression: diagnostics
suggestion: "Add newline after \"Raises\""
fixable: true
location:
row: 207
row: 216
column: 4
end_location:
row: 221
row: 230
column: 7
fix:
content: ""
location:
row: 218
row: 227
column: 10
end_location:
row: 218
row: 227
column: 11
parent: ~

0 comments on commit 4d83b1b

Please sign in to comment.