Rename applicability levels to always, sometimes, and never (#7821)

Following much discussion for #4181 at
https://github.com/astral-sh/ruff/pull/5119,
https://github.com/astral-sh/ruff/discussions/5476, #7769,
https://github.com/astral-sh/ruff/pull/7819, and in
[Discord](1159144114),
this pull request changes `Applicability` from using `Automatic`,
`Suggested`, and `Manual` to `Always`, `Sometimes`, and `Never`.

Also removes `Applicability::Unspecified` (replacing #7792).
This commit is contained in:
Zanie Blue 2023-10-05 13:43:46 -05:00 committed by GitHub
parent 7dc9887ab9
commit b64f403dc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
187 changed files with 386 additions and 381 deletions

View file

@ -114,7 +114,7 @@ pub(crate) fn blank_after_summary(checker: &mut Checker, docstring: &Docstring)
}
// Insert one blank line after the summary (replacing any existing lines).
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
checker.stylist().line_ending().to_string(),
summary_end,
blank_end,

View file

@ -191,7 +191,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
let mut diagnostic = Diagnostic::new(BlankLineBeforeClass, docstring.range());
if checker.patch(diagnostic.kind.rule()) {
// Delete the blank line before the class.
diagnostic.set_fix(Fix::automatic(Edit::deletion(
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
)));
@ -204,7 +204,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
let mut diagnostic = Diagnostic::new(OneBlankLineBeforeClass, docstring.range());
if checker.patch(diagnostic.kind.rule()) {
// Insert one blank line before the class.
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
checker.stylist().line_ending().to_string(),
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
@ -252,7 +252,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
// """Has priorities""" ; priorities=1
// ```
let next_statement = next_statement.trim_whitespace_start();
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
line_ending.to_string() + line_ending + indentation + next_statement,
replacement_start,
first_line.end(),
@ -282,7 +282,7 @@ pub(crate) fn blank_before_after_class(checker: &mut Checker, docstring: &Docstr
let mut diagnostic = Diagnostic::new(OneBlankLineAfterClass, docstring.range());
if checker.patch(diagnostic.kind.rule()) {
// Insert a blank line before the class (replacing any existing lines).
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
checker.stylist().line_ending().to_string(),
replacement_start,
blank_lines_end,

View file

@ -134,7 +134,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.
diagnostic.set_fix(Fix::automatic(Edit::deletion(
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
blank_lines_start,
docstring.start() - docstring.indentation.text_len(),
)));
@ -190,7 +190,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.
diagnostic.set_fix(Fix::automatic(Edit::deletion(
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
first_line_end,
blank_lines_end,
)));

View file

@ -91,7 +91,7 @@ pub(crate) fn capitalized(checker: &mut Checker, docstring: &Docstring) {
);
if checker.patch(diagnostic.kind.rule()) {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
capitalized_word,
TextRange::at(body.start(), first_word.text_len()),
)));

View file

@ -105,7 +105,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
let mut diagnostic = Diagnostic::new(EndsInPeriod, docstring.range());
// Best-effort fix: avoid adding a period after other punctuation marks.
if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) {
diagnostic.set_fix(Fix::suggested(Edit::insertion(
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
".".to_string(),
line.start() + trimmed.text_len(),
)));

View file

@ -104,7 +104,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring
let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range());
// Best-effort fix: avoid adding a period after other punctuation marks.
if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) {
diagnostic.set_fix(Fix::suggested(Edit::insertion(
diagnostic.set_fix(Fix::sometimes_applies(Edit::insertion(
".".to_string(),
line.start() + trimmed.text_len(),
)));

View file

@ -189,7 +189,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()) {
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
clean_space(docstring.indentation),
TextRange::at(line.start(), line_indent.text_len()),
)));
@ -236,7 +236,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
} else {
Edit::range_replacement(indent, over_indented)
};
diagnostic.set_fix(Fix::automatic(edit));
diagnostic.set_fix(Fix::always_applies(edit));
}
checker.diagnostics.push(diagnostic);
}
@ -256,7 +256,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
} else {
Edit::range_replacement(indent, range)
};
diagnostic.set_fix(Fix::automatic(edit));
diagnostic.set_fix(Fix::always_applies(edit));
}
checker.diagnostics.push(diagnostic);
}

View file

@ -141,7 +141,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()) {
diagnostic.set_fix(Fix::automatic(Edit::deletion(
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
first_line.end(),
line.start() + TextSize::try_from(end_column).unwrap(),
)));
@ -197,7 +197,7 @@ pub(crate) fn multi_line_summary_start(checker: &mut Checker, docstring: &Docstr
first_line.strip_prefix(prefix).unwrap().trim_start()
);
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
repl,
body.start(),
first_line.end(),

View file

@ -96,7 +96,7 @@ pub(crate) fn newline_after_last_paragraph(checker: &mut Checker, docstring: &Do
checker.stylist().line_ending().as_str(),
clean_space(docstring.indentation)
);
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
content,
docstring.expr.end() - num_trailing_quotes - num_trailing_spaces,
docstring.expr.end() - num_trailing_quotes,

View file

@ -69,7 +69,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)
{
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
trimmed.to_string(),
TextRange::at(body.start(), line.text_len()),
)));

