Rename Autofix to Fix (#7657)

**Summary** Mostly mechanical symbol rename and search-and-replace, with
small changes to the markdown docs to read better
This commit is contained in:
konsti 2023-09-28 12:53:05 +02:00 committed by GitHub
parent 8028de8956
commit 1e173f7909
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
231 changed files with 943 additions and 960 deletions

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines};
use ruff_text_size::Ranged;
@ -47,7 +47,7 @@ pub struct BlankLineAfterSummary {
}
impl Violation for BlankLineAfterSummary {
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
const FIX_KIND: FixKind = FixKind::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
@ -61,7 +61,7 @@ impl Violation for BlankLineAfterSummary {
}
}
fn autofix_title(&self) -> Option<String> {
fn fix_title(&self) -> Option<String> {
Some("Insert single blank line".to_string())
}
}

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_trivia::{indentation_at_offset, PythonWhitespace};
use ruff_source_file::{Line, UniversalNewlineIterator};
@ -43,13 +43,13 @@ use crate::registry::{AsRule, Rule};
#[violation]
pub struct OneBlankLineBeforeClass;
impl AlwaysAutofixableViolation for OneBlankLineBeforeClass {
impl AlwaysFixableViolation for OneBlankLineBeforeClass {
#[derive_message_formats]
fn message(&self) -> String {
format!("1 blank line required before class docstring")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Insert 1 blank line before class docstring".to_string()
}
}
@ -95,13 +95,13 @@ impl AlwaysAutofixableViolation for OneBlankLineBeforeClass {
#[violation]
pub struct OneBlankLineAfterClass;
impl AlwaysAutofixableViolation for OneBlankLineAfterClass {
impl AlwaysFixableViolation for OneBlankLineAfterClass {
#[derive_message_formats]
fn message(&self) -> String {
format!("1 blank line required after class docstring")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Insert 1 blank line after class docstring".to_string()
}
}
@ -140,13 +140,13 @@ impl AlwaysAutofixableViolation for OneBlankLineAfterClass {
#[violation]
pub struct BlankLineBeforeClass;
impl AlwaysAutofixableViolation for BlankLineBeforeClass {
impl AlwaysFixableViolation for BlankLineBeforeClass {
#[derive_message_formats]
fn message(&self) -> String {
format!("No blank lines allowed before class docstring")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove blank line(s) before class docstring".to_string()
}
}

View file

@ -1,7 +1,7 @@
use once_cell::sync::Lazy;
use regex::Regex;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_trivia::PythonWhitespace;
use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines};
@ -42,14 +42,14 @@ pub struct NoBlankLineBeforeFunction {
num_lines: usize,
}
impl AlwaysAutofixableViolation for NoBlankLineBeforeFunction {
impl AlwaysFixableViolation for NoBlankLineBeforeFunction {
#[derive_message_formats]
fn message(&self) -> String {
let NoBlankLineBeforeFunction { num_lines } = self;
format!("No blank lines allowed before function docstring (found {num_lines})")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove blank line(s) before function docstring".to_string()
}
}
@ -86,14 +86,14 @@ pub struct NoBlankLineAfterFunction {
num_lines: usize,
}
impl AlwaysAutofixableViolation for NoBlankLineAfterFunction {
impl AlwaysFixableViolation for NoBlankLineAfterFunction {
#[derive_message_formats]
fn message(&self) -> String {
let NoBlankLineAfterFunction { num_lines } = self;
format!("No blank lines allowed after function docstring (found {num_lines})")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove blank line(s) after function docstring".to_string()
}
}

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;
use ruff_text_size::{TextLen, TextRange};
@ -36,7 +36,7 @@ pub struct FirstLineCapitalized {
capitalized_word: String,
}
impl AlwaysAutofixableViolation for FirstLineCapitalized {
impl AlwaysFixableViolation for FirstLineCapitalized {
#[derive_message_formats]
fn message(&self) -> String {
format!(
@ -45,7 +45,7 @@ impl AlwaysAutofixableViolation for FirstLineCapitalized {
)
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
format!(
"Capitalize `{}` to `{}`",
self.first_word, self.capitalized_word

View file

@ -1,7 +1,7 @@
use ruff_text_size::TextLen;
use strum::IntoEnumIterator;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines};
use ruff_text_size::Ranged;
@ -47,13 +47,13 @@ use crate::rules::pydocstyle::helpers::logical_line;
#[violation]
pub struct EndsInPeriod;
impl AlwaysAutofixableViolation for EndsInPeriod {
impl AlwaysFixableViolation for EndsInPeriod {
#[derive_message_formats]
fn message(&self) -> String {
format!("First line should end with a period")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Add period".to_string()
}
}
@ -103,7 +103,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) {
if !trimmed.ends_with('.') {
let mut diagnostic = Diagnostic::new(EndsInPeriod, docstring.range());
// Best-effort autofix: avoid adding a period after other punctuation marks.
// 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(
".".to_string(),

View file

@ -1,7 +1,7 @@
use ruff_text_size::TextLen;
use strum::IntoEnumIterator;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines};
use ruff_text_size::Ranged;
@ -46,13 +46,13 @@ use crate::rules::pydocstyle::helpers::logical_line;
#[violation]
pub struct EndsInPunctuation;
impl AlwaysAutofixableViolation for EndsInPunctuation {
impl AlwaysFixableViolation for EndsInPunctuation {
#[derive_message_formats]
fn message(&self) -> String {
format!("First line should end with a period, question mark, or exclamation point")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Add closing punctuation".to_string()
}
}
@ -102,7 +102,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring
if !trimmed.ends_with(['.', '!', '?']) {
let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range());
// Best-effort autofix: avoid adding a period after other punctuation marks.
// 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(
".".to_string(),

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
use ruff_diagnostics::{AlwaysFixableViolation, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::docstrings::{clean_space, leading_space};
@ -88,13 +88,13 @@ impl Violation for IndentWithSpaces {
#[violation]
pub struct UnderIndentation;
impl AlwaysAutofixableViolation for UnderIndentation {
impl AlwaysFixableViolation for UnderIndentation {
#[derive_message_formats]
fn message(&self) -> String {
format!("Docstring is under-indented")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Increase indentation".to_string()
}
}
@ -135,13 +135,13 @@ impl AlwaysAutofixableViolation for UnderIndentation {
#[violation]
pub struct OverIndentation;
impl AlwaysAutofixableViolation for OverIndentation {
impl AlwaysFixableViolation for OverIndentation {
#[derive_message_formats]
fn message(&self) -> String {
format!("Docstring is over-indented")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove over-indentation".to_string()
}
}
@ -182,7 +182,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
if checker.enabled(Rule::UnderIndentation) {
// We report under-indentation on every line. This isn't great, but enables
// autofix.
// fix.
if (i == lines.len() - 1 || !is_blank)
&& line_indent.len() < docstring.indentation.len()
{
@ -226,7 +226,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) {
if is_over_indented {
for over_indented in over_indented_lines {
// We report over-indentation on every line. This isn't great, but
// enables autofix.
// enables fix.
let mut diagnostic =
Diagnostic::new(OverIndentation, TextRange::empty(over_indented.start()));
if checker.patch(diagnostic.kind.rule()) {

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::str::{is_triple_quote, leading_quote};
use ruff_python_semantic::Definition;
@ -52,13 +52,13 @@ use crate::registry::{AsRule, Rule};
#[violation]
pub struct MultiLineSummaryFirstLine;
impl AlwaysAutofixableViolation for MultiLineSummaryFirstLine {
impl AlwaysFixableViolation for MultiLineSummaryFirstLine {
#[derive_message_formats]
fn message(&self) -> String {
format!("Multi-line docstring summary should start at the first line")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove whitespace after opening quotes".to_string()
}
}
@ -106,13 +106,13 @@ impl AlwaysAutofixableViolation for MultiLineSummaryFirstLine {
#[violation]
pub struct MultiLineSummarySecondLine;
impl AlwaysAutofixableViolation for MultiLineSummarySecondLine {
impl AlwaysFixableViolation for MultiLineSummarySecondLine {
#[derive_message_formats]
fn message(&self) -> String {
format!("Multi-line docstring summary should start at the second line")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Insert line break and indentation after opening quotes".to_string()
}
}

View file

@ -1,6 +1,6 @@
use ruff_text_size::{TextLen, TextSize};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::docstrings::clean_space;
use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlines};
@ -47,13 +47,13 @@ use crate::registry::AsRule;
#[violation]
pub struct NewLineAfterLastParagraph;
impl AlwaysAutofixableViolation for NewLineAfterLastParagraph {
impl AlwaysFixableViolation for NewLineAfterLastParagraph {
#[derive_message_formats]
fn message(&self) -> String {
format!("Multi-line docstring closing quotes should be on a separate line")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Move closing quotes to new line".to_string()
}
}

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_source_file::NewlineWithTrailingNewline;
use ruff_text_size::Ranged;
@ -35,14 +35,14 @@ use crate::rules::pydocstyle::helpers::ends_with_backslash;
pub struct SurroundingWhitespace;
impl Violation for SurroundingWhitespace {
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
const FIX_KIND: FixKind = FixKind::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
format!("No whitespaces allowed surrounding docstring text")
}
fn autofix_title(&self) -> Option<String> {
fn fix_title(&self) -> Option<String> {
Some("Trim surrounding whitespace".to_string())
}
}

View file

@ -1,4 +1,4 @@
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::str::{leading_quote, trailing_quote};
use ruff_source_file::NewlineWithTrailingNewline;
@ -37,14 +37,14 @@ use crate::registry::AsRule;
pub struct FitsOnOneLine;
impl Violation for FitsOnOneLine {
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
const FIX_KIND: FixKind = FixKind::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
format!("One-line docstring should fit on one line")
}
fn autofix_title(&self) -> Option<String> {
fn fix_title(&self) -> Option<String> {
Some("Reformat to one line".to_string())
}
}

View file

@ -3,7 +3,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use rustc_hash::FxHashSet;
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
use ruff_diagnostics::{AlwaysFixableViolation, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::docstrings::{clean_space, leading_space};
@ -88,14 +88,14 @@ pub struct SectionNotOverIndented {
name: String,
}
impl AlwaysAutofixableViolation for SectionNotOverIndented {
impl AlwaysFixableViolation for SectionNotOverIndented {
#[derive_message_formats]
fn message(&self) -> String {
let SectionNotOverIndented { name } = self;
format!("Section is over-indented (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let SectionNotOverIndented { name } = self;
format!("Remove over-indentation from \"{name}\"")
}
@ -186,14 +186,14 @@ pub struct SectionUnderlineNotOverIndented {
name: String,
}
impl AlwaysAutofixableViolation for SectionUnderlineNotOverIndented {
impl AlwaysFixableViolation for SectionUnderlineNotOverIndented {
#[derive_message_formats]
fn message(&self) -> String {
let SectionUnderlineNotOverIndented { name } = self;
format!("Section underline is over-indented (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let SectionUnderlineNotOverIndented { name } = self;
format!("Remove over-indentation from \"{name}\" underline")
}
@ -265,14 +265,14 @@ pub struct CapitalizeSectionName {
name: String,
}
impl AlwaysAutofixableViolation for CapitalizeSectionName {
impl AlwaysFixableViolation for CapitalizeSectionName {
#[derive_message_formats]
fn message(&self) -> String {
let CapitalizeSectionName { name } = self;
format!("Section name should be properly capitalized (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let CapitalizeSectionName { name } = self;
format!("Capitalize \"{name}\"")
}
@ -361,14 +361,14 @@ pub struct NewLineAfterSectionName {
name: String,
}
impl AlwaysAutofixableViolation for NewLineAfterSectionName {
impl AlwaysFixableViolation for NewLineAfterSectionName {
#[derive_message_formats]
fn message(&self) -> String {
let NewLineAfterSectionName { name } = self;
format!("Section name should end with a newline (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let NewLineAfterSectionName { name } = self;
format!("Add newline after \"{name}\"")
}
@ -457,14 +457,14 @@ pub struct DashedUnderlineAfterSection {
name: String,
}
impl AlwaysAutofixableViolation for DashedUnderlineAfterSection {
impl AlwaysFixableViolation for DashedUnderlineAfterSection {
#[derive_message_formats]
fn message(&self) -> String {
let DashedUnderlineAfterSection { name } = self;
format!("Missing dashed underline after section (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let DashedUnderlineAfterSection { name } = self;
format!("Add dashed line under \"{name}\"")
}
@ -559,14 +559,14 @@ pub struct SectionUnderlineAfterName {
name: String,
}
impl AlwaysAutofixableViolation for SectionUnderlineAfterName {
impl AlwaysFixableViolation for SectionUnderlineAfterName {
#[derive_message_formats]
fn message(&self) -> String {
let SectionUnderlineAfterName { name } = self;
format!("Section underline should be in the line following the section's name (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let SectionUnderlineAfterName { name } = self;
format!("Add underline to \"{name}\"")
}
@ -658,14 +658,14 @@ pub struct SectionUnderlineMatchesSectionLength {
name: String,
}
impl AlwaysAutofixableViolation for SectionUnderlineMatchesSectionLength {
impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength {
#[derive_message_formats]
fn message(&self) -> String {
let SectionUnderlineMatchesSectionLength { name } = self;
format!("Section underline should match the length of its name (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let SectionUnderlineMatchesSectionLength { name } = self;
format!("Adjust underline length to match \"{name}\"")
}
@ -753,14 +753,14 @@ pub struct NoBlankLineAfterSection {
name: String,
}
impl AlwaysAutofixableViolation for NoBlankLineAfterSection {
impl AlwaysFixableViolation for NoBlankLineAfterSection {
#[derive_message_formats]
fn message(&self) -> String {
let NoBlankLineAfterSection { name } = self;
format!("Missing blank line after section (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let NoBlankLineAfterSection { name } = self;
format!("Add blank line after \"{name}\"")
}
@ -846,14 +846,14 @@ pub struct NoBlankLineBeforeSection {
name: String,
}
impl AlwaysAutofixableViolation for NoBlankLineBeforeSection {
impl AlwaysFixableViolation for NoBlankLineBeforeSection {
#[derive_message_formats]
fn message(&self) -> String {
let NoBlankLineBeforeSection { name } = self;
format!("Missing blank line before section (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let NoBlankLineBeforeSection { name } = self;
format!("Add blank line before \"{name}\"")
}
@ -942,14 +942,14 @@ pub struct BlankLineAfterLastSection {
name: String,
}
impl AlwaysAutofixableViolation for BlankLineAfterLastSection {
impl AlwaysFixableViolation for BlankLineAfterLastSection {
#[derive_message_formats]
fn message(&self) -> String {
let BlankLineAfterLastSection { name } = self;
format!("Missing blank line after last section (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let BlankLineAfterLastSection { name } = self;
format!("Add blank line after \"{name}\"")
}
@ -1109,14 +1109,14 @@ pub struct SectionNameEndsInColon {
name: String,
}
impl AlwaysAutofixableViolation for SectionNameEndsInColon {
impl AlwaysFixableViolation for SectionNameEndsInColon {
#[derive_message_formats]
fn message(&self) -> String {
let SectionNameEndsInColon { name } = self;
format!("Section name should end with a colon (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
let SectionNameEndsInColon { name } = self;
format!("Add colon to \"{name}\"")
}
@ -1276,14 +1276,14 @@ pub struct BlankLinesBetweenHeaderAndContent {
name: String,
}
impl AlwaysAutofixableViolation for BlankLinesBetweenHeaderAndContent {
impl AlwaysFixableViolation for BlankLinesBetweenHeaderAndContent {
#[derive_message_formats]
fn message(&self) -> String {
let BlankLinesBetweenHeaderAndContent { name } = self;
format!("No blank lines allowed between a section header and its content (\"{name}\")")
}
fn autofix_title(&self) -> String {
fn fix_title(&self) -> String {
"Remove blank line(s)".to_string()
}
}