Skip to content

Commit

Permalink
Add applicability to pydocstyle (#5390)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanrittenhouse authored Jun 27, 2023
1 parent 0585e14 commit ff0d0ab
Show file tree
Hide file tree
Showing 39 changed files with 125 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring)
}

// Insert one blank line after the summary (replacing any existing lines).
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
checker.stylist.line_ending().to_string(),
summary_end,
blank_end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
);
if checker.patch(diagnostic.kind.rule()) {
// Delete the blank line before the class.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
diagnostic.set_fix(Fix::automatic(Edit::deletion(
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
)));
Expand All @@ -116,8 +115,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
);
if checker.patch(diagnostic.kind.rule()) {
// Insert one blank line before the class.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
checker.stylist.line_ending().to_string(),
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
Expand Down Expand Up @@ -163,8 +161,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
);
if checker.patch(diagnostic.kind.rule()) {
// Insert a blank line before the class (replacing any existing lines).
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
checker.stylist.line_ending().to_string(),
first_line_start,
blank_lines_end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
);
if checker.patch(diagnostic.kind.rule()) {
// Delete the blank line before the docstring.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
diagnostic.set_fix(Fix::automatic(Edit::deletion(
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
)));
Expand Down Expand Up @@ -143,8 +142,7 @@ pub(crate) fn blank_before_after_function(checker: &mut Checker, docstring: &Doc
);
if checker.patch(diagnostic.kind.rule()) {
// Delete the blank line after the docstring.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
diagnostic.set_fix(Fix::automatic(Edit::deletion(
first_line_end,
blank_lines_end,
)));
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/pydocstyle/rules/capitalized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ pub(crate) fn capitalized(checker: &mut Checker, docstring: &Docstring) {
);

if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
capitalized_word,
TextRange::at(body.start(), first_word.text_len()),
)));
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/pydocstyle/rules/ends_with_period.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
&& !trimmed.ends_with(':')
&& !trimmed.ends_with(';')
{
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::suggested(Edit::insertion(
".".to_string(),
line.start() + trimmed.text_len(),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring
let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range());
// Best-effort autofix: avoid adding a period after other punctuation marks.
if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::suggested(Edit::insertion(
".".to_string(),
line.start() + trimmed.text_len(),
)));
Expand Down
9 changes: 3 additions & 6 deletions crates/ruff/src/rules/pydocstyle/rules/indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic =
Diagnostic::new(UnderIndentation, TextRange::empty(line.start()));
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
clean_space(docstring.indentation),
TextRange::at(line.start(), line_indent.text_len()),
)));
Expand Down Expand Up @@ -139,8 +138,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
} else {
Edit::range_replacement(indent, over_indented)
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::automatic(edit));
}
checker.diagnostics.push(diagnostic);
}
Expand All @@ -160,8 +158,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
} else {
Edit::range_replacement(indent, range)
};
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(edit));
diagnostic.set_fix(Fix::automatic(edit));
}
checker.diagnostics.push(diagnostic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstr
// Delete until first non-whitespace char.
for line in content_lines {
if let Some(end_column) = line.find(|c: char| !c.is_whitespace()) {
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
diagnostic.set_fix(Fix::automatic(Edit::deletion(
first_line.end(),
line.start() + TextSize::try_from(end_column).unwrap(),
)));
Expand Down Expand Up @@ -114,8 +113,7 @@ pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstr
first_line.strip_prefix(prefix).unwrap().trim_start()
);

#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
repl,
body.start(),
first_line.end(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ pub(crate) fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Do
checker.stylist.line_ending().as_str(),
clean_space(docstring.indentation)
);
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
content,
docstring.expr.end() - num_trailing_quotes - num_trailing_spaces,
docstring.expr.end() - num_trailing_quotes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub(crate) fn no_surrounding_whitespace(checker: &mut Checker, docstring: &Docst
// characters, avoid applying the fix.
if !trimmed.ends_with(quote) && !trimmed.starts_with(quote) && !ends_with_backslash(trimmed)
{
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
trimmed.to_string(),
TextRange::at(body.start(), line.text_len()),
)));
Expand Down
3 changes: 1 addition & 2 deletions crates/ruff/src/rules/pydocstyle/rules/one_liner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) {
if !trimmed.ends_with(trailing.chars().last().unwrap())
&& !trimmed.starts_with(leading.chars().last().unwrap())
{
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
format!("{leading}{trimmed}{trailing}"),
docstring.range(),
)));
Expand Down
42 changes: 14 additions & 28 deletions crates/ruff/src/rules/pydocstyle/rules/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ fn blanks_and_section_underline(
let range =
TextRange::new(context.following_range().start(), blank_lines_end);
// Delete any blank lines between the header and the underline.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
}
checker.diagnostics.push(diagnostic);
}
Expand Down Expand Up @@ -405,8 +404,7 @@ fn blanks_and_section_underline(
"-".repeat(context.section_name().len()),
checker.stylist.line_ending().as_str()
);
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::replacement(
diagnostic.set_fix(Fix::automatic(Edit::replacement(
content,
blank_lines_end,
non_blank_line.full_end(),
Expand All @@ -432,8 +430,7 @@ fn blanks_and_section_underline(
);

// Replace the existing indentation with whitespace of the appropriate length.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
clean_space(docstring.indentation),
range,
)));
Expand Down Expand Up @@ -472,8 +469,7 @@ fn blanks_and_section_underline(
);
if checker.patch(diagnostic.kind.rule()) {
// Delete any blank lines between the header and content.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::deletion(
diagnostic.set_fix(Fix::automatic(Edit::deletion(
line_after_dashes.start(),
blank_lines_after_dashes_end,
)));
Expand Down Expand Up @@ -507,8 +503,7 @@ fn blanks_and_section_underline(
clean_space(docstring.indentation),
"-".repeat(context.section_name().len()),
);
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::automatic(Edit::insertion(
content,
context.summary_range().end(),
)));
Expand All @@ -527,8 +522,7 @@ fn blanks_and_section_underline(
let range =
TextRange::new(context.following_range().start(), blank_lines_end);
// Delete any blank lines between the header and content.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
}
checker.diagnostics.push(diagnostic);
}
Expand All @@ -553,8 +547,7 @@ fn blanks_and_section_underline(
"-".repeat(context.section_name().len()),
);