View file

@ -78,7 +78,7 @@ pub(crate) fn one_liner(checker: &mut Checker, docstring: &Docstring) {
&& !trimmed.ends_with(trailing.chars().last().unwrap())
&& !trimmed.starts_with(leading.chars().last().unwrap())
{
diagnostic.set_fix(Fix::suggested(Edit::range_replacement(
diagnostic.set_fix(Fix::sometimes_applies(Edit::range_replacement(
format!("{leading}{trimmed}{trailing}"),
docstring.range(),
)));

View file

@ -1392,7 +1392,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.
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(range)));
}
checker.diagnostics.push(diagnostic);
}
@ -1420,7 +1420,7 @@ fn blanks_and_section_underline(
"-".repeat(context.section_name().len()),
checker.stylist().line_ending().as_str()
);
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
content,
blank_lines_end,
non_blank_line.full_end(),
@ -1446,7 +1446,7 @@ fn blanks_and_section_underline(
leading_space.text_len() + TextSize::from(1),
);
let contents = clean_space(docstring.indentation);
diagnostic.set_fix(Fix::automatic(if contents.is_empty() {
diagnostic.set_fix(Fix::always_applies(if contents.is_empty() {
Edit::range_deletion(range)
} else {
Edit::range_replacement(contents, range)
@ -1486,7 +1486,7 @@ fn blanks_and_section_underline(
);
if checker.patch(diagnostic.kind.rule()) {
// Delete any blank lines between the header and content.
diagnostic.set_fix(Fix::automatic(Edit::deletion(
diagnostic.set_fix(Fix::always_applies(Edit::deletion(
line_after_dashes.start(),
blank_lines_after_dashes_end,
)));
@ -1529,14 +1529,14 @@ fn blanks_and_section_underline(
{
// If an existing underline is an equal sign line of the appropriate length,
// replace it with a dashed line.
diagnostic.set_fix(Fix::automatic(Edit::replacement(
diagnostic.set_fix(Fix::always_applies(Edit::replacement(
content,
context.summary_range().end(),
non_blank_line.end(),
)));
} else {
// Otherwise, insert a dashed line after the section header.
diagnostic.set_fix(Fix::automatic(Edit::insertion(
diagnostic.set_fix(Fix::always_applies(Edit::insertion(
content,
context.summary_range().end(),
)));
@ -1556,7 +1556,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.
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(range)));
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(range)));
}
checker.diagnostics.push(diagnostic);
}
@ -1581,7 +1581,7 @@ fn blanks_and_section_underline(
"-".repeat(context.section_name().len()),
);
diagnostic.set_fix(Fix::automatic(Edit::insertion(
diagnostic.set_fix(Fix::always_applies(Edit::insertion(
content,
context.summary_range().end(),
)));
@ -1618,7 +1618,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();
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
capitalized_section_name.to_string(),
section_range,
)));
@ -1641,7 +1641,7 @@ fn common_section(
let content = clean_space(docstring.indentation);
let fix_range = TextRange::at(context.start(), leading_space.text_len());
diagnostic.set_fix(Fix::automatic(if content.is_empty() {
diagnostic.set_fix(Fix::always_applies(if content.is_empty() {
Edit::range_deletion(fix_range)
} else {
Edit::range_replacement(content, fix_range)
@ -1664,7 +1664,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a newline at the beginning of the next section.
diagnostic.set_fix(Fix::automatic(Edit::insertion(
diagnostic.set_fix(Fix::always_applies(Edit::insertion(
line_end.to_string(),
next.start(),
)));
@ -1681,7 +1681,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a newline after the section.
diagnostic.set_fix(Fix::automatic(Edit::insertion(
diagnostic.set_fix(Fix::always_applies(Edit::insertion(
format!("{}{}", line_end, docstring.indentation),
context.end(),
)));
@ -1704,7 +1704,7 @@ fn common_section(
);
if checker.patch(diagnostic.kind.rule()) {
// Add a blank line before the section.
diagnostic.set_fix(Fix::automatic(Edit::insertion(
diagnostic.set_fix(Fix::always_applies(Edit::insertion(
line_end.to_string(),
context.start(),
)));
@ -1900,7 +1900,7 @@ fn numpy_section(
);
if checker.patch(diagnostic.kind.rule()) {
let section_range = context.section_name_range();
diagnostic.set_fix(Fix::automatic(Edit::range_deletion(TextRange::at(
diagnostic.set_fix(Fix::always_applies(Edit::range_deletion(TextRange::at(
section_range.end(),
suffix.text_len(),
))));
@ -1937,7 +1937,7 @@ fn google_section(
if checker.patch(diagnostic.kind.rule()) {
// Replace the suffix.
let section_name_range = context.section_name_range();
diagnostic.set_fix(Fix::automatic(Edit::range_replacement(
diagnostic.set_fix(Fix::always_applies(Edit::range_replacement(
":".to_string(),
TextRange::at(section_name_range.end(), suffix.text_len()),
)));