Implement autofix for more docstring-related rules (#448)

This commit is contained in:
Charlie Marsh 2022-10-17 16:56:47 -04:00 committed by GitHub
parent 118a9feec8
commit 206e6463be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 1378 additions and 919 deletions

View file

@ -294,7 +294,7 @@ The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` com
| D202 | NoBlankLineAfterFunction | No blank lines allowed after function docstring (found 1) | 🛠 | | D202 | NoBlankLineAfterFunction | No blank lines allowed after function docstring (found 1) | 🛠 |
| D203 | OneBlankLineBeforeClass | 1 blank line required before class docstring | 🛠 | | D203 | OneBlankLineBeforeClass | 1 blank line required before class docstring | 🛠 |
| D204 | OneBlankLineAfterClass | 1 blank line required after class docstring | 🛠 | | D204 | OneBlankLineAfterClass | 1 blank line required after class docstring | 🛠 |
| D205 | NoBlankLineAfterSummary | 1 blank line required between summary line and description | 🛠 | | D205 | BlankLineAfterSummary | 1 blank line required between summary line and description | 🛠 |
| D206 | IndentWithSpaces | Docstring should be indented with spaces, not tabs | | | D206 | IndentWithSpaces | Docstring should be indented with spaces, not tabs | |
| D207 | NoUnderIndentation | Docstring is under-indented | | | D207 | NoUnderIndentation | Docstring is under-indented | |
| D208 | NoOverIndentation | Docstring is over-indented | | | D208 | NoOverIndentation | Docstring is over-indented | |
@ -304,7 +304,7 @@ The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` com
| D212 | MultiLineSummaryFirstLine | Multi-line docstring summary should start at the first line | | | D212 | MultiLineSummaryFirstLine | Multi-line docstring summary should start at the first line | |
| D213 | MultiLineSummarySecondLine | Multi-line docstring summary should start at the second line | | | D213 | MultiLineSummarySecondLine | Multi-line docstring summary should start at the second line | |
| D214 | SectionNotOverIndented | Section is over-indented ("Returns") | | | D214 | SectionNotOverIndented | Section is over-indented ("Returns") | |
| D215 | SectionUnderlineNotOverIndented | Section underline is over-indented ("Returns") | | | D215 | SectionUnderlineNotOverIndented | Section underline is over-indented ("Returns") | 🛠 |
| D300 | UsesTripleQuotes | Use """triple double quotes""" | | | D300 | UsesTripleQuotes | Use """triple double quotes""" | |
| D400 | EndsInPeriod | First line should end with a period | | | D400 | EndsInPeriod | First line should end with a period | |
| D402 | NoSignature | First line should not be the function's 'signature' | | | D402 | NoSignature | First line should not be the function's 'signature' | |
@ -312,12 +312,12 @@ The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` com
| D404 | NoThisPrefix | First word of the docstring should not be `This` | | | D404 | NoThisPrefix | First word of the docstring should not be `This` | |
| D405 | CapitalizeSectionName | Section name should be properly capitalized ("returns") | | | D405 | CapitalizeSectionName | Section name should be properly capitalized ("returns") | |
| D406 | NewLineAfterSectionName | Section name should end with a newline ("Returns") | | | D406 | NewLineAfterSectionName | Section name should end with a newline ("Returns") | |
| D407 | DashedUnderlineAfterSection | Missing dashed underline after section ("Returns") | | | D407 | DashedUnderlineAfterSection | Missing dashed underline after section ("Returns") | 🛠 |
| D408 | SectionUnderlineAfterName | Section underline should be in the line following the section's name ("Returns") | | | D408 | SectionUnderlineAfterName | Section underline should be in the line following the section's name ("Returns") | |
| D409 | SectionUnderlineMatchesSectionLength | Section underline should match the length of its name ("Returns") | | | D409 | SectionUnderlineMatchesSectionLength | Section underline should match the length of its name ("Returns") | 🛠 |
| D410 | BlankLineAfterSection | Missing blank line after section ("Returns") | 🛠 | | D410 | BlankLineAfterSection | Missing blank line after section ("Returns") | 🛠 |
| D411 | BlankLineBeforeSection | Missing blank line before section ("Returns") | | | D411 | BlankLineBeforeSection | Missing blank line before section ("Returns") | 🛠 |
| D412 | NoBlankLinesBetweenHeaderAndContent | No blank lines allowed between a section header and its content ("Returns") | | | D412 | NoBlankLinesBetweenHeaderAndContent | No blank lines allowed between a section header and its content ("Returns") | 🛠 |
| D413 | BlankLineAfterLastSection | Missing blank line after last section ("Returns") | 🛠 | | D413 | BlankLineAfterLastSection | Missing blank line after last section ("Returns") | 🛠 |
| D414 | NonEmptySection | Section has no content ("Returns") | | | D414 | NonEmptySection | Section has no content ("Returns") | |
| D415 | EndsInPunctuation | First line should end with a period, question mark, or exclamation point | | | D415 | EndsInPunctuation | First line should end with a period, question mark, or exclamation point | |

View file

@ -1,7 +1,10 @@
use crate::autofix::Fix;
use crate::autofix::Patch;
use itertools::Itertools; use itertools::Itertools;
use rustpython_parser::ast::Location; use rustpython_parser::ast::Location;
use std::collections::BTreeSet;
use crate::checks::{Check, Fix}; use crate::checks::Check;
#[derive(Hash)] #[derive(Hash)]
pub enum Mode { pub enum Mode {
@ -35,34 +38,44 @@ pub fn fix_file(checks: &mut [Check], contents: &str) -> Option<String> {
fn apply_fixes<'a>(fixes: impl Iterator<Item = &'a mut Fix>, contents: &str) -> String { fn apply_fixes<'a>(fixes: impl Iterator<Item = &'a mut Fix>, contents: &str) -> String {
let lines: Vec<&str> = contents.lines().collect(); let lines: Vec<&str> = contents.lines().collect();
let mut output = "".to_string(); let mut output: String = Default::default();
let mut last_pos: Location = Location::new(0, 0); let mut last_pos: Location = Default::default();
let mut applied: BTreeSet<&Patch> = Default::default();
for fix in fixes.sorted_by_key(|fix| fix.location) { for fix in fixes.sorted_by_key(|fix| fix.patch.location) {
// Best-effort approach: if this fix overlaps with a fix we've already applied, skip it. // If we already applied an identical fix as part of another correction, skip any
if last_pos > fix.location { // re-application.
if applied.contains(&fix.patch) {
fix.applied = true;
continue; continue;
} }
if fix.location.row() > last_pos.row() { // Best-effort approach: if this fix overlaps with a fix we've already applied, skip it.
if last_pos > fix.patch.location {
continue;
}
if fix.patch.location.row() > last_pos.row() {
if last_pos.row() > 0 || last_pos.column() > 0 { if last_pos.row() > 0 || last_pos.column() > 0 {
output.push_str(&lines[last_pos.row() - 1][last_pos.column() - 1..]); output.push_str(&lines[last_pos.row() - 1][last_pos.column() - 1..]);
output.push('\n'); output.push('\n');
} }
for line in &lines[last_pos.row()..fix.location.row() - 1] { for line in &lines[last_pos.row()..fix.patch.location.row() - 1] {
output.push_str(line); output.push_str(line);
output.push('\n'); output.push('\n');
} }
output.push_str(&lines[fix.location.row() - 1][..fix.location.column() - 1]); output
output.push_str(&fix.content); .push_str(&lines[fix.patch.location.row() - 1][..fix.patch.location.column() - 1]);
output.push_str(&fix.patch.content);
} else { } else {
output.push_str( output.push_str(
&lines[last_pos.row() - 1][last_pos.column() - 1..fix.location.column() - 1], &lines[last_pos.row() - 1][last_pos.column() - 1..fix.patch.location.column() - 1],
); );
output.push_str(&fix.content); output.push_str(&fix.patch.content);
} }
last_pos = fix.patch.end_location;
last_pos = fix.end_location; applied.insert(&fix.patch);
fix.applied = true; fix.applied = true;
} }
@ -89,7 +102,8 @@ mod tests {
use rustpython_parser::ast::Location; use rustpython_parser::ast::Location;
use crate::autofix::fixer::apply_fixes; use crate::autofix::fixer::apply_fixes;
use crate::checks::Fix; use crate::autofix::Fix;
use crate::autofix::Patch;
#[test] #[test]
fn empty_file() -> Result<()> { fn empty_file() -> Result<()> {
@ -105,9 +119,11 @@ mod tests {
#[test] #[test]
fn apply_single_replacement() -> Result<()> { fn apply_single_replacement() -> Result<()> {
let mut fixes = vec![Fix { let mut fixes = vec![Fix {
content: "Bar".to_string(), patch: Patch {
location: Location::new(1, 9), content: "Bar".to_string(),
end_location: Location::new(1, 15), location: Location::new(1, 9),
end_location: Location::new(1, 15),
},
applied: false, applied: false,
}]; }];
let actual = apply_fixes( let actual = apply_fixes(
@ -129,9 +145,11 @@ mod tests {
#[test] #[test]
fn apply_single_removal() -> Result<()> { fn apply_single_removal() -> Result<()> {
let mut fixes = vec![Fix { let mut fixes = vec![Fix {
content: "".to_string(), patch: Patch {
location: Location::new(1, 8), content: "".to_string(),
end_location: Location::new(1, 16), location: Location::new(1, 8),
end_location: Location::new(1, 16),
},
applied: false, applied: false,
}]; }];
let actual = apply_fixes( let actual = apply_fixes(
@ -154,15 +172,19 @@ mod tests {
fn apply_double_removal() -> Result<()> { fn apply_double_removal() -> Result<()> {
let mut fixes = vec![ let mut fixes = vec![
Fix { Fix {
content: "".to_string(), patch: Patch {
location: Location::new(1, 8), content: "".to_string(),
end_location: Location::new(1, 17), location: Location::new(1, 8),
end_location: Location::new(1, 17),
},
applied: false, applied: false,
}, },
Fix { Fix {
content: "".to_string(), patch: Patch {
location: Location::new(1, 17), content: "".to_string(),
end_location: Location::new(1, 24), location: Location::new(1, 17),
end_location: Location::new(1, 24),
},
applied: false, applied: false,
}, },
]; ];
@ -186,15 +208,19 @@ mod tests {
fn ignore_overlapping_fixes() -> Result<()> { fn ignore_overlapping_fixes() -> Result<()> {
let mut fixes = vec![ let mut fixes = vec![
Fix { Fix {
content: "".to_string(), patch: Patch {
location: Location::new(1, 8), content: "".to_string(),
end_location: Location::new(1, 16), location: Location::new(1, 8),
end_location: Location::new(1, 16),
},
applied: false, applied: false,
}, },
Fix { Fix {
content: "ignored".to_string(), patch: Patch {
location: Location::new(1, 10), content: "ignored".to_string(),
end_location: Location::new(1, 12), location: Location::new(1, 10),
end_location: Location::new(1, 12),
},
applied: false, applied: false,
}, },
]; ];

View file

@ -9,7 +9,7 @@ use rustpython_parser::token::Tok;
use crate::ast::operations::SourceCodeLocator; use crate::ast::operations::SourceCodeLocator;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::checks::Fix; use crate::autofix::Fix;
/// Convert a location within a file (relative to `base`) to an absolute position. /// Convert a location within a file (relative to `base`) to an absolute position.
fn to_absolute(relative: &Location, base: &Location) -> Location { fn to_absolute(relative: &Location, base: &Location) -> Location {
@ -56,12 +56,7 @@ pub fn remove_class_def_base(
} }
return match (fix_start, fix_end) { return match (fix_start, fix_end) {
(Some(start), Some(end)) => Some(Fix { (Some(start), Some(end)) => Some(Fix::replacement("".to_string(), start, end)),
content: "".to_string(),
location: start,
end_location: end,
applied: false,
}),
_ => None, _ => None,
}; };
} }
@ -95,12 +90,7 @@ pub fn remove_class_def_base(
} }
match (fix_start, fix_end) { match (fix_start, fix_end) {
(Some(start), Some(end)) => Some(Fix { (Some(start), Some(end)) => Some(Fix::replacement("".to_string(), start, end)),
content: "".to_string(),
location: start,
end_location: end,
applied: false,
}),
_ => None, _ => None,
} }
} else { } else {
@ -120,12 +110,7 @@ pub fn remove_class_def_base(
} }
match (fix_start, fix_end) { match (fix_start, fix_end) {
(Some(start), Some(end)) => Some(Fix { (Some(start), Some(end)) => Some(Fix::replacement("".to_string(), start, end)),
content: "".to_string(),
location: start,
end_location: end,
applied: false,
}),
_ => None, _ => None,
} }
} }
@ -150,12 +135,11 @@ pub fn remove_super_arguments(locator: &mut SourceCodeLocator, expr: &Expr) -> O
let mut state = Default::default(); let mut state = Default::default();
tree.codegen(&mut state); tree.codegen(&mut state);
return Some(Fix { return Some(Fix::replacement(
content: state.to_string(), state.to_string(),
location: range.location, range.location,
end_location: range.end_location, range.end_location,
applied: false, ));
});
} }
} }
} }
@ -232,21 +216,18 @@ pub fn remove_stmt(stmt: &Stmt, parent: Option<&Stmt>, deleted: &[&Stmt]) -> Res
{ {
// If removing this node would lead to an invalid syntax tree, replace // If removing this node would lead to an invalid syntax tree, replace
// it with a `pass`. // it with a `pass`.
Ok(Fix { Ok(Fix::replacement(
location: stmt.location, "pass".to_string(),
end_location: stmt.end_location.unwrap(), stmt.location,
content: "pass".to_string(), stmt.end_location.unwrap(),
applied: false, ))
})
} else { } else {
// Otherwise, nuke the entire line. // Otherwise, nuke the entire line.
// TODO(charlie): This logic assumes that there are no multi-statement physical lines. // TODO(charlie): This logic assumes that there are no multi-statement physical lines.
Ok(Fix { Ok(Fix::deletion(
location: Location::new(stmt.location.row(), 1), Location::new(stmt.location.row(), 1),
end_location: Location::new(stmt.end_location.unwrap().row() + 1, 1), Location::new(stmt.end_location.unwrap().row() + 1, 1),
content: "".to_string(), ))
applied: false,
})
} }
} }
@ -307,12 +288,11 @@ pub fn remove_unused_imports(
let mut state = Default::default(); let mut state = Default::default();
tree.codegen(&mut state); tree.codegen(&mut state);
Ok(Fix { Ok(Fix::replacement(
content: state.to_string(), state.to_string(),
location: stmt.location, stmt.location,
end_location: stmt.end_location.unwrap(), stmt.end_location.unwrap(),
applied: false, ))
})
} }
} }
@ -382,11 +362,10 @@ pub fn remove_unused_import_froms(
let mut state = Default::default(); let mut state = Default::default();
tree.codegen(&mut state); tree.codegen(&mut state);
Ok(Fix { Ok(Fix::replacement(
content: state.to_string(), state.to_string(),
location: stmt.location, stmt.location,
end_location: stmt.end_location.unwrap(), stmt.end_location.unwrap(),
applied: false, ))
})
} }
} }

View file

@ -1,2 +1,53 @@
use rustpython_ast::Location;
use serde::{Deserialize, Serialize};
pub mod fixer; pub mod fixer;
pub mod fixes; pub mod fixes;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct Patch {
pub content: String,
pub location: Location,
pub end_location: Location,
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Fix {
pub patch: Patch,
pub applied: bool,
}
impl Fix {
pub fn deletion(start: Location, end: Location) -> Self {
Self {
patch: Patch {
content: "".to_string(),
location: start,
end_location: end,
},
applied: false,
}
}
pub fn replacement(content: String, start: Location, end: Location) -> Self {
Self {
patch: Patch {
content,
location: start,
end_location: end,
},
applied: false,
}
}
pub fn insertion(content: String, at: Location) -> Self {
Self {
patch: Patch {
content,
location: at,
end_location: at,
},
applied: false,
}
}
}

View file

@ -4,7 +4,8 @@ use rustpython_parser::ast::Location;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::checks::{Check, CheckCode, CheckKind, Fix}; use crate::autofix::Fix;
use crate::checks::{Check, CheckCode, CheckKind};
use crate::noqa; use crate::noqa;
use crate::noqa::Directive; use crate::noqa::Directive;
use crate::settings::Settings; use crate::settings::Settings;
@ -166,15 +167,10 @@ pub fn check_lines(
}, },
); );
if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
check.amend(Fix { check.amend(Fix::deletion(
content: "".to_string(), Location::new(row + 1, start + 1),
location: Location::new(row + 1, start + 1), Location::new(row + 1, lines[row].chars().count() + 1),
end_location: Location::new( ));
row + 1,
lines[row].chars().count() + 1,
),
applied: false,
});
} }
line_checks.push(check); line_checks.push(check);
} }
@ -200,25 +196,16 @@ pub fn check_lines(
); );
if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
if valid_codes.is_empty() { if valid_codes.is_empty() {
check.amend(Fix { check.amend(Fix::deletion(
content: "".to_string(), Location::new(row + 1, start + 1),
location: Location::new(row + 1, start + 1), Location::new(row + 1, lines[row].chars().count() + 1),
end_location: Location::new( ));
row + 1,
lines[row].chars().count() + 1,
),
applied: false,
});
} else { } else {
check.amend(Fix { check.amend(Fix::replacement(
content: format!(" # noqa: {}", valid_codes.join(", ")), format!(" # noqa: {}", valid_codes.join(", ")),
location: Location::new(row + 1, start + 1), Location::new(row + 1, start + 1),
end_location: Location::new( Location::new(row + 1, lines[row].chars().count() + 1),
row + 1, ));
lines[row].chars().count() + 1,
),
applied: false,
});
} }
} }
line_checks.push(check); line_checks.push(check);

View file

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
use strum_macros::{AsRefStr, EnumIter, EnumString}; use strum_macros::{AsRefStr, EnumIter, EnumString};
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::Fix;
use crate::pyupgrade::types::Primitive; use crate::pyupgrade::types::Primitive;
#[derive( #[derive(
@ -293,6 +294,7 @@ pub enum CheckKind {
// pydocstyle // pydocstyle
BlankLineAfterLastSection(String), BlankLineAfterLastSection(String),
BlankLineAfterSection(String), BlankLineAfterSection(String),
BlankLineAfterSummary,
BlankLineBeforeSection(String), BlankLineBeforeSection(String),
CapitalizeSectionName(String), CapitalizeSectionName(String),
DashedUnderlineAfterSection(String), DashedUnderlineAfterSection(String),
@ -308,7 +310,6 @@ pub enum CheckKind {
NewLineAfterLastParagraph, NewLineAfterLastParagraph,
NewLineAfterSectionName(String), NewLineAfterSectionName(String),
NoBlankLineAfterFunction(usize), NoBlankLineAfterFunction(usize),
NoBlankLineAfterSummary,
NoBlankLineBeforeClass(usize), NoBlankLineBeforeClass(usize),
NoBlankLineBeforeFunction(usize), NoBlankLineBeforeFunction(usize),
NoBlankLinesBetweenHeaderAndContent(String), NoBlankLinesBetweenHeaderAndContent(String),
@ -473,7 +474,7 @@ impl CheckCode {
CheckCode::D202 => CheckKind::NoBlankLineAfterFunction(1), CheckCode::D202 => CheckKind::NoBlankLineAfterFunction(1),
CheckCode::D203 => CheckKind::OneBlankLineBeforeClass(0), CheckCode::D203 => CheckKind::OneBlankLineBeforeClass(0),
CheckCode::D204 => CheckKind::OneBlankLineAfterClass(0), CheckCode::D204 => CheckKind::OneBlankLineAfterClass(0),
CheckCode::D205 => CheckKind::NoBlankLineAfterSummary, CheckCode::D205 => CheckKind::BlankLineAfterSummary,
CheckCode::D206 => CheckKind::IndentWithSpaces, CheckCode::D206 => CheckKind::IndentWithSpaces,
CheckCode::D207 => CheckKind::NoUnderIndentation, CheckCode::D207 => CheckKind::NoUnderIndentation,
CheckCode::D208 => CheckKind::NoOverIndentation, CheckCode::D208 => CheckKind::NoOverIndentation,
@ -756,7 +757,7 @@ impl CheckKind {
CheckKind::NewLineAfterLastParagraph => &CheckCode::D209, CheckKind::NewLineAfterLastParagraph => &CheckCode::D209,
CheckKind::NewLineAfterSectionName(_) => &CheckCode::D406, CheckKind::NewLineAfterSectionName(_) => &CheckCode::D406,
CheckKind::NoBlankLineAfterFunction(_) => &CheckCode::D202, CheckKind::NoBlankLineAfterFunction(_) => &CheckCode::D202,
CheckKind::NoBlankLineAfterSummary => &CheckCode::D205, CheckKind::BlankLineAfterSummary => &CheckCode::D205,
CheckKind::NoBlankLineBeforeClass(_) => &CheckCode::D211, CheckKind::NoBlankLineBeforeClass(_) => &CheckCode::D211,
CheckKind::NoBlankLineBeforeFunction(_) => &CheckCode::D201, CheckKind::NoBlankLineBeforeFunction(_) => &CheckCode::D201,
CheckKind::NoBlankLinesBetweenHeaderAndContent(_) => &CheckCode::D412, CheckKind::NoBlankLinesBetweenHeaderAndContent(_) => &CheckCode::D412,
@ -1053,7 +1054,7 @@ impl CheckKind {
} }
// pydocstyle // pydocstyle
CheckKind::FitsOnOneLine => "One-line docstring should fit on one line".to_string(), CheckKind::FitsOnOneLine => "One-line docstring should fit on one line".to_string(),
CheckKind::NoBlankLineAfterSummary => { CheckKind::BlankLineAfterSummary => {
"1 blank line required between summary line and description".to_string() "1 blank line required between summary line and description".to_string()
} }
CheckKind::NewLineAfterLastParagraph => { CheckKind::NewLineAfterLastParagraph => {
@ -1205,19 +1206,24 @@ impl CheckKind {
self, self,
CheckKind::BlankLineAfterLastSection(_) CheckKind::BlankLineAfterLastSection(_)
| CheckKind::BlankLineAfterSection(_) | CheckKind::BlankLineAfterSection(_)
| CheckKind::BlankLineAfterSummary
| CheckKind::BlankLineBeforeSection(_)
| CheckKind::DashedUnderlineAfterSection(_)
| CheckKind::DeprecatedUnittestAlias(_, _) | CheckKind::DeprecatedUnittestAlias(_, _)
| CheckKind::DoNotAssertFalse | CheckKind::DoNotAssertFalse
| CheckKind::DuplicateHandlerException(_) | CheckKind::DuplicateHandlerException(_)
| CheckKind::NewLineAfterLastParagraph | CheckKind::NewLineAfterLastParagraph
| CheckKind::NoBlankLineAfterFunction(_) | CheckKind::NoBlankLineAfterFunction(_)
| CheckKind::NoBlankLineAfterSummary
| CheckKind::NoBlankLineBeforeClass(_) | CheckKind::NoBlankLineBeforeClass(_)
| CheckKind::NoBlankLineBeforeFunction(_) | CheckKind::NoBlankLineBeforeFunction(_)
| CheckKind::NoBlankLinesBetweenHeaderAndContent(_)
| CheckKind::NoSurroundingWhitespace | CheckKind::NoSurroundingWhitespace
| CheckKind::OneBlankLineAfterClass(_) | CheckKind::OneBlankLineAfterClass(_)
| CheckKind::OneBlankLineBeforeClass(_) | CheckKind::OneBlankLineBeforeClass(_)
| CheckKind::PPrintFound | CheckKind::PPrintFound
| CheckKind::PrintFound | CheckKind::PrintFound
| CheckKind::SectionUnderlineMatchesSectionLength(_)
| CheckKind::SectionUnderlineNotOverIndented(_)
| CheckKind::SuperCallWithParameters | CheckKind::SuperCallWithParameters
| CheckKind::TypeOfPrimitive(_) | CheckKind::TypeOfPrimitive(_)
| CheckKind::UnnecessaryAbspath | CheckKind::UnnecessaryAbspath
@ -1231,43 +1237,6 @@ impl CheckKind {
} }
} }
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Fix {
pub content: String,
pub location: Location,
pub end_location: Location,
pub applied: bool,
}
impl Fix {
pub fn deletion(start: Location, end: Location) -> Self {
Self {
content: "".to_string(),
location: start,
end_location: end,
applied: false,
}
}
pub fn replacement(content: String, start: Location, end: Location) -> Self {
Self {
content,
location: start,
end_location: end,
applied: false,
}
}
pub fn insertion(content: String, at: Location) -> Self {
Self {
content,
location: at,
end_location: at,
applied: false,
}
}
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Check { pub struct Check {
pub kind: CheckKind, pub kind: CheckKind,
@ -1277,11 +1246,11 @@ pub struct Check {
} }
impl Check { impl Check {
pub fn new(kind: CheckKind, rage: Range) -> Self { pub fn new(kind: CheckKind, range: Range) -> Self {
Self { Self {
kind, kind,
location: rage.location, location: range.location,
end_location: rage.end_location, end_location: range.end_location,
fix: None, fix: None,
} }
} }

View file

@ -2,8 +2,9 @@ use rustpython_ast::{Constant, Expr, ExprContext, ExprKind, Stmt, StmtKind};
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckKind, Fix}; use crate::checks::{Check, CheckKind};
use crate::code_gen::SourceGenerator; use crate::code_gen::SourceGenerator;
fn assertion_error(msg: &Option<Box<Expr>>) -> Stmt { fn assertion_error(msg: &Option<Box<Expr>>) -> Stmt {
@ -47,12 +48,11 @@ pub fn assert_false(checker: &mut Checker, stmt: &Stmt, test: &Expr, msg: &Optio
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
if let Ok(()) = generator.unparse_stmt(&assertion_error(msg)) { if let Ok(()) = generator.unparse_stmt(&assertion_error(msg)) {
if let Ok(content) = generator.generate() { if let Ok(content) = generator.generate() {
check.amend(Fix { check.amend(Fix::replacement(
content, content,
location: stmt.location, stmt.location,
end_location: stmt.end_location.unwrap(), stmt.end_location.unwrap(),
applied: false, ));
})
} }
} }
} }

View file

@ -6,8 +6,9 @@ use rustpython_ast::{Excepthandler, ExcepthandlerKind, Expr, ExprContext, ExprKi
use crate::ast::helpers; use crate::ast::helpers;
use crate::ast::types::{CheckLocator, Range}; use crate::ast::types::{CheckLocator, Range};
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckCode, CheckKind, Fix}; use crate::checks::{Check, CheckCode, CheckKind};
use crate::code_gen::SourceGenerator; use crate::code_gen::SourceGenerator;
fn type_pattern(elts: Vec<&Expr>) -> Expr { fn type_pattern(elts: Vec<&Expr>) -> Expr {
@ -54,12 +55,11 @@ pub fn duplicate_handler_exceptions(
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
if let Ok(()) = generator.unparse_expr(&type_pattern(unique_elts), 0) { if let Ok(()) = generator.unparse_expr(&type_pattern(unique_elts), 0) {
if let Ok(content) = generator.generate() { if let Ok(content) = generator.generate() {
check.amend(Fix { check.amend(Fix::replacement(
content, content,
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ))
})
} }
} }
} }

View file

@ -31,7 +31,7 @@ pub fn print_call(checker: &mut Checker, expr: &Expr, func: &Expr) {
&deleted, &deleted,
) { ) {
Ok(fix) => { Ok(fix) => {
if fix.content.is_empty() || fix.content == "pass" { if fix.patch.content.is_empty() || fix.patch.content == "pass" {
checker.deletions.insert(context.defined_by); checker.deletions.insert(context.defined_by);
} }
check.amend(fix) check.amend(fix)

View file

@ -8,8 +8,9 @@ use titlecase::titlecase;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckCode, CheckKind, Fix}; use crate::checks::{Check, CheckCode, CheckKind};
use crate::docstrings::definition::{Definition, DefinitionKind}; use crate::docstrings::definition::{Definition, DefinitionKind};
use crate::docstrings::helpers; use crate::docstrings::helpers;
use crate::docstrings::sections::{section_contexts, SectionContext}; use crate::docstrings::sections::{section_contexts, SectionContext};
@ -180,6 +181,7 @@ pub fn blank_before_after_function(checker: &mut Checker, definition: &Definitio
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Delete the blank line before the docstring.
check.amend(Fix::deletion( check.amend(Fix::deletion(
Location::new(docstring.location.row() - blank_lines_before, 1), Location::new(docstring.location.row() - blank_lines_before, 1),
Location::new(docstring.location.row(), 1), Location::new(docstring.location.row(), 1),
@ -217,6 +219,7 @@ pub fn blank_before_after_function(checker: &mut Checker, definition: &Definitio
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Delete the blank line after the docstring.
check.amend(Fix::deletion( check.amend(Fix::deletion(
Location::new( Location::new(
docstring.location.row() + 1 + expected_blank_lines_after, docstring.location.row() + 1 + expected_blank_lines_after,
@ -266,6 +269,7 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply)
{ {
// Delete the blank line before the class.
check.amend(Fix::deletion( check.amend(Fix::deletion(
Location::new(docstring.location.row() - blank_lines_before, 1), Location::new(docstring.location.row() - blank_lines_before, 1),
Location::new(docstring.location.row(), 1), Location::new(docstring.location.row(), 1),
@ -282,6 +286,7 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply)
{ {
// Insert one blank line before the class.
check.amend(Fix::replacement( check.amend(Fix::replacement(
"\n".to_string(), "\n".to_string(),
Location::new(docstring.location.row() - blank_lines_before, 1), Location::new(docstring.location.row() - blank_lines_before, 1),
@ -313,6 +318,7 @@ pub fn blank_before_after_class(checker: &mut Checker, definition: &Definition)
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Insert a blank line before the class (replacing any existing lines).
check.amend(Fix::replacement( check.amend(Fix::replacement(
"\n".to_string(), "\n".to_string(),
Location::new(docstring.end_location.unwrap().row() + 1, 1), Location::new(docstring.end_location.unwrap().row() + 1, 1),
@ -350,10 +356,11 @@ pub fn blank_after_summary(checker: &mut Checker, definition: &Definition) {
} }
if lines_count > 1 && blanks_count != 1 { if lines_count > 1 && blanks_count != 1 {
let mut check = Check::new( let mut check = Check::new(
CheckKind::NoBlankLineAfterSummary, CheckKind::BlankLineAfterSummary,
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Insert one blank line after the summary (replacing any existing lines).
check.amend(Fix::replacement( check.amend(Fix::replacement(
"\n".to_string(), "\n".to_string(),
Location::new(docstring.location.row() + 1, 1), Location::new(docstring.location.row() + 1, 1),
@ -845,10 +852,22 @@ fn blanks_and_section_underline(
// Nothing but blank lines after the section header. // Nothing but blank lines after the section header.
if blank_lines_after_header == context.following_lines.len() { if blank_lines_after_header == context.following_lines.len() {
if checker.settings.enabled.contains(&CheckCode::D407) { if checker.settings.enabled.contains(&CheckCode::D407) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()), CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Add a dashed line (of the appropriate length) under the section header.
let mut content = "".to_string();
content.push_str(helpers::indentation(checker, docstring));
content.push_str(&"-".repeat(context.section_name.len()));
content.push('\n');
check.amend(Fix::insertion(
content,
Location::new(docstring.location.row() + context.original_index + 1, 1),
));
}
checker.add_check(check);
} }
if checker.settings.enabled.contains(&CheckCode::D414) { if checker.settings.enabled.contains(&CheckCode::D414) {
checker.add_check(Check::new( checker.add_check(Check::new(
@ -866,28 +885,68 @@ fn blanks_and_section_underline(
if !dash_line_found { if !dash_line_found {
if checker.settings.enabled.contains(&CheckCode::D407) { if checker.settings.enabled.contains(&CheckCode::D407) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()), CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Add a dashed line (of the appropriate length) under the section header.
let mut content = "".to_string();
content.push_str(helpers::indentation(checker, docstring));
content.push_str(&"-".repeat(context.section_name.len()));
content.push('\n');
check.amend(Fix::insertion(
content,
Location::new(docstring.location.row() + context.original_index + 1, 1),
));
}
checker.add_check(check);
} }
if blank_lines_after_header > 0 { if blank_lines_after_header > 0 {
if checker.settings.enabled.contains(&CheckCode::D212) { if checker.settings.enabled.contains(&CheckCode::D412) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::NoBlankLinesBetweenHeaderAndContent( CheckKind::NoBlankLinesBetweenHeaderAndContent(
context.section_name.to_string(), context.section_name.to_string(),
), ),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Delete any blank lines between the header and content.
check.amend(Fix::deletion(
Location::new(docstring.location.row() + context.original_index + 1, 1),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
1,
),
));
}
checker.add_check(check);
} }
} }
} else { } else {
if blank_lines_after_header > 0 { if blank_lines_after_header > 0 {
if checker.settings.enabled.contains(&CheckCode::D408) { if checker.settings.enabled.contains(&CheckCode::D408) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::SectionUnderlineAfterName(context.section_name.to_string()), CheckKind::SectionUnderlineAfterName(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Delete any blank lines between the header and the underline.
check.amend(Fix::deletion(
Location::new(docstring.location.row() + context.original_index + 1, 1),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
1,
),
));
}
checker.add_check(check);
} }
} }
@ -899,23 +958,70 @@ fn blanks_and_section_underline(
!= context.section_name.len() != context.section_name.len()
{ {
if checker.settings.enabled.contains(&CheckCode::D409) { if checker.settings.enabled.contains(&CheckCode::D409) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::SectionUnderlineMatchesSectionLength( CheckKind::SectionUnderlineMatchesSectionLength(
context.section_name.to_string(), context.section_name.to_string(),
), ),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Replace the existing underline with a line of the appropriate length.
let mut content = "".to_string();
content.push_str(helpers::indentation(checker, docstring));
content.push_str(&"-".repeat(context.section_name.len()));
content.push('\n');
check.amend(Fix::replacement(
content,
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
1,
),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header
+ 1,
1,
),
));
};
checker.add_check(check);
} }
} }
if checker.settings.enabled.contains(&CheckCode::D215) { if checker.settings.enabled.contains(&CheckCode::D215) {
if helpers::leading_space(non_empty_line).len() let leading_space = helpers::leading_space(non_empty_line);
> helpers::indentation(checker, docstring).len() let indentation = helpers::indentation(checker, docstring).to_string();
{ if leading_space.len() > indentation.len() {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::SectionUnderlineNotOverIndented(context.section_name.to_string()), CheckKind::SectionUnderlineNotOverIndented(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Replace the existing indentation with whitespace of the appropriate length.
check.amend(Fix::replacement(
indentation,
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
1,
),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
1 + leading_space.len(),
),
));
};
checker.add_check(check);
} }
} }
@ -925,7 +1031,11 @@ fn blanks_and_section_underline(
let line_after_dashes = context.following_lines[line_after_dashes_index]; let line_after_dashes = context.following_lines[line_after_dashes_index];
if line_after_dashes.trim().is_empty() { if line_after_dashes.trim().is_empty() {
let rest_of_lines = &context.following_lines[line_after_dashes_index..]; let rest_of_lines = &context.following_lines[line_after_dashes_index..];
if rest_of_lines.iter().all(|line| line.trim().is_empty()) { let blank_lines_after_dashes = rest_of_lines
.iter()
.take_while(|line| line.trim().is_empty())
.count();
if blank_lines_after_dashes == rest_of_lines.len() {
if checker.settings.enabled.contains(&CheckCode::D414) { if checker.settings.enabled.contains(&CheckCode::D414) {
checker.add_check(Check::new( checker.add_check(Check::new(
CheckKind::NonEmptySection(context.section_name.to_string()), CheckKind::NonEmptySection(context.section_name.to_string()),
@ -934,12 +1044,33 @@ fn blanks_and_section_underline(
} }
} else { } else {
if checker.settings.enabled.contains(&CheckCode::D412) { if checker.settings.enabled.contains(&CheckCode::D412) {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::NoBlankLinesBetweenHeaderAndContent( CheckKind::NoBlankLinesBetweenHeaderAndContent(
context.section_name.to_string(), context.section_name.to_string(),
), ),
Range::from_located(docstring), Range::from_located(docstring),
)); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Delete any blank lines between the header and content.
check.amend(Fix::deletion(
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ line_after_dashes_index,
1,
),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ line_after_dashes_index
+ blank_lines_after_dashes,
1,
),
));
}
checker.add_check(check);
} }
} }
} }
@ -1003,6 +1134,7 @@ fn common_section(
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Add a newline after the section.
check.amend(Fix::insertion( check.amend(Fix::insertion(
"\n".to_string(), "\n".to_string(),
Location::new( Location::new(
@ -1023,6 +1155,7 @@ fn common_section(
Range::from_located(docstring), Range::from_located(docstring),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Add a newline after the section.
check.amend(Fix::insertion( check.amend(Fix::insertion(
"\n".to_string(), "\n".to_string(),
Location::new( Location::new(
@ -1032,7 +1165,7 @@ fn common_section(
+ context.following_lines.len(), + context.following_lines.len(),
1, 1,
), ),
)) ));
} }
checker.add_check(check); checker.add_check(check);
} }
@ -1041,10 +1174,18 @@ fn common_section(
if checker.settings.enabled.contains(&CheckCode::D411) { if checker.settings.enabled.contains(&CheckCode::D411) {
if !context.previous_line.is_empty() { if !context.previous_line.is_empty() {
checker.add_check(Check::new( let mut check = Check::new(
CheckKind::BlankLineBeforeSection(context.section_name.to_string()), CheckKind::BlankLineBeforeSection(context.section_name.to_string()),
Range::from_located(docstring), Range::from_located(docstring),
)) );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
// Add a blank line before the section.
check.amend(Fix::insertion(
"\n".to_string(),
Location::new(docstring.location.row() + context.original_index, 1),
));
}
checker.add_check(check)
} }
} }

View file

@ -5,8 +5,9 @@ use rustpython_ast::{Expr, ExprKind};
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckKind, Fix}; use crate::checks::{Check, CheckKind};
static DEPRECATED_ALIASES: Lazy<BTreeMap<&'static str, &'static str>> = Lazy::new(|| { static DEPRECATED_ALIASES: Lazy<BTreeMap<&'static str, &'static str>> = Lazy::new(|| {
BTreeMap::from([ BTreeMap::from([
@ -38,12 +39,11 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) {
Range::from_located(expr), Range::from_located(expr),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
check.amend(Fix { check.amend(Fix::replacement(
content: format!("self.{}", target), format!("self.{}", target),
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ));
});
} }
checker.add_check(check); checker.add_check(check);
} }

View file

@ -2,8 +2,9 @@ use rustpython_ast::Expr;
use crate::ast::types::{CheckLocator, Range}; use crate::ast::types::{CheckLocator, Range};
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{CheckKind, Fix}; use crate::checks::CheckKind;
use crate::pyupgrade::checks; use crate::pyupgrade::checks;
pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
@ -12,12 +13,11 @@ pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args:
{ {
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
if let CheckKind::TypeOfPrimitive(primitive) = &check.kind { if let CheckKind::TypeOfPrimitive(primitive) = &check.kind {
check.amend(Fix { check.amend(Fix::replacement(
content: primitive.builtin(), primitive.builtin(),
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ));
});
} }
} }
checker.add_check(check); checker.add_check(check);

View file

@ -2,8 +2,8 @@ use rustpython_ast::Expr;
use crate::ast::types::{CheckLocator, Range}; use crate::ast::types::{CheckLocator, Range};
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::Fix;
use crate::pyupgrade::checks; use crate::pyupgrade::checks;
pub fn unnecessary_abspath(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { pub fn unnecessary_abspath(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) {
@ -11,12 +11,11 @@ pub fn unnecessary_abspath(checker: &mut Checker, expr: &Expr, func: &Expr, args
checks::unnecessary_abspath(func, args, checker.locate_check(Range::from_located(expr))) checks::unnecessary_abspath(func, args, checker.locate_check(Range::from_located(expr)))
{ {
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
check.amend(Fix { check.amend(Fix::replacement(
content: "__file__".to_string(), "__file__".to_string(),
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ));
});
} }
checker.add_check(check); checker.add_check(check);
} }

View file

@ -2,8 +2,9 @@ use rustpython_ast::Expr;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckKind, Fix}; use crate::checks::{Check, CheckKind};
use crate::python::typing; use crate::python::typing;
pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr, id: &str) { pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr, id: &str) {
@ -14,12 +15,11 @@ pub fn use_pep585_annotation(checker: &mut Checker, expr: &Expr, id: &str) {
Range::from_located(expr), Range::from_located(expr),
); );
if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) { if matches!(checker.autofix, fixer::Mode::Generate | fixer::Mode::Apply) {
check.amend(Fix { check.amend(Fix::replacement(
content: id.to_lowercase(), id.to_lowercase(),
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ));
})
} }
checker.add_check(check); checker.add_check(check);
} }

View file

@ -3,8 +3,9 @@ use rustpython_ast::{Constant, Expr, ExprKind, Operator};
use crate::ast::helpers::match_name_or_attr; use crate::ast::helpers::match_name_or_attr;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::fixer; use crate::autofix::fixer;
use crate::autofix::Fix;
use crate::check_ast::Checker; use crate::check_ast::Checker;
use crate::checks::{Check, CheckKind, Fix}; use crate::checks::{Check, CheckKind};
use crate::code_gen::SourceGenerator; use crate::code_gen::SourceGenerator;
fn optional(expr: &Expr) -> Expr { fn optional(expr: &Expr) -> Expr {
@ -49,12 +50,11 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
if let Ok(()) = generator.unparse_expr(&optional(slice), 0) { if let Ok(()) = generator.unparse_expr(&optional(slice), 0) {
if let Ok(content) = generator.generate() { if let Ok(content) = generator.generate() {
check.amend(Fix { check.amend(Fix::replacement(
content, content,
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ))
})
} }
} }
} }
@ -70,12 +70,11 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
if let Ok(()) = generator.unparse_expr(&union(elts), 0) { if let Ok(()) = generator.unparse_expr(&union(elts), 0) {
if let Ok(content) = generator.generate() { if let Ok(content) = generator.generate() {
check.amend(Fix { check.amend(Fix::replacement(
content, content,
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ))
})
} }
} }
} }
@ -84,12 +83,11 @@ pub fn use_pep604_annotation(checker: &mut Checker, expr: &Expr, value: &Expr, s
let mut generator = SourceGenerator::new(); let mut generator = SourceGenerator::new();
if let Ok(()) = generator.unparse_expr(slice, 0) { if let Ok(()) = generator.unparse_expr(slice, 0) {
if let Ok(content) = generator.generate() { if let Ok(content) = generator.generate() {
check.amend(Fix { check.amend(Fix::replacement(
content, content,
location: expr.location, expr.location,
end_location: expr.end_location.unwrap(), expr.end_location.unwrap(),
applied: false, ));
});
} }
} }
} }

View file

@ -26,7 +26,7 @@ pub fn useless_metaclass_type(checker: &mut Checker, stmt: &Stmt, value: &Expr,
&deleted, &deleted,
) { ) {
Ok(fix) => { Ok(fix) => {
if fix.content.is_empty() || fix.content == "pass" { if fix.patch.content.is_empty() || fix.patch.content == "pass" {
checker.deletions.insert(context.defined_by); checker.deletions.insert(context.defined_by);
} }
check.amend(fix) check.amend(fix)

View file

@ -10,13 +10,14 @@ expression: checks
row: 8 row: 8
column: 13 column: 13
fix: fix:
content: raise AssertionError() patch:
location: content: raise AssertionError()
row: 8 location:
column: 1 row: 8
end_location: column: 1
row: 8 end_location:
column: 13 row: 8
column: 13
applied: false applied: false
- kind: DoNotAssertFalse - kind: DoNotAssertFalse
location: location:
@ -26,12 +27,13 @@ expression: checks
row: 10 row: 10
column: 13 column: 13
fix: fix:
content: "raise AssertionError('message')" patch:
location: content: "raise AssertionError('message')"
row: 10 location:
column: 1 row: 10
end_location: column: 1
row: 10 end_location:
column: 24 row: 10
column: 24
applied: false applied: false

View file

@ -12,13 +12,14 @@ expression: checks
row: 17 row: 17
column: 25 column: 25
fix: fix:
content: "OSError," patch:
location: content: "OSError,"
row: 17 location:
column: 9 row: 17
end_location: column: 9
row: 17 end_location:
column: 25 row: 17
column: 25
applied: false applied: false
- kind: - kind:
DuplicateHandlerException: DuplicateHandlerException:
@ -30,13 +31,14 @@ expression: checks
row: 28 row: 28
column: 25 column: 25
fix: fix:
content: "MyError," patch:
location: content: "MyError,"
row: 28 location:
column: 9 row: 28
end_location: column: 9
row: 28 end_location:
column: 25 row: 28
column: 25
applied: false applied: false
- kind: - kind:
DuplicateHandlerException: DuplicateHandlerException:
@ -48,12 +50,13 @@ expression: checks
row: 49 row: 49
column: 27 column: 27
fix: fix:
content: "re.error," patch:
location: content: "re.error,"
row: 49 location:
column: 9 row: 49
end_location: column: 9
row: 49 end_location:
column: 27 row: 49
column: 27
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 132 row: 132
column: 25 column: 25
fix: fix:
content: "" patch:
location: content: ""
row: 131 location:
column: 1 row: 131
end_location: column: 1
row: 132 end_location:
column: 1 row: 132
column: 1
applied: false applied: false
- kind: - kind:
NoBlankLineBeforeFunction: 1 NoBlankLineBeforeFunction: 1
@ -28,12 +29,13 @@ expression: checks
row: 146 row: 146
column: 38 column: 38
fix: fix:
content: "" patch:
location: content: ""
row: 145 location:
column: 1 row: 145
end_location: column: 1
row: 146 end_location:
column: 1 row: 146
column: 1
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 79 row: 79
column: 33 column: 33
fix: fix:
content: "" patch:
location: content: ""
row: 81 location:
column: 1 row: 81
end_location: column: 1
row: 80 end_location:
column: 1 row: 80
column: 1
applied: false applied: false
- kind: - kind:
NoBlankLineAfterFunction: 1 NoBlankLineAfterFunction: 1
@ -28,13 +29,14 @@ expression: checks
row: 137 row: 137
column: 25 column: 25
fix: fix:
content: "" patch:
location: content: ""
row: 138 location:
column: 1 row: 138
end_location: column: 1
row: 139 end_location:
column: 1 row: 139
column: 1
applied: false applied: false
- kind: - kind:
NoBlankLineAfterFunction: 1 NoBlankLineAfterFunction: 1
@ -45,13 +47,14 @@ expression: checks
row: 146 row: 146
column: 38 column: 38
fix: fix:
content: "" patch:
location: content: ""
row: 147 location:
column: 1 row: 147
end_location: column: 1
row: 148 end_location:
column: 1 row: 148
column: 1
applied: false applied: false
- kind: - kind:
NoBlankLineAfterFunction: 0 NoBlankLineAfterFunction: 0
@ -62,12 +65,13 @@ expression: checks
row: 453 row: 453
column: 24 column: 24
fix: fix:
content: "" patch:
location: content: ""
row: 455 location:
column: 1 row: 455
end_location: column: 1
row: 454 end_location:
column: 1 row: 454
column: 1
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 156 row: 156
column: 33 column: 33
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 156 location:
column: 1 row: 156
end_location: column: 1
row: 156 end_location:
column: 1 row: 156
column: 1
applied: false applied: false
- kind: - kind:
OneBlankLineBeforeClass: 0 OneBlankLineBeforeClass: 0
@ -28,13 +29,14 @@ expression: checks
row: 187 row: 187
column: 46 column: 46
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 187 location:
column: 1 row: 187
end_location: column: 1
row: 187 end_location:
column: 1 row: 187
column: 1
applied: false applied: false
- kind: - kind:
OneBlankLineBeforeClass: 0 OneBlankLineBeforeClass: 0
@ -45,12 +47,13 @@ expression: checks
row: 527 row: 527
column: 8 column: 8
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 521 location:
column: 1 row: 521
end_location: column: 1
row: 521 end_location:
column: 1 row: 521
column: 1
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 176 row: 176
column: 25 column: 25
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 177 location:
column: 1 row: 177
end_location: column: 1
row: 177 end_location:
column: 1 row: 177
column: 1
applied: false applied: false
- kind: - kind:
OneBlankLineAfterClass: 0 OneBlankLineAfterClass: 0
@ -28,12 +29,13 @@ expression: checks
row: 187 row: 187
column: 46 column: 46
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 188 location:
column: 1 row: 188
end_location: column: 1
row: 188 end_location:
column: 1 row: 188
column: 1
applied: false applied: false

View file

@ -2,7 +2,7 @@
source: src/linter.rs source: src/linter.rs
expression: checks expression: checks
--- ---
- kind: NoBlankLineAfterSummary - kind: BlankLineAfterSummary
location: location:
row: 195 row: 195
column: 5 column: 5
@ -10,15 +10,16 @@ expression: checks
row: 198 row: 198
column: 8 column: 8
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 196 location:
column: 1 row: 196
end_location: column: 1
row: 196 end_location:
column: 1 row: 196
column: 1
applied: false applied: false
- kind: NoBlankLineAfterSummary - kind: BlankLineAfterSummary
location: location:
row: 205 row: 205
column: 5 column: 5
@ -26,12 +27,13 @@ expression: checks
row: 210 row: 210
column: 8 column: 8
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 206 location:
column: 1 row: 206
end_location: column: 1
row: 208 end_location:
column: 1 row: 208
column: 1
applied: false applied: false

View file

@ -10,12 +10,13 @@ expression: checks
row: 278 row: 278
column: 20 column: 20
fix: fix:
content: "\n " patch:
location: content: "\n "
row: 278 location:
column: 17 row: 278
end_location: column: 17
row: 278 end_location:
column: 17 row: 278
column: 17
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 283 row: 283
column: 34 column: 34
fix: fix:
content: Whitespace at the end. patch:
location: content: Whitespace at the end.
row: 283 location:
column: 8 row: 283
end_location: column: 8
row: 283 end_location:
column: 31 row: 283
column: 31
applied: false applied: false
- kind: NoSurroundingWhitespace - kind: NoSurroundingWhitespace
location: location:
@ -26,13 +27,14 @@ expression: checks
row: 288 row: 288
column: 38 column: 38
fix: fix:
content: Whitespace at everywhere. patch:
location: content: Whitespace at everywhere.
row: 288 location:
column: 8 row: 288
end_location: column: 8
row: 288 end_location:
column: 35 row: 288
column: 35
applied: false applied: false
- kind: NoSurroundingWhitespace - kind: NoSurroundingWhitespace
location: location:
@ -42,12 +44,13 @@ expression: checks
row: 297 row: 297
column: 8 column: 8
fix: fix:
content: Whitespace at the beginning. patch:
location: content: Whitespace at the beginning.
row: 294 location:
column: 8 row: 294
end_location: column: 8
row: 294 end_location:
column: 37 row: 294
column: 37
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 165 row: 165
column: 30 column: 30
fix: fix:
content: "" patch:
location: content: ""
row: 164 location:
column: 1 row: 164
end_location: column: 1
row: 165 end_location:
column: 1 row: 165
column: 1
applied: false applied: false
- kind: - kind:
NoBlankLineBeforeClass: 1 NoBlankLineBeforeClass: 1
@ -28,12 +29,13 @@ expression: checks
row: 176 row: 176
column: 25 column: 25
fix: fix:
content: "" patch:
location: content: ""
row: 175 location:
column: 1 row: 175
end_location: column: 1
row: 176 end_location:
column: 1 row: 176
column: 1
applied: false applied: false

View file

@ -10,7 +10,16 @@ expression: checks
end_location: end_location:
row: 153 row: 153
column: 8 column: 8
fix: ~ fix:
patch:
content: " "
location:
row: 150
column: 1
end_location:
row: 150
column: 9
applied: false
- kind: - kind:
SectionUnderlineNotOverIndented: Returns SectionUnderlineNotOverIndented: Returns
location: location:
@ -19,5 +28,14 @@ expression: checks
end_location: end_location:
row: 165 row: 165
column: 8 column: 8
fix: ~ fix:
patch:
content: " "
location:
row: 164
column: 1
end_location:
row: 164
column: 9
applied: false

View file

@ -10,7 +10,16 @@ expression: checks
end_location: end_location:
row: 47 row: 47
column: 8 column: 8
fix: ~ fix:
patch:
content: " -------\n"
location:
row: 45
column: 1
end_location:
row: 45
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Returns DashedUnderlineAfterSection: Returns
location: location:
@ -19,7 +28,16 @@ expression: checks
end_location: end_location:
row: 58 row: 58
column: 8 column: 8
fix: ~ fix:
patch:
content: " -------\n"
location:
row: 57
column: 1
end_location:
row: 57
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Raises DashedUnderlineAfterSection: Raises
location: location:
@ -28,7 +46,16 @@ expression: checks
end_location: end_location:
row: 221 row: 221
column: 8 column: 8
fix: ~ fix:
patch:
content: " ------\n"
location:
row: 219
column: 1
end_location:
row: 219
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Returns DashedUnderlineAfterSection: Returns
location: location:
@ -37,7 +64,16 @@ expression: checks
end_location: end_location:
row: 262 row: 262
column: 8 column: 8
fix: ~ fix:
patch:
content: " -------\n"
location:
row: 258
column: 1
end_location:
row: 258
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Raises DashedUnderlineAfterSection: Raises
location: location:
@ -46,7 +82,16 @@ expression: checks
end_location: end_location:
row: 262 row: 262
column: 8 column: 8
fix: ~ fix:
patch:
content: " ------\n"
location:
row: 260
column: 1
end_location:
row: 260
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -55,7 +100,16 @@ expression: checks
end_location: end_location:
row: 274 row: 274
column: 8 column: 8
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 272
column: 1
end_location:
row: 272
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -64,7 +118,16 @@ expression: checks
end_location: end_location:
row: 292 row: 292
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 289
column: 1
end_location:
row: 289
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -73,7 +136,16 @@ expression: checks
end_location: end_location:
row: 306 row: 306
column: 8 column: 8
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 304
column: 1
end_location:
row: 304
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -82,7 +154,16 @@ expression: checks
end_location: end_location:
row: 319 row: 319
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 316
column: 1
end_location:
row: 316
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -91,7 +172,16 @@ expression: checks
end_location: end_location:
row: 330 row: 330
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 328
column: 1
end_location:
row: 328
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -100,7 +190,16 @@ expression: checks
end_location: end_location:
row: 343 row: 343
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 340
column: 1
end_location:
row: 340
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -109,7 +208,16 @@ expression: checks
end_location: end_location:
row: 355 row: 355
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 353
column: 1
end_location:
row: 353
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -118,7 +226,16 @@ expression: checks
end_location: end_location:
row: 367 row: 367
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 365
column: 1
end_location:
row: 365
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -127,7 +244,16 @@ expression: checks
end_location: end_location:
row: 382 row: 382
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 374
column: 1
end_location:
row: 374
column: 1
applied: false
- kind: - kind:
DashedUnderlineAfterSection: Args DashedUnderlineAfterSection: Args
location: location:
@ -136,5 +262,14 @@ expression: checks
end_location: end_location:
row: 497 row: 497
column: 12 column: 12
fix: ~ fix:
patch:
content: " ----\n"
location:
row: 495
column: 1
end_location:
row: 495
column: 1
applied: false

View file

@ -10,5 +10,14 @@ expression: checks
end_location: end_location:
row: 92 row: 92
column: 8 column: 8
fix: ~ fix:
patch:
content: ""
location:
row: 88
column: 1
end_location:
row: 89
column: 1
applied: false

View file

@ -10,7 +10,16 @@ expression: checks
end_location: end_location:
row: 105 row: 105
column: 8 column: 8
fix: ~ fix:
patch:
content: " -------\n"
location:
row: 102
column: 1
end_location:
row: 103
column: 1
applied: false
- kind: - kind:
SectionUnderlineMatchesSectionLength: Returns SectionUnderlineMatchesSectionLength: Returns
location: location:
@ -19,5 +28,14 @@ expression: checks
end_location: end_location:
row: 221 row: 221
column: 8 column: 8
fix: ~ fix:
patch:
content: " -------\n"
location:
row: 216
column: 1
end_location:
row: 217
column: 1
applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 78 row: 78
column: 8 column: 8
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 71 location:
column: 1 row: 71
end_location: column: 1
row: 71 end_location:
column: 1 row: 71
column: 1
applied: false applied: false
- kind: - kind:
BlankLineAfterSection: Returns BlankLineAfterSection: Returns
@ -28,12 +29,13 @@ expression: checks
row: 221 row: 221
column: 8 column: 8
fix: fix:
content: "\n" patch:
location: content: "\n"
row: 218 location:
column: 1 row: 218
end_location: column: 1
row: 218 end_location:
column: 1 row: 218
column: 1
applied: false applied: false

View file

@ -10,7 +10,16 @@ expression: checks
end_location: end_location:
row: 78 row: 78
column: 8 column: 8
fix: ~ fix:
patch:
content: "\n"
location:
row: 71
column: 1
end_location:
row: 71
column: 1
applied: false
- kind: - kind:
BlankLineBeforeSection: Returns BlankLineBeforeSection: Returns
location: location:
@ -19,7 +28,16 @@ expression: checks
end_location: end_location:
row: 129 row: 129
column: 8 column: 8
fix: ~ fix:
patch:
content: "\n"
location:
row: 125
column: 1
end_location:
row: 125
column: 1
applied: false
- kind: - kind:
BlankLineBeforeSection: Raises BlankLineBeforeSection: Raises
location: location:
@ -28,5 +46,14 @@ expression: checks
end_location: end_location:
row: 221 row: 221
column: 8 column: 8
fix: ~ fix:
patch:
content: "\n"
location:
row: 218
column: 1
end_location:
row: 218
column: 1
applied: false

View file

@ -10,5 +10,14 @@ expression: checks
end_location: end_location:
row: 221 row: 221
column: 8 column: 8
fix: ~ fix:
patch:
content: ""
location:
row: 211
column: 1
end_location:
row: 212
column: 1
applied: false

View file

@ -12,13 +12,14 @@ expression: checks
row: 2 row: 2
column: 21 column: 21
fix: fix:
content: import os patch:
location: content: import os
row: 2 location:
column: 1 row: 2
end_location: column: 1
row: 2 end_location:
column: 21 row: 2
column: 21
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -30,13 +31,14 @@ expression: checks
row: 8 row: 8
column: 2 column: 2
fix: fix:
content: "from collections import (\n Counter,\n namedtuple,\n)" patch:
location: content: "from collections import (\n Counter,\n namedtuple,\n)"
row: 4 location:
column: 1 row: 4
end_location: column: 1
row: 8 end_location:
column: 2 row: 8
column: 2
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -48,13 +50,14 @@ expression: checks
row: 12 row: 12
column: 24 column: 24
fix: fix:
content: import logging.handlers patch:
location: content: import logging.handlers
row: 12 location:
column: 1 row: 12
end_location: column: 1
row: 12 end_location:
column: 24 row: 12
column: 24
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -66,13 +69,14 @@ expression: checks
row: 33 row: 33
column: 18 column: 18
fix: fix:
content: "" patch:
location: content: ""
row: 33 location:
column: 1 row: 33
end_location: column: 1
row: 34 end_location:
column: 1 row: 34
column: 1
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -84,13 +88,14 @@ expression: checks
row: 34 row: 34
column: 21 column: 21
fix: fix:
content: "" patch:
location: content: ""
row: 34 location:
column: 1 row: 34
end_location: column: 1
row: 35 end_location:
column: 1 row: 35
column: 1
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -102,13 +107,14 @@ expression: checks
row: 38 row: 38
column: 19 column: 19
fix: fix:
content: "" patch:
location: content: ""
row: 38 location:
column: 1 row: 38
end_location: column: 1
row: 39 end_location:
column: 1 row: 39
column: 1
applied: false applied: false
- kind: - kind:
UnusedImport: UnusedImport:
@ -120,12 +126,13 @@ expression: checks
row: 53 row: 53
column: 22 column: 22
fix: fix:
content: pass patch:
location: content: pass
row: 53 location:
column: 9 row: 53
end_location: column: 9
row: 53 end_location:
column: 22 row: 53
column: 22
applied: false applied: false

View file

@ -10,12 +10,13 @@ expression: checks
row: 1 row: 1
column: 23 column: 23
fix: fix:
content: "" patch:
location: content: ""
row: 1 location:
column: 1 row: 1
end_location: column: 1
row: 2 end_location:
column: 1 row: 2
column: 1
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 3 row: 3
column: 24 column: 24
fix: fix:
content: "" patch:
location: content: ""
row: 3 location:
column: 1 row: 3
end_location: column: 1
row: 4 end_location:
column: 1 row: 4
column: 1
applied: false applied: false
- kind: PPrintFound - kind: PPrintFound
location: location:
@ -26,12 +27,13 @@ expression: checks
row: 8 row: 8
column: 31 column: 31
fix: fix:
content: "" patch:
location: content: ""
row: 8 location:
column: 1 row: 8
end_location: column: 1
row: 9 end_location:
column: 1 row: 9
column: 1
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 2 row: 2
column: 25 column: 25
fix: fix:
content: pass patch:
location: content: pass
row: 2 location:
column: 5 row: 2
end_location: column: 5
row: 2 end_location:
column: 25 row: 2
column: 25
applied: false applied: false
- kind: UselessMetaclassType - kind: UselessMetaclassType
location: location:
@ -26,12 +27,13 @@ expression: checks
row: 6 row: 6
column: 25 column: 25
fix: fix:
content: "" patch:
location: content: ""
row: 6 location:
column: 1 row: 6
end_location: column: 1
row: 7 end_location:
column: 1 row: 7
column: 1
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 3 row: 3
column: 22 column: 22
fix: fix:
content: __file__ patch:
location: content: __file__
row: 3 location:
column: 5 row: 3
end_location: column: 5
row: 3 end_location:
column: 22 row: 3
column: 22
applied: false applied: false
- kind: UnnecessaryAbspath - kind: UnnecessaryAbspath
location: location:
@ -26,13 +27,14 @@ expression: checks
row: 9 row: 9
column: 30 column: 30
fix: fix:
content: __file__ patch:
location: content: __file__
row: 9 location:
column: 5 row: 9
end_location: column: 5
row: 9 end_location:
column: 30 row: 9
column: 30
applied: false applied: false
- kind: UnnecessaryAbspath - kind: UnnecessaryAbspath
location: location:
@ -42,12 +44,13 @@ expression: checks
row: 15 row: 15
column: 27 column: 27
fix: fix:
content: __file__ patch:
location: content: __file__
row: 15 location:
column: 5 row: 15
end_location: column: 5
row: 15 end_location:
column: 27 row: 15
column: 27
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 1 row: 1
column: 9 column: 9
fix: fix:
content: str patch:
location: content: str
row: 1 location:
column: 1 row: 1
end_location: column: 1
row: 1 end_location:
column: 9 row: 1
column: 9
applied: false applied: false
- kind: - kind:
TypeOfPrimitive: Bytes TypeOfPrimitive: Bytes
@ -28,13 +29,14 @@ expression: checks
row: 2 row: 2
column: 10 column: 10
fix: fix:
content: bytes patch:
location: content: bytes
row: 2 location:
column: 1 row: 2
end_location: column: 1
row: 2 end_location:
column: 10 row: 2
column: 10
applied: false applied: false
- kind: - kind:
TypeOfPrimitive: Int TypeOfPrimitive: Int
@ -45,13 +47,14 @@ expression: checks
row: 3 row: 3
column: 8 column: 8
fix: fix:
content: int patch:
location: content: int
row: 3 location:
column: 1 row: 3
end_location: column: 1
row: 3 end_location:
column: 8 row: 3
column: 8
applied: false applied: false
- kind: - kind:
TypeOfPrimitive: Float TypeOfPrimitive: Float
@ -62,13 +65,14 @@ expression: checks
row: 4 row: 4
column: 9 column: 9
fix: fix:
content: float patch:
location: content: float
row: 4 location:
column: 1 row: 4
end_location: column: 1
row: 4 end_location:
column: 9 row: 4
column: 9
applied: false applied: false
- kind: - kind:
TypeOfPrimitive: Complex TypeOfPrimitive: Complex
@ -79,12 +83,13 @@ expression: checks
row: 5 row: 5
column: 9 column: 9
fix: fix:
content: complex patch:
location: content: complex
row: 5 location:
column: 1 row: 5
end_location: column: 1
row: 5 end_location:
column: 9 row: 5
column: 9
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 5 row: 5
column: 15 column: 15
fix: fix:
content: "" patch:
location: content: ""
row: 5 location:
column: 8 row: 5
end_location: column: 8
row: 5 end_location:
column: 16 row: 5
column: 16
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -28,13 +29,14 @@ expression: checks
row: 10 row: 10
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 9 location:
column: 8 row: 9
end_location: column: 8
row: 11 end_location:
column: 2 row: 11
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -45,13 +47,14 @@ expression: checks
row: 16 row: 16
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 15 location:
column: 8 row: 15
end_location: column: 8
row: 18 end_location:
column: 2 row: 18
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -62,13 +65,14 @@ expression: checks
row: 24 row: 24
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 22 location:
column: 8 row: 22
end_location: column: 8
row: 25 end_location:
column: 2 row: 25
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -79,13 +83,14 @@ expression: checks
row: 31 row: 31
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 29 location:
column: 8 row: 29
end_location: column: 8
row: 32 end_location:
column: 2 row: 32
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -96,13 +101,14 @@ expression: checks
row: 37 row: 37
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 36 location:
column: 8 row: 36
end_location: column: 8
row: 39 end_location:
column: 2 row: 39
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -113,13 +119,14 @@ expression: checks
row: 45 row: 45
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 43 location:
column: 8 row: 43
end_location: column: 8
row: 47 end_location:
column: 2 row: 47
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -130,13 +137,14 @@ expression: checks
row: 53 row: 53
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 51 location:
column: 8 row: 51
end_location: column: 8
row: 55 end_location:
column: 2 row: 55
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -147,13 +155,14 @@ expression: checks
row: 61 row: 61
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 59 location:
column: 8 row: 59
end_location: column: 8
row: 63 end_location:
column: 2 row: 63
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -164,13 +173,14 @@ expression: checks
row: 69 row: 69
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 67 location:
column: 8 row: 67
end_location: column: 8
row: 71 end_location:
column: 2 row: 71
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -181,13 +191,14 @@ expression: checks
row: 75 row: 75
column: 18 column: 18
fix: fix:
content: "" patch:
location: content: ""
row: 75 location:
column: 10 row: 75
end_location: column: 10
row: 75 end_location:
column: 18 row: 75
column: 18
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -198,13 +209,14 @@ expression: checks
row: 79 row: 79
column: 15 column: 15
fix: fix:
content: "" patch:
location: content: ""
row: 79 location:
column: 9 row: 79
end_location: column: 9
row: 79 end_location:
column: 17 row: 79
column: 17
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -215,13 +227,14 @@ expression: checks
row: 84 row: 84
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 84 location:
column: 5 row: 84
end_location: column: 5
row: 85 end_location:
column: 5 row: 85
column: 5
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -232,13 +245,14 @@ expression: checks
row: 92 row: 92
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 91 location:
column: 6 row: 91
end_location: column: 6
row: 92 end_location:
column: 11 row: 92
column: 11
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -249,13 +263,14 @@ expression: checks
row: 98 row: 98
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 98 location:
column: 5 row: 98
end_location: column: 5
row: 100 end_location:
column: 5 row: 100
column: 5
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: B UselessObjectInheritance: B
@ -266,13 +281,14 @@ expression: checks
row: 108 row: 108
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 107 location:
column: 6 row: 107
end_location: column: 6
row: 108 end_location:
column: 11 row: 108
column: 11
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -283,13 +299,14 @@ expression: checks
row: 114 row: 114
column: 19 column: 19
fix: fix:
content: "" patch:
location: content: ""
row: 114 location:
column: 12 row: 114
end_location: column: 12
row: 114 end_location:
column: 20 row: 114
column: 20
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -300,13 +317,14 @@ expression: checks
row: 119 row: 119
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 118 location:
column: 8 row: 118
end_location: column: 8
row: 120 end_location:
column: 2 row: 120
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -317,13 +335,14 @@ expression: checks
row: 125 row: 125
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 124 location:
column: 8 row: 124
end_location: column: 8
row: 126 end_location:
column: 2 row: 126
column: 2
applied: false applied: false
- kind: - kind:
UselessObjectInheritance: A UselessObjectInheritance: A
@ -334,12 +353,13 @@ expression: checks
row: 131 row: 131
column: 11 column: 11
fix: fix:
content: "" patch:
location: content: ""
row: 130 location:
column: 8 row: 130
end_location: column: 8
row: 133 end_location:
column: 2 row: 133
column: 2
applied: false applied: false

View file

@ -13,13 +13,14 @@ expression: checks
row: 6 row: 6
column: 26 column: 26
fix: fix:
content: self.assertEqual patch:
location: content: self.assertEqual
row: 6 location:
column: 9 row: 6
end_location: column: 9
row: 6 end_location:
column: 26 row: 6
column: 26
applied: false applied: false
- kind: - kind:
DeprecatedUnittestAlias: DeprecatedUnittestAlias:
@ -32,13 +33,14 @@ expression: checks
row: 7 row: 7
column: 26 column: 26
fix: fix:
content: self.assertEqual patch:
location: content: self.assertEqual
row: 7 location:
column: 9 row: 7
end_location: column: 9
row: 7 end_location:
column: 26 row: 7
column: 26
applied: false applied: false
- kind: - kind:
DeprecatedUnittestAlias: DeprecatedUnittestAlias:
@ -51,13 +53,14 @@ expression: checks
row: 9 row: 9
column: 35 column: 35
fix: fix:
content: self.assertAlmostEqual patch:
location: content: self.assertAlmostEqual
row: 9 location:
column: 9 row: 9
end_location: column: 9
row: 9 end_location:
column: 35 row: 9
column: 35
applied: false applied: false
- kind: - kind:
DeprecatedUnittestAlias: DeprecatedUnittestAlias:
@ -70,12 +73,13 @@ expression: checks
row: 10 row: 10
column: 36 column: 36
fix: fix:
content: self.assertNotRegex patch:
location: content: self.assertNotRegex
row: 10 location:
column: 9 row: 10
end_location: column: 9
row: 10 end_location:
column: 36 row: 10
column: 36
applied: false applied: false

View file

@ -11,13 +11,14 @@ expression: checks
row: 4 row: 4
column: 14 column: 14
fix: fix:
content: list patch:
location: content: list
row: 4 location:
column: 10 row: 4
end_location: column: 10
row: 4 end_location:
column: 14 row: 4
column: 14
applied: false applied: false
- kind: - kind:
UsePEP585Annotation: List UsePEP585Annotation: List
@ -28,12 +29,13 @@ expression: checks
row: 11 row: 11
column: 21 column: 21
fix: fix:
content: list patch:
location: content: list
row: 11 location:
column: 10 row: 11
end_location: column: 10
row: 11 end_location:
column: 21 row: 11
column: 21
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 4 row: 4
column: 23 column: 23
fix: fix:
content: str | None patch:
location: content: str | None
row: 4 location:
column: 10 row: 4
end_location: column: 10
row: 4 end_location:
column: 23 row: 4
column: 23
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -26,13 +27,14 @@ expression: checks
row: 11 row: 11
column: 30 column: 30
fix: fix:
content: str | None patch:
location: content: str | None
row: 11 location:
column: 10 row: 11
end_location: column: 10
row: 11 end_location:
column: 30 row: 11
column: 30
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -42,13 +44,14 @@ expression: checks
row: 18 row: 18
column: 46 column: 46
fix: fix:
content: "str | int | Union[float, bytes]" patch:
location: content: "str | int | Union[float, bytes]"
row: 18 location:
column: 10 row: 18
end_location: column: 10
row: 18 end_location:
column: 46 row: 18
column: 46
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -58,13 +61,14 @@ expression: checks
row: 18 row: 18
column: 45 column: 45
fix: fix:
content: float | bytes patch:
location: content: float | bytes
row: 18 location:
column: 26 row: 18
end_location: column: 26
row: 18 end_location:
column: 45 row: 18
column: 45
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -74,13 +78,14 @@ expression: checks
row: 25 row: 25
column: 32 column: 32
fix: fix:
content: str | int patch:
location: content: str | int
row: 25 location:
column: 10 row: 25
end_location: column: 10
row: 25 end_location:
column: 32 row: 25
column: 32
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -90,13 +95,14 @@ expression: checks
row: 32 row: 32
column: 48 column: 48
fix: fix:
content: "str | int | Union[float, bytes]" patch:
location: content: "str | int | Union[float, bytes]"
row: 32 location:
column: 10 row: 32
end_location: column: 10
row: 32 end_location:
column: 48 row: 32
column: 48
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -106,13 +112,14 @@ expression: checks
row: 32 row: 32
column: 48 column: 48
fix: fix:
content: float | bytes patch:
location: content: float | bytes
row: 32 location:
column: 10 row: 32
end_location: column: 10
row: 32 end_location:
column: 48 row: 32
column: 48
applied: false applied: false
- kind: UsePEP604Annotation - kind: UsePEP604Annotation
location: location:
@ -122,12 +129,13 @@ expression: checks
row: 39 row: 39
column: 34 column: 34
fix: fix:
content: str | int patch:
location: content: str | int
row: 39 location:
column: 10 row: 39
end_location: column: 10
row: 39 end_location:
column: 34 row: 39
column: 34
applied: false applied: false

View file

@ -10,13 +10,14 @@ expression: checks
row: 17 row: 17
column: 36 column: 36
fix: fix:
content: super() patch:
location: content: super()
row: 17 location:
column: 18 row: 17
end_location: column: 18
row: 17 end_location:
column: 36 row: 17
column: 36
applied: false applied: false
- kind: SuperCallWithParameters - kind: SuperCallWithParameters
location: location:
@ -26,13 +27,14 @@ expression: checks
row: 18 row: 18
column: 27 column: 27
fix: fix:
content: super() patch:
location: content: super()
row: 18 location:
column: 9 row: 18
end_location: column: 9
row: 18 end_location:
column: 27 row: 18
column: 27
applied: false applied: false
- kind: SuperCallWithParameters - kind: SuperCallWithParameters
location: location:
@ -42,13 +44,14 @@ expression: checks
row: 22 row: 22
column: 10 column: 10
fix: fix:
content: super() patch:
location: content: super()
row: 19 location:
column: 9 row: 19
end_location: column: 9
row: 22 end_location:
column: 10 row: 22
column: 10
applied: false applied: false
- kind: SuperCallWithParameters - kind: SuperCallWithParameters
location: location:
@ -58,13 +61,14 @@ expression: checks
row: 36 row: 36
column: 29 column: 29
fix: fix:
content: super() patch:
location: content: super()
row: 36 location:
column: 9 row: 36
end_location: column: 9
row: 36 end_location:
column: 29 row: 36
column: 29
applied: false applied: false
- kind: SuperCallWithParameters - kind: SuperCallWithParameters
location: location:
@ -74,12 +78,13 @@ expression: checks
row: 50 row: 50
column: 33 column: 33
fix: fix:
content: super() patch:
location: content: super()
row: 50 location:
column: 13 row: 50
end_location: column: 13
row: 50 end_location:
column: 33 row: 50
column: 33
applied: false applied: false

View file

@ -12,13 +12,14 @@ expression: checks
row: 8 row: 8
column: 2 column: 2
fix: fix:
content: "from models import (\n Fruit,\n)" patch:
location: content: "from models import (\n Fruit,\n)"
row: 5 location:
column: 1 row: 5
end_location: column: 1
row: 8 end_location:
column: 2 row: 8
column: 2
applied: false applied: false
- kind: - kind:
UndefinedName: Bar UndefinedName: Bar

View file

@ -11,13 +11,14 @@ expression: checks
row: 9 row: 9
column: 18 column: 18
fix: fix:
content: "" patch:
location: content: ""
row: 9 location:
column: 10 row: 9
end_location: column: 10
row: 9 end_location:
column: 18 row: 9
column: 18
applied: false applied: false
- kind: - kind:
UnusedNOQA: UnusedNOQA:
@ -29,13 +30,14 @@ expression: checks
row: 13 row: 13
column: 24 column: 24
fix: fix:
content: "" patch:
location: content: ""
row: 13 location:
column: 10 row: 13
end_location: column: 10
row: 13 end_location:
column: 24 row: 13
column: 24
applied: false applied: false
- kind: - kind:
UnusedNOQA: UnusedNOQA:
@ -48,13 +50,14 @@ expression: checks
row: 16 row: 16
column: 30 column: 30
fix: fix:
content: "" patch:
location: content: ""
row: 16 location:
column: 10 row: 16
end_location: column: 10
row: 16 end_location:
column: 30 row: 16
column: 30
applied: false applied: false
- kind: - kind:
UnusedNOQA: UnusedNOQA:
@ -66,13 +69,14 @@ expression: checks
row: 19 row: 19
column: 30 column: 30
fix: fix:
content: " # noqa: F841" patch:
location: content: " # noqa: F841"
row: 19 location:
column: 10 row: 19
end_location: column: 10
row: 19 end_location:
column: 30 row: 19
column: 30
applied: false applied: false
- kind: - kind:
UnusedNOQA: UnusedNOQA:
@ -84,13 +88,14 @@ expression: checks
row: 44 row: 44
column: 24 column: 24
fix: fix:
content: " # noqa: E501" patch:
location: content: " # noqa: E501"
row: 44 location:
column: 4 row: 44
end_location: column: 4
row: 44 end_location:
column: 24 row: 44
column: 24
applied: false applied: false
- kind: - kind:
UnusedNOQA: UnusedNOQA:
@ -102,13 +107,14 @@ expression: checks
row: 52 row: 52
column: 18 column: 18
fix: fix:
content: "" patch:
location: content: ""
row: 52 location:
column: 4 row: 52
end_location: column: 4
row: 52 end_location:
column: 18 row: 52
column: 18
applied: false applied: false
- kind: - kind:
UnusedNOQA: ~ UnusedNOQA: ~
@ -119,12 +125,13 @@ expression: checks
row: 60 row: 60
column: 12 column: 12
fix: fix:
content: "" patch:
location: content: ""
row: 60 location:
column: 4 row: 60
end_location: column: 4
row: 60 end_location:
column: 12 row: 60
column: 12
applied: false applied: false