#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::automatic(Edit::insertion(
content,
context.summary_range().end(),
)));
Expand Down Expand Up @@ -591,8 +584,7 @@ fn common_section(
// Replace the section title with the capitalized variant. This requires
// locating the start and end of the section name.
let section_range = context.section_name_range();
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
capitalized_section_name.to_string(),
section_range,
)));
Expand All @@ -615,8 +607,7 @@ fn common_section(
let content = clean_space(docstring.indentation);
let fix_range = TextRange::at(context.range().start(), leading_space.text_len());

#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(if content.is_empty() {
diagnostic.set_fix(Fix::automatic(if content.is_empty() {
Edit::range_deletion(fix_range)
} else {
Edit::range_replacement(content, fix_range)
Expand All @@ -639,8 +630,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a newline at the beginning of the next section.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::automatic(Edit::insertion(
line_end.to_string(),
next.range().start(),
)));
Expand All @@ -657,8 +647,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a newline after the section.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::automatic(Edit::insertion(
format!("{}{}", line_end, docstring.indentation),
context.range().end(),
)));
Expand All @@ -678,8 +667,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a blank line before the section.
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::insertion(
diagnostic.set_fix(Fix::automatic(Edit::insertion(
line_end.to_string(),
context.range().start(),
)));
Expand Down Expand Up @@ -882,8 +870,7 @@ fn numpy_section(
);
if checker.patch(diagnostic.kind.rule()) {
let section_range = context.section_name_range();
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_deletion(TextRange::at(
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(TextRange::at(
section_range.end(),
suffix.text_len(),
))));
Expand Down Expand Up @@ -920,8 +907,7 @@ fn google_section(
if checker.patch(diagnostic.kind.rule()) {
// Replace the suffix.
let section_name_range = context.section_name_range();
#[allow(deprecated)]
diagnostic.set_fix(Fix::unspecified(Edit::range_replacement(
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
":".to_string(),
TextRange::at(section_name_range.end(), suffix.text_len()),
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ D.py:137:5: D201 [*] No blank lines allowed before function docstring (found 1)
|
= help: Remove blank line(s) before function docstring

Suggested fix
Fix
133 133 |
134 134 | @expect('D201: No blank lines allowed before function docstring (found 1)')
135 135 | def leading_space():
Expand All @@ -30,7 +30,7 @@ D.py:151:5: D201 [*] No blank lines allowed before function docstring (found 1)
|
= help: Remove blank line(s) before function docstring

Suggested fix
Fix
147 147 | @expect('D201: No blank lines allowed before function docstring (found 1)')
148 148 | @expect('D202: No blank lines allowed after function docstring (found 1)')
149 149 | def trailing_and_leading_space():
Expand All @@ -52,7 +52,7 @@ D.py:546:5: D201 [*] No blank lines allowed before function docstring (found 1)
|
= help: Remove blank line(s) before function docstring

Suggested fix
Fix
542 542 | @expect('D201: No blank lines allowed before function docstring (found 1)')
543 543 | @expect('D213: Multi-line docstring summary should start at the second line')
544 544 | def multiline_leading_space():
Expand All @@ -76,7 +76,7 @@ D.py:568:5: D201 [*] No blank lines allowed before function docstring (found 1)
|
= help: Remove blank line(s) before function docstring

Suggested fix
Fix
564 564 | @expect('D202: No blank lines allowed after function docstring (found 1)')
565 565 | @expect('D213: Multi-line docstring summary should start at the second line')
566 566 | def multiline_trailing_and_leading_space():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ D.py:142:5: D202 [*] No blank lines allowed after function docstring (found 1)
|
= help: Remove blank line(s) after function docstring

Suggested fix
Fix
140 140 | @expect('D202: No blank lines allowed after function docstring (found 1)')
141 141 | def trailing_space():
142 142 | """Leading space."""
Expand All @@ -32,7 +32,7 @@ D.py:151:5: D202 [*] No blank lines allowed after function docstring (found 1)
|
= help: Remove blank line(s) after function docstring

Suggested fix
Fix
149 149 | def trailing_and_leading_space():
150 150 |
151 151 | """Trailing and leading space."""
Expand All @@ -56,7 +56,7 @@ D.py:555:5: D202 [*] No blank lines allowed after function docstring (found 1)
|
= help: Remove blank line(s) after function docstring

Suggested fix
Fix
556 556 |
557 557 | More content.
558 558 | """
Expand All @@ -80,7 +80,7 @@ D.py:568:5: D202 [*] No blank lines allowed after function docstring (found 1)
|
= help: Remove blank line(s) after function docstring

Suggested fix
Fix
569 569 |
570 570 | More content.
571 571 | """
Expand Down
Loading

0 comments on commit ff0d0ab

Please sign in to comment.