mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
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:
parent
8028de8956
commit
1e173f7909
231 changed files with 943 additions and 960 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
use anyhow::{bail, Result};
|
||||
use libcst_native::{
|
||||
Arg, Attribute, Call, Comparison, CompoundStatement, Dict, Expression, FunctionDef,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Interface for generating autofix edits from higher-level actions (e.g., "remove an argument").
|
||||
//! Interface for generating fix edits from higher-level actions (e.g., "remove an argument").
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
|
@ -12,7 +12,7 @@ use ruff_python_trivia::{
|
|||
use ruff_source_file::{Locator, NewlineWithTrailingNewline};
|
||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::autofix::codemods;
|
||||
use crate::fix::codemods;
|
||||
|
||||
/// Return the `Fix` to use when deleting a `Stmt`.
|
||||
///
|
||||
|
@ -293,7 +293,7 @@ mod tests {
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::{Ranged, TextSize};
|
||||
|
||||
use crate::autofix::edits::{next_stmt_break, trailing_semicolon};
|
||||
use crate::fix::edits::{next_stmt_break, trailing_semicolon};
|
||||
|
||||
#[test]
|
||||
fn find_semicolon() -> Result<()> {
|
|
@ -141,7 +141,7 @@ mod tests {
|
|||
use ruff_diagnostics::{Diagnostic, Edit, Fix, SourceMarker};
|
||||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::autofix::{apply_fixes, FixResult};
|
||||
use crate::fix::{apply_fixes, FixResult};
|
||||
use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile;
|
||||
|
||||
#[allow(deprecated)]
|
|
@ -17,9 +17,9 @@ use ruff_python_semantic::SemanticModel;
|
|||
use ruff_python_trivia::textwrap::indent;
|
||||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::cst::matchers::{match_aliases, match_import_from, match_statement};
|
||||
use crate::fix;
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
use crate::importer::insertion::Insertion;
|
||||
|
||||
mod insertion;
|
||||
|
@ -91,7 +91,7 @@ impl<'a> Importer<'a> {
|
|||
at: TextSize,
|
||||
) -> Result<RuntimeImportEdit> {
|
||||
// Generate the modified import statement.
|
||||
let content = autofix::codemods::retain_imports(
|
||||
let content = fix::codemods::retain_imports(
|
||||
&import.names,
|
||||
import.statement,
|
||||
self.locator,
|
||||
|
@ -124,7 +124,7 @@ impl<'a> Importer<'a> {
|
|||
source_type: PySourceType,
|
||||
) -> Result<TypingImportEdit> {
|
||||
// Generate the modified import statement.
|
||||
let content = autofix::codemods::retain_imports(
|
||||
let content = fix::codemods::retain_imports(
|
||||
&import.names,
|
||||
import.statement,
|
||||
self.locator,
|
||||
|
|
|
@ -14,7 +14,6 @@ pub use rules::pycodestyle::rules::{IOError, SyntaxError};
|
|||
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
mod autofix;
|
||||
mod checkers;
|
||||
pub mod codes;
|
||||
mod comments;
|
||||
|
@ -22,6 +21,7 @@ mod cst;
|
|||
pub mod directives;
|
||||
mod doc_lines;
|
||||
mod docstrings;
|
||||
mod fix;
|
||||
pub mod fs;
|
||||
mod importer;
|
||||
mod lex;
|
||||
|
|
|
@ -18,7 +18,6 @@ use ruff_python_parser::{AsMode, ParseError};
|
|||
use ruff_source_file::{Locator, SourceFileBuilder};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::{fix_file, FixResult};
|
||||
use crate::checkers::ast::check_ast;
|
||||
use crate::checkers::filesystem::check_file_path;
|
||||
use crate::checkers::imports::check_imports;
|
||||
|
@ -27,6 +26,7 @@ use crate::checkers::physical_lines::check_physical_lines;
|
|||
use crate::checkers::tokens::check_tokens;
|
||||
use crate::directives::Directives;
|
||||
use crate::doc_lines::{doc_lines_from_ast, doc_lines_from_tokens};
|
||||
use crate::fix::{fix_file, FixResult};
|
||||
use crate::logging::DisplayParseError;
|
||||
use crate::message::Message;
|
||||
use crate::noqa::add_noqa;
|
||||
|
@ -412,7 +412,7 @@ fn diagnostics_to_messages(
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Generate `Diagnostic`s from source code content, iteratively autofixing
|
||||
/// Generate `Diagnostic`s from source code content, iteratively fixing
|
||||
/// until stable.
|
||||
pub fn lint_fix<'a>(
|
||||
path: &Path,
|
||||
|
@ -433,7 +433,7 @@ pub fn lint_fix<'a>(
|
|||
// Track whether the _initial_ source code was parseable.
|
||||
let mut parseable = false;
|
||||
|
||||
// Continuously autofix until the source code stabilizes.
|
||||
// Continuously fix until the source code stabilizes.
|
||||
loop {
|
||||
// Tokenize once.
|
||||
let tokens: Vec<LexResult> =
|
||||
|
@ -478,17 +478,17 @@ pub fn lint_fix<'a>(
|
|||
// longer parseable on a subsequent pass, then we've introduced a
|
||||
// syntax error. Return the original code.
|
||||
if parseable && result.error.is_some() {
|
||||
report_autofix_syntax_error(
|
||||
report_fix_syntax_error(
|
||||
path,
|
||||
transformed.source_code(),
|
||||
&result.error.unwrap(),
|
||||
fixed.keys().copied(),
|
||||
);
|
||||
return Err(anyhow!("Autofix introduced a syntax error"));
|
||||
return Err(anyhow!("Fix introduced a syntax error"));
|
||||
}
|
||||
}
|
||||
|
||||
// Apply autofix.
|
||||
// Apply fix.
|
||||
if let Some(FixResult {
|
||||
code: fixed_contents,
|
||||
fixes: applied,
|
||||
|
@ -569,7 +569,7 @@ This indicates a bug in Ruff. If you could open an issue at:
|
|||
}
|
||||
|
||||
#[allow(clippy::print_stderr)]
|
||||
fn report_autofix_syntax_error(
|
||||
fn report_fix_syntax_error(
|
||||
path: &Path,
|
||||
transformed: &str,
|
||||
error: &ParseError,
|
||||
|
@ -578,7 +578,7 @@ fn report_autofix_syntax_error(
|
|||
let codes = collect_rule_codes(rules);
|
||||
if cfg!(debug_assertions) {
|
||||
eprintln!(
|
||||
"{}{} Autofix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---",
|
||||
"{}{} Fix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---",
|
||||
"error".red().bold(),
|
||||
":".bold(),
|
||||
fs::relativize_path(path),
|
||||
|
@ -589,11 +589,11 @@ fn report_autofix_syntax_error(
|
|||
} else {
|
||||
eprintln!(
|
||||
r#"
|
||||
{}{} Autofix introduced a syntax error. Reverting all changes.
|
||||
{}{} Fix introduced a syntax error. Reverting all changes.
|
||||
|
||||
This indicates a bug in Ruff. If you could open an issue at:
|
||||
|
||||
https://github.com/astral-sh/ruff/issues/new?title=%5BAutofix%20error%5D
|
||||
https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D
|
||||
|
||||
...quoting the contents of `{}`, the rule codes {}, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
|
||||
"#,
|
||||
|
|
|
@ -143,9 +143,9 @@ impl Display for RuleCodeAndBody<'_> {
|
|||
if self.show_fix_status && self.message.fix.is_some() {
|
||||
write!(
|
||||
f,
|
||||
"{code} {autofix}{body}",
|
||||
"{code} {fix}{body}",
|
||||
code = kind.rule().noqa_code().to_string().red().bold(),
|
||||
autofix = format_args!("[{}] ", "*".cyan()),
|
||||
fix = format_args!("[{}] ", "*".cyan()),
|
||||
body = kind.body,
|
||||
)
|
||||
} else {
|
||||
|
|
|
@ -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_index::Indexer;
|
||||
use ruff_source_file::Locator;
|
||||
|
@ -25,13 +25,13 @@ use super::super::detection::comment_contains_code;
|
|||
#[violation]
|
||||
pub struct CommentedOutCode;
|
||||
|
||||
impl AlwaysAutofixableViolation for CommentedOutCode {
|
||||
impl AlwaysFixableViolation for CommentedOutCode {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Found commented-out code")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove commented-out code".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::ReturnStatementVisitor;
|
||||
use ruff_python_ast::identifier::Identifier;
|
||||
|
@ -287,14 +287,14 @@ pub struct MissingReturnTypeSpecialMethod {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for MissingReturnTypeSpecialMethod {
|
||||
impl AlwaysFixableViolation for MissingReturnTypeSpecialMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let MissingReturnTypeSpecialMethod { name } = self;
|
||||
format!("Missing return type annotation for special method `{name}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add `None` return type".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
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::helpers::is_const_false;
|
||||
|
||||
|
@ -33,13 +33,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct AssertFalse;
|
||||
|
||||
impl AlwaysAutofixableViolation for AssertFalse {
|
||||
impl AlwaysFixableViolation for AssertFalse {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace `assert False`".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr, ExprContext};
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
use rustc_hash::{FxHashMap, 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::call_path;
|
||||
|
@ -86,7 +86,7 @@ pub struct DuplicateHandlerException {
|
|||
pub names: Vec<String>,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for DuplicateHandlerException {
|
||||
impl AlwaysFixableViolation for DuplicateHandlerException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let DuplicateHandlerException { names } = self;
|
||||
|
@ -98,7 +98,7 @@ impl AlwaysAutofixableViolation for DuplicateHandlerException {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"De-duplicate exceptions".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::autofix::edits::pad;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use crate::fix::edits::pad;
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Constant, Expr};
|
||||
use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private};
|
||||
|
@ -34,7 +34,7 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct GetAttrWithConstant;
|
||||
|
||||
impl AlwaysAutofixableViolation for GetAttrWithConstant {
|
||||
impl AlwaysFixableViolation for GetAttrWithConstant {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!(
|
||||
|
@ -43,7 +43,7 @@ impl AlwaysAutofixableViolation for GetAttrWithConstant {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace `getattr` with attribute access".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ast::call_path::{from_qualified_name, CallPath};
|
||||
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::helpers::is_docstring_stmt;
|
||||
use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault};
|
||||
|
@ -64,14 +64,14 @@ use crate::registry::AsRule;
|
|||
pub struct MutableArgumentDefault;
|
||||
|
||||
impl Violation for MutableArgumentDefault {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Do not use mutable data structures for argument defaults")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace with `None`; initialize within function"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
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::helpers::map_starred;
|
||||
use ruff_python_ast::{self as ast, ExceptHandler, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::edits::pad;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits::pad;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -39,13 +39,13 @@ pub struct RedundantTupleInExceptionHandler {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for RedundantTupleInExceptionHandler {
|
||||
impl AlwaysFixableViolation for RedundantTupleInExceptionHandler {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("A length-one tuple literal is redundant in exception handlers")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let RedundantTupleInExceptionHandler { name } = self;
|
||||
format!("Replace with `except {name}`")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Constant, Expr, ExprContext, Identifier, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_codegen::Generator;
|
||||
use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private};
|
||||
|
@ -34,7 +34,7 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct SetAttrWithConstant;
|
||||
|
||||
impl AlwaysAutofixableViolation for SetAttrWithConstant {
|
||||
impl AlwaysFixableViolation for SetAttrWithConstant {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!(
|
||||
|
@ -43,7 +43,7 @@ impl AlwaysAutofixableViolation for SetAttrWithConstant {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace `setattr` with assignment".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{self as ast, Constant, Expr};
|
||||
|
||||
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_text_size::Ranged;
|
||||
|
||||
|
@ -37,7 +37,7 @@ use crate::registry::AsRule;
|
|||
pub struct UnreliableCallableCheck;
|
||||
|
||||
impl Violation for UnreliableCallableCheck {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -47,7 +47,7 @@ impl Violation for UnreliableCallableCheck {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace with `callable()`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
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::visitor::Visitor;
|
||||
use ruff_python_ast::{self as ast, Expr};
|
||||
|
@ -56,7 +56,7 @@ pub struct UnusedLoopControlVariable {
|
|||
}
|
||||
|
||||
impl Violation for UnusedLoopControlVariable {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -70,7 +70,7 @@ impl Violation for UnusedLoopControlVariable {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let UnusedLoopControlVariable { rename, name, .. } = self;
|
||||
|
||||
rename
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
|
||||
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_parser::lexer::{LexResult, Spanned};
|
||||
|
@ -138,13 +138,13 @@ impl Context {
|
|||
#[violation]
|
||||
pub struct MissingTrailingComma;
|
||||
|
||||
impl AlwaysAutofixableViolation for MissingTrailingComma {
|
||||
impl AlwaysFixableViolation for MissingTrailingComma {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Trailing comma missing")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add trailing comma".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -209,13 +209,13 @@ impl Violation for TrailingCommaOnBareTuple {
|
|||
#[violation]
|
||||
pub struct ProhibitedTrailingComma;
|
||||
|
||||
impl AlwaysAutofixableViolation for ProhibitedTrailingComma {
|
||||
impl AlwaysFixableViolation for ProhibitedTrailingComma {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Trailing comma prohibited")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove trailing comma".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ pub(crate) fn trailing_commas(
|
|||
);
|
||||
if settings.rules.should_fix(Rule::MissingTrailingComma) {
|
||||
// Create a replacement that includes the final bracket (or other token),
|
||||
// rather than just inserting a comma at the end. This prevents the UP034 autofix
|
||||
// rather than just inserting a comma at the end. This prevents the UP034 fix
|
||||
// removing any brackets in the same linter pass - doing both at the same time could
|
||||
// lead to a syntax error.
|
||||
let contents = locator.slice(missing_comma.1);
|
||||
|
|
|
@ -917,11 +917,11 @@ COM81.py:627:20: COM812 [*] Trailing comma missing
|
|||
627 |+ **{'ham': spam},
|
||||
628 628 | )
|
||||
629 629 |
|
||||
630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
|
||||
630 630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error.
|
||||
|
||||
COM81.py:632:42: COM812 [*] Trailing comma missing
|
||||
|
|
||||
630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
|
||||
630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error.
|
||||
631 | the_first_one = next(
|
||||
632 | (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket
|
||||
| COM812
|
||||
|
@ -931,7 +931,7 @@ COM81.py:632:42: COM812 [*] Trailing comma missing
|
|||
|
||||
ℹ Fix
|
||||
629 629 |
|
||||
630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
|
||||
630 630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error.
|
||||
631 631 | the_first_one = next(
|
||||
632 |- (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket
|
||||
632 |+ (i for i in range(10) if i // 2 == 0), # COM812 fix should include the final bracket
|
||||
|
|
|
@ -15,9 +15,9 @@ use ruff_python_semantic::SemanticModel;
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::autofix::edits::pad;
|
||||
use crate::cst::helpers::{negate, space};
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
use crate::fix::edits::pad;
|
||||
use crate::rules::flake8_comprehensions::rules::ObjectType;
|
||||
use crate::{
|
||||
checkers::ast::Checker,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -35,14 +35,14 @@ pub struct UnnecessaryCallAroundSorted {
|
|||
func: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryCallAroundSorted {
|
||||
impl AlwaysFixableViolation for UnnecessaryCallAroundSorted {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryCallAroundSorted { func } = self;
|
||||
format!("Unnecessary `{func}` call around `sorted()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let UnnecessaryCallAroundSorted { func } = self;
|
||||
format!("Remove unnecessary `{func}` call")
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{Expr, Keyword};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -37,14 +37,14 @@ pub struct UnnecessaryCollectionCall {
|
|||
obj_type: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryCollectionCall {
|
||||
impl AlwaysFixableViolation for UnnecessaryCollectionCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryCollectionCall { obj_type } = self;
|
||||
format!("Unnecessary `{obj_type}` call (rewrite as a literal)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a literal".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::comparable::ComparableExpr;
|
||||
use ruff_python_ast::{self as ast, Comprehension, Expr};
|
||||
|
@ -34,14 +34,14 @@ pub struct UnnecessaryComprehension {
|
|||
obj_type: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryComprehension {
|
||||
impl AlwaysFixableViolation for UnnecessaryComprehension {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryComprehension { obj_type } = self;
|
||||
format!("Unnecessary `{obj_type}` comprehension (rewrite using `{obj_type}()`)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let UnnecessaryComprehension { obj_type } = self;
|
||||
format!("Rewrite using `{obj_type}()`")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::Violation;
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic};
|
||||
use ruff_diagnostics::{Diagnostic, FixKind};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::any_over_expr;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -44,14 +44,14 @@ use crate::rules::flake8_comprehensions::fixes;
|
|||
pub struct UnnecessaryComprehensionAnyAll;
|
||||
|
||||
impl Violation for UnnecessaryComprehensionAnyAll {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary list comprehension.")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Remove unnecessary list comprehension".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::comparable::ComparableKeyword;
|
||||
use ruff_python_ast::{self as ast, Arguments, Expr, Keyword};
|
||||
|
@ -49,14 +49,14 @@ pub struct UnnecessaryDoubleCastOrProcess {
|
|||
outer: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryDoubleCastOrProcess {
|
||||
impl AlwaysFixableViolation for UnnecessaryDoubleCastOrProcess {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryDoubleCastOrProcess { inner, outer } = self;
|
||||
format!("Unnecessary `{inner}` call within `{outer}()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let UnnecessaryDoubleCastOrProcess { inner, .. } = self;
|
||||
format!("Remove the inner `{inner}` call")
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Expr, Keyword};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -30,13 +30,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryGeneratorDict;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorDict {
|
||||
impl AlwaysFixableViolation for UnnecessaryGeneratorDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary generator (rewrite as a `dict` comprehension)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `dict` comprehension".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -31,13 +31,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryGeneratorList;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorList {
|
||||
impl AlwaysFixableViolation for UnnecessaryGeneratorList {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary generator (rewrite as a `list` comprehension)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `list` comprehension".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -31,13 +31,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryGeneratorSet;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryGeneratorSet {
|
||||
impl AlwaysFixableViolation for UnnecessaryGeneratorSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary generator (rewrite as a `set` comprehension)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `set` comprehension".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::Expr;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -28,13 +28,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryListCall;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListCall {
|
||||
impl AlwaysFixableViolation for UnnecessaryListCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary `list` call (remove the outer call to `list()`)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove outer `list` call".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Expr, Keyword};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -28,13 +28,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryListComprehensionDict;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListComprehensionDict {
|
||||
impl AlwaysFixableViolation for UnnecessaryListComprehensionDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary `list` comprehension (rewrite as a `dict` comprehension)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `dict` comprehension".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -29,13 +29,13 @@ use super::helpers;
|
|||
#[violation]
|
||||
pub struct UnnecessaryListComprehensionSet;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryListComprehensionSet {
|
||||
impl AlwaysFixableViolation for UnnecessaryListComprehensionSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary `list` comprehension (rewrite as a `set` comprehension)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `set` comprehension".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Expr, Keyword};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -34,14 +34,14 @@ pub struct UnnecessaryLiteralDict {
|
|||
obj_type: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralDict {
|
||||
impl AlwaysFixableViolation for UnnecessaryLiteralDict {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryLiteralDict { obj_type } = self;
|
||||
format!("Unnecessary `{obj_type}` literal (rewrite as a `dict` literal)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `dict` literal".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -36,14 +36,14 @@ pub struct UnnecessaryLiteralSet {
|
|||
obj_type: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralSet {
|
||||
impl AlwaysFixableViolation for UnnecessaryLiteralSet {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryLiteralSet { obj_type } = self;
|
||||
format!("Unnecessary `{obj_type}` literal (rewrite as a `set` literal)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Rewrite as a `set` literal".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::fmt;
|
|||
|
||||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -51,14 +51,14 @@ pub struct UnnecessaryLiteralWithinDictCall {
|
|||
kind: DictKind,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinDictCall {
|
||||
impl AlwaysFixableViolation for UnnecessaryLiteralWithinDictCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryLiteralWithinDictCall { kind } = self;
|
||||
format!("Unnecessary `dict` {kind} passed to `dict()` (remove the outer call to `dict()`)")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove outer `dict` call".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{Expr, Keyword};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -37,7 +37,7 @@ pub struct UnnecessaryLiteralWithinListCall {
|
|||
literal: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinListCall {
|
||||
impl AlwaysFixableViolation for UnnecessaryLiteralWithinListCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryLiteralWithinListCall { literal } = self;
|
||||
|
@ -53,7 +53,7 @@ impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinListCall {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let UnnecessaryLiteralWithinListCall { literal } = self;
|
||||
{
|
||||
if literal == "list" {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{Expr, Keyword};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub struct UnnecessaryLiteralWithinTupleCall {
|
|||
literal: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinTupleCall {
|
||||
impl AlwaysFixableViolation for UnnecessaryLiteralWithinTupleCall {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryLiteralWithinTupleCall { literal } = self;
|
||||
|
@ -55,7 +55,7 @@ impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinTupleCall {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let UnnecessaryLiteralWithinTupleCall { literal } = self;
|
||||
{
|
||||
if literal == "list" {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt;
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix};
|
||||
use ruff_diagnostics::{FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::visitor;
|
||||
use ruff_python_ast::visitor::Visitor;
|
||||
|
@ -47,7 +47,7 @@ pub struct UnnecessaryMap {
|
|||
}
|
||||
|
||||
impl Violation for UnnecessaryMap {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -55,7 +55,7 @@ impl Violation for UnnecessaryMap {
|
|||
format!("Unnecessary `map` usage (rewrite using a {object_type})")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let UnnecessaryMap { object_type } = self;
|
||||
Some(format!("Replace `map` with a {object_type}"))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprContext, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
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::whitespace;
|
||||
use ruff_python_codegen::{Generator, Stylist};
|
||||
|
@ -50,14 +50,14 @@ use crate::registry::{AsRule, Rule};
|
|||
pub struct RawStringInException;
|
||||
|
||||
impl Violation for RawStringInException {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Exception must not use a string literal, assign to variable first")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Assign to variable; remove string literal".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -104,14 +104,14 @@ impl Violation for RawStringInException {
|
|||
pub struct FStringInException;
|
||||
|
||||
impl Violation for FStringInException {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Exception must not use an f-string literal, assign to variable first")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Assign to variable; remove f-string literal".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -160,14 +160,14 @@ impl Violation for FStringInException {
|
|||
pub struct DotFormatInException;
|
||||
|
||||
impl Violation for DotFormatInException {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Exception must not use a `.format()` string directly, assign to variable first")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Assign to variable; remove `.format()` string".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_text_size::{TextRange, 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_trivia::is_python_whitespace;
|
||||
use ruff_source_file::Locator;
|
||||
|
@ -35,13 +35,13 @@ use crate::settings::LinterSettings;
|
|||
#[violation]
|
||||
pub struct ShebangLeadingWhitespace;
|
||||
|
||||
impl AlwaysAutofixableViolation for ShebangLeadingWhitespace {
|
||||
impl AlwaysFixableViolation for ShebangLeadingWhitespace {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Avoid whitespace before shebang")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Remove whitespace before shebang")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use itertools::Itertools;
|
|||
use ruff_python_parser::lexer::LexResult;
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
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::Locator;
|
||||
|
@ -34,14 +34,14 @@ use crate::rules::flake8_implicit_str_concat::settings::Settings;
|
|||
pub struct SingleLineImplicitStringConcatenation;
|
||||
|
||||
impl Violation for SingleLineImplicitStringConcatenation {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Implicitly concatenated string literals on one line")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Combine string literals".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::{Binding, Imported};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -37,7 +37,7 @@ pub struct UnconventionalImportAlias {
|
|||
}
|
||||
|
||||
impl Violation for UnconventionalImportAlias {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -45,7 +45,7 @@ impl Violation for UnconventionalImportAlias {
|
|||
format!("`{name}` should be imported as `{asname}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let UnconventionalImportAlias { name, asname } = self;
|
||||
Some(format!("Alias `{name}` to `{asname}`"))
|
||||
}
|
||||
|
|
|
@ -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 as ast;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -41,14 +41,14 @@ use crate::registry::AsRule;
|
|||
pub struct DirectLoggerInstantiation;
|
||||
|
||||
impl Violation for DirectLoggerInstantiation {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use `logging.getLogger()` to instantiate loggers")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace with `logging.getLogger()`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::{self as ast, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -44,14 +44,14 @@ use crate::registry::AsRule;
|
|||
pub struct InvalidGetLoggerArgument;
|
||||
|
||||
impl Violation for InvalidGetLoggerArgument {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use `__name__` with `logging.getLogger()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace with `__name__`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::Expr;
|
||||
|
||||
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_text_size::Ranged;
|
||||
|
||||
|
@ -36,13 +36,13 @@ use crate::registry::AsRule;
|
|||
pub struct UndocumentedWarn;
|
||||
|
||||
impl Violation for UndocumentedWarn {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use of undocumented `logging.WARN` constant")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace `logging.WARN` with `logging.WARNING`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
/// ## What it does
|
||||
|
@ -376,13 +376,13 @@ impl Violation for LoggingFString {
|
|||
#[violation]
|
||||
pub struct LoggingWarn;
|
||||
|
||||
impl AlwaysAutofixableViolation for LoggingWarn {
|
||||
impl AlwaysFixableViolation for LoggingWarn {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Logging statement uses `warn` instead of `warning`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Convert to `warn`".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use rustc_hash::FxHashSet;
|
||||
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Expr, Stmt};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -36,14 +36,14 @@ pub struct DuplicateClassFieldDefinition {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for DuplicateClassFieldDefinition {
|
||||
impl AlwaysFixableViolation for DuplicateClassFieldDefinition {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let DuplicateClassFieldDefinition { name } = self;
|
||||
format!("Class field `{name}` is defined multiple times")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let DuplicateClassFieldDefinition { name } = self;
|
||||
format!("Remove duplicate field definition for `{name}`")
|
||||
}
|
||||
|
@ -80,12 +80,8 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St
|
|||
stmt.range(),
|
||||
);
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit = autofix::edits::delete_stmt(
|
||||
stmt,
|
||||
Some(stmt),
|
||||
checker.locator(),
|
||||
checker.indexer(),
|
||||
);
|
||||
let edit =
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::suggested(edit).isolate(Checker::isolation(Some(
|
||||
checker.semantic().current_statement_id(),
|
||||
))));
|
||||
|
|
|
@ -7,7 +7,7 @@ use ruff_text_size::{Ranged, TextRange};
|
|||
|
||||
use ruff_python_ast::{self as ast, Arguments, BoolOp, Expr, ExprContext, Identifier};
|
||||
|
||||
use ruff_diagnostics::AlwaysAutofixableViolation;
|
||||
use ruff_diagnostics::AlwaysFixableViolation;
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
|
@ -45,14 +45,14 @@ pub struct MultipleStartsEndsWith {
|
|||
attr: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for MultipleStartsEndsWith {
|
||||
impl AlwaysFixableViolation for MultipleStartsEndsWith {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let MultipleStartsEndsWith { attr } = self;
|
||||
format!("Call `{attr}` once with a `tuple`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let MultipleStartsEndsWith { attr } = self;
|
||||
format!("Merge into a single `{attr}` call")
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
use ruff_python_ast::Stmt;
|
||||
|
||||
use ruff_diagnostics::AlwaysAutofixableViolation;
|
||||
use ruff_diagnostics::AlwaysFixableViolation;
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::is_docstring_stmt;
|
||||
use ruff_python_ast::whitespace::trailing_comment_start_offset;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -38,13 +38,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct UnnecessaryPass;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryPass {
|
||||
impl AlwaysFixableViolation for UnnecessaryPass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary `pass` statement")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove unnecessary `pass`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ pub(crate) fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) {
|
|||
let edit = if let Some(index) = trailing_comment_start_offset(second, checker.locator()) {
|
||||
Edit::range_deletion(second.range().add_end(index))
|
||||
} else {
|
||||
autofix::edits::delete_stmt(second, None, checker.locator(), checker.indexer())
|
||||
fix::edits::delete_stmt(second, None, checker.locator(), checker.indexer())
|
||||
};
|
||||
diagnostic.set_fix(Fix::automatic(edit));
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Expr, ExprLambda};
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
|
@ -40,14 +40,14 @@ use crate::registry::AsRule;
|
|||
pub struct ReimplementedListBuiltin;
|
||||
|
||||
impl Violation for ReimplementedListBuiltin {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Prefer `list` over useless lambda")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Replace with `list`".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use ruff_diagnostics::Diagnostic;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Constant, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::edits::{remove_argument, Parentheses};
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits::{remove_argument, Parentheses};
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -31,13 +31,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct UnnecessaryRangeStart;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryRangeStart {
|
||||
impl AlwaysFixableViolation for UnnecessaryRangeStart {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary `start` argument in `range`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Remove `start` argument")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::Parameters;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -41,14 +41,14 @@ pub struct AnyEqNeAnnotation {
|
|||
method_name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for AnyEqNeAnnotation {
|
||||
impl AlwaysFixableViolation for AnyEqNeAnnotation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let AnyEqNeAnnotation { method_name } = self;
|
||||
format!("Prefer `object` to `Any` for the second parameter to `{method_name}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Replace with `object`")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Violation for CollectionsNamedTuple {
|
|||
format!("Use `typing.NamedTuple` instead of `collections.namedtuple`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Replace with `typing.NamedTuple`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::collections::HashSet;
|
|||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::AsRule;
|
||||
use crate::rules::flake8_pyi::helpers::traverse_union;
|
||||
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::comparable::ComparableExpr;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -34,14 +34,14 @@ pub struct DuplicateUnionMember {
|
|||
}
|
||||
|
||||
impl Violation for DuplicateUnionMember {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Duplicate union member `{}`", self.duplicate_name)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!(
|
||||
"Remove duplicate union member `{}`",
|
||||
self.duplicate_name
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{Constant, Expr, ExprConstant, Stmt, StmtExpr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -31,14 +31,14 @@ use crate::registry::AsRule;
|
|||
pub struct EllipsisInNonEmptyClassBody;
|
||||
|
||||
impl Violation for EllipsisInNonEmptyClassBody {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Non-empty class body must not contain `...`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Remove unnecessary `...`".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -64,12 +64,8 @@ pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[St
|
|||
) {
|
||||
let mut diagnostic = Diagnostic::new(EllipsisInNonEmptyClassBody, stmt.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit = autofix::edits::delete_stmt(
|
||||
stmt,
|
||||
Some(stmt),
|
||||
checker.locator(),
|
||||
checker.indexer(),
|
||||
);
|
||||
let edit =
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(Some(
|
||||
checker.semantic().current_statement_id(),
|
||||
))));
|
||||
|
|
|
@ -6,7 +6,7 @@ use ruff_python_ast::{
|
|||
};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
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::helpers::is_const_none;
|
||||
use ruff_python_semantic::SemanticModel;
|
||||
|
@ -49,7 +49,7 @@ pub struct BadExitAnnotation {
|
|||
}
|
||||
|
||||
impl Violation for BadExitAnnotation {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -65,7 +65,7 @@ impl Violation for BadExitAnnotation {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
if matches!(self.error_kind, ErrorKind::StarArgsNotAnnotated) {
|
||||
Some("Annotate star-args with `object`".to_string())
|
||||
} else {
|
||||
|
|
|
@ -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::helpers::is_docstring_stmt;
|
||||
use ruff_python_ast::{self as ast, Expr, Stmt};
|
||||
|
@ -31,13 +31,13 @@ use crate::registry::Rule;
|
|||
#[violation]
|
||||
pub struct NonEmptyStubBody;
|
||||
|
||||
impl AlwaysAutofixableViolation for NonEmptyStubBody {
|
||||
impl AlwaysFixableViolation for NonEmptyStubBody {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Function body must contain only `...`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Replace function body with `...`")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ impl Violation for NonSelfReturnType {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Consider using `typing_extensions.Self` as return type".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::Expr;
|
||||
use ruff_text_size::{Ranged, TextSize};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
@ -30,13 +30,13 @@ pub struct NumericLiteralTooLong;
|
|||
/// ```python
|
||||
/// def foo(arg: int = ...) -> None: ...
|
||||
/// ```
|
||||
impl AlwaysAutofixableViolation for NumericLiteralTooLong {
|
||||
impl AlwaysFixableViolation for NumericLiteralTooLong {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Numeric literals with a string representation longer than ten characters are not permitted")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `...`".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
#[violation]
|
||||
pub struct PassInClassBody;
|
||||
|
||||
impl AlwaysAutofixableViolation for PassInClassBody {
|
||||
impl AlwaysFixableViolation for PassInClassBody {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Class body must not contain `pass`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Remove unnecessary `pass`")
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ pub(crate) fn pass_in_class_body(checker: &mut Checker, class_def: &ast::StmtCla
|
|||
let mut diagnostic = Diagnostic::new(PassInClassBody, stmt.range());
|
||||
if checker.patch(diagnostic.kind.rule()) {
|
||||
let edit =
|
||||
autofix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(Some(
|
||||
checker.semantic().current_statement_id(),
|
||||
))));
|
||||
|
|
|
@ -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::Stmt;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -29,13 +29,13 @@ use crate::registry::Rule;
|
|||
#[violation]
|
||||
pub struct PassStatementStubBody;
|
||||
|
||||
impl AlwaysAutofixableViolation for PassStatementStubBody {
|
||||
impl AlwaysFixableViolation for PassStatementStubBody {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Empty body should contain `...`, not `pass`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Replace `pass` with `...`")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_text_size::TextRange;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
@ -9,13 +9,13 @@ use crate::registry::Rule;
|
|||
#[violation]
|
||||
pub struct QuotedAnnotationInStub;
|
||||
|
||||
impl AlwaysAutofixableViolation for QuotedAnnotationInStub {
|
||||
impl AlwaysFixableViolation for QuotedAnnotationInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Quoted annotations should not be included in stubs")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove quotes".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use ruff_python_ast::{self as ast, Expr};
|
|||
use ruff_python_semantic::SemanticModel;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::snippet::SourceCodeSnippet;
|
||||
use crate::fix::snippet::SourceCodeSnippet;
|
||||
use crate::{checkers::ast::Checker, rules::flake8_pyi::helpers::traverse_union};
|
||||
|
||||
/// ## What it does
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::call_path::CallPath;
|
||||
use ruff_python_ast::{
|
||||
|
@ -18,13 +18,13 @@ use crate::settings::types::PythonVersion;
|
|||
#[violation]
|
||||
pub struct TypedArgumentDefaultInStub;
|
||||
|
||||
impl AlwaysAutofixableViolation for TypedArgumentDefaultInStub {
|
||||
impl AlwaysFixableViolation for TypedArgumentDefaultInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Only simple default values allowed for typed arguments")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace default value with `...`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ impl AlwaysAutofixableViolation for TypedArgumentDefaultInStub {
|
|||
#[violation]
|
||||
pub struct ArgumentDefaultInStub;
|
||||
|
||||
impl AlwaysAutofixableViolation for ArgumentDefaultInStub {
|
||||
impl AlwaysFixableViolation for ArgumentDefaultInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Only simple default values allowed for arguments")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace default value with `...`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -46,13 +46,13 @@ impl AlwaysAutofixableViolation for ArgumentDefaultInStub {
|
|||
#[violation]
|
||||
pub struct AssignmentDefaultInStub;
|
||||
|
||||
impl AlwaysAutofixableViolation for AssignmentDefaultInStub {
|
||||
impl AlwaysFixableViolation for AssignmentDefaultInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Only simple default values allowed for assignments")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace default value with `...`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ pub struct TypeAliasWithoutAnnotation {
|
|||
value: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for TypeAliasWithoutAnnotation {
|
||||
impl AlwaysFixableViolation for TypeAliasWithoutAnnotation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let TypeAliasWithoutAnnotation {
|
||||
|
@ -142,7 +142,7 @@ impl AlwaysAutofixableViolation for TypeAliasWithoutAnnotation {
|
|||
format!("Use `{module}.TypeAlias` for type alias, e.g., `{name}: TypeAlias = {value}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add `TypeAlias` annotation".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use ruff_python_ast as ast;
|
||||
use ruff_python_ast::Stmt;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::identifier::Identifier;
|
||||
use ruff_python_semantic::analyze::visibility::is_abstract;
|
||||
|
||||
use crate::autofix::edits::delete_stmt;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits::delete_stmt;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -29,14 +29,14 @@ pub struct StrOrReprDefinedInStub {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for StrOrReprDefinedInStub {
|
||||
impl AlwaysFixableViolation for StrOrReprDefinedInStub {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let StrOrReprDefinedInStub { name } = self;
|
||||
format!("Defining `{name}` in a stub is almost always redundant")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let StrOrReprDefinedInStub { name } = self;
|
||||
format!("Remove definition of `{name}`")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{self as ast, Constant, Expr};
|
||||
|
||||
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::helpers::is_docstring_stmt;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -30,13 +30,13 @@ pub struct StringOrBytesTooLong;
|
|||
/// ```python
|
||||
/// def foo(arg: str = ...) -> None: ...
|
||||
/// ```
|
||||
impl AlwaysAutofixableViolation for StringOrBytesTooLong {
|
||||
impl AlwaysFixableViolation for StringOrBytesTooLong {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("String and bytes literals longer than 50 characters are not permitted")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `...`".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::Imported;
|
||||
use ruff_python_semantic::{Binding, BindingKind};
|
||||
|
@ -33,7 +33,7 @@ use crate::renamer::Renamer;
|
|||
pub struct UnaliasedCollectionsAbcSetImport;
|
||||
|
||||
impl Violation for UnaliasedCollectionsAbcSetImport {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -42,7 +42,7 @@ impl Violation for UnaliasedCollectionsAbcSetImport {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(format!("Alias `Set` to `AbstractSet`"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use libcst_native::{
|
|||
SimpleWhitespace, SmallStatement, Statement, TrailingWhitespace,
|
||||
};
|
||||
|
||||
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::helpers::Truthiness;
|
||||
use ruff_python_ast::parenthesize::parenthesized_range;
|
||||
|
@ -20,11 +20,11 @@ use ruff_python_codegen::Stylist;
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::cst::helpers::negate;
|
||||
use crate::cst::matchers::match_indented_block;
|
||||
use crate::cst::matchers::match_module;
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
use crate::importer::ImportRequest;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
|
@ -62,14 +62,14 @@ use super::unittest_assert::UnittestAssert;
|
|||
pub struct PytestCompositeAssertion;
|
||||
|
||||
impl Violation for PytestCompositeAssertion {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Assertion should be broken down into multiple parts")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Break down assertion into multiple parts".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ pub struct PytestUnittestAssertion {
|
|||
}
|
||||
|
||||
impl Violation for PytestUnittestAssertion {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -200,7 +200,7 @@ impl Violation for PytestUnittestAssertion {
|
|||
format!("Use a regular `assert` instead of unittest-style `{assertion}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let PytestUnittestAssertion { assertion } = self;
|
||||
Some(format!("Replace `{assertion}(...)` with `assert ...`"))
|
||||
}
|
||||
|
@ -354,7 +354,7 @@ pub struct PytestUnittestRaisesAssertion {
|
|||
}
|
||||
|
||||
impl Violation for PytestUnittestRaisesAssertion {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -362,7 +362,7 @@ impl Violation for PytestUnittestRaisesAssertion {
|
|||
format!("Use `pytest.raises` instead of unittest-style `{assertion}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let PytestUnittestRaisesAssertion { assertion } = self;
|
||||
Some(format!("Replace `{assertion}` with `pytest.raises`"))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
|
||||
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::call_path::collect_call_path;
|
||||
|
@ -14,8 +14,8 @@ use ruff_python_semantic::SemanticModel;
|
|||
use ruff_text_size::Ranged;
|
||||
use ruff_text_size::{TextLen, TextRange};
|
||||
|
||||
use crate::autofix::edits;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits;
|
||||
use crate::registry::{AsRule, Rule};
|
||||
|
||||
use super::helpers::{
|
||||
|
@ -65,14 +65,14 @@ pub struct PytestFixtureIncorrectParenthesesStyle {
|
|||
actual: Parentheses,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle {
|
||||
impl AlwaysFixableViolation for PytestFixtureIncorrectParenthesesStyle {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let PytestFixtureIncorrectParenthesesStyle { expected, actual } = self;
|
||||
format!("Use `@pytest.fixture{expected}` over `@pytest.fixture{actual}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let PytestFixtureIncorrectParenthesesStyle { expected, .. } = self;
|
||||
match expected {
|
||||
Parentheses::None => "Remove parentheses".to_string(),
|
||||
|
@ -154,13 +154,13 @@ impl Violation for PytestFixturePositionalArgs {
|
|||
#[violation]
|
||||
pub struct PytestExtraneousScopeFunction;
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction {
|
||||
impl AlwaysFixableViolation for PytestExtraneousScopeFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`scope='function'` is implied in `@pytest.fixture()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove implied `scope` argument".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -488,14 +488,14 @@ pub struct PytestUselessYieldFixture {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
|
||||
impl AlwaysFixableViolation for PytestUselessYieldFixture {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let PytestUselessYieldFixture { name } = self;
|
||||
format!("No teardown in fixture `{name}`, use `return` instead of `yield`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace `yield` with `return`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -543,13 +543,13 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
|
|||
#[violation]
|
||||
pub struct PytestErroneousUseFixturesOnFixture;
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture {
|
||||
impl AlwaysFixableViolation for PytestErroneousUseFixturesOnFixture {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`pytest.mark.usefixtures` has no effect on fixtures")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove `pytest.mark.usefixtures`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -586,13 +586,13 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture {
|
|||
#[violation]
|
||||
pub struct PytestUnnecessaryAsyncioMarkOnFixture;
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestUnnecessaryAsyncioMarkOnFixture {
|
||||
impl AlwaysFixableViolation for PytestUnnecessaryAsyncioMarkOnFixture {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("`pytest.mark.asyncio` is unnecessary for fixtures")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove `pytest.mark.asyncio`".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Decorator, Expr};
|
||||
|
||||
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::call_path::CallPath;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -54,7 +54,7 @@ pub struct PytestIncorrectMarkParenthesesStyle {
|
|||
actual_parens: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
|
||||
impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let PytestIncorrectMarkParenthesesStyle {
|
||||
|
@ -68,7 +68,7 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add/remove parentheses".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
|
|||
#[violation]
|
||||
pub struct PytestUseFixturesWithoutParameters;
|
||||
|
||||
impl AlwaysAutofixableViolation for PytestUseFixturesWithoutParameters {
|
||||
impl AlwaysFixableViolation for PytestUseFixturesWithoutParameters {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Useless `pytest.mark.usefixtures` without parameters")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove `usefixtures` decorator or pass parameters".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::hash::BuildHasherDefault;
|
|||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
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::comparable::ComparableExpr;
|
||||
use ruff_python_ast::node::AstNode;
|
||||
|
@ -77,7 +77,7 @@ pub struct PytestParametrizeNamesWrongType {
|
|||
}
|
||||
|
||||
impl Violation for PytestParametrizeNamesWrongType {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -85,7 +85,7 @@ impl Violation for PytestParametrizeNamesWrongType {
|
|||
format!("Wrong name(s) type in `@pytest.mark.parametrize`, expected `{expected}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let PytestParametrizeNamesWrongType { expected } = self;
|
||||
Some(format!("Use a `{expected}` for parameter names"))
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ pub struct PytestDuplicateParametrizeTestCases {
|
|||
}
|
||||
|
||||
impl Violation for PytestDuplicateParametrizeTestCases {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -242,7 +242,7 @@ impl Violation for PytestDuplicateParametrizeTestCases {
|
|||
format!("Duplicate of test case at index {index} in `@pytest_mark.parametrize`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Remove duplicate test case".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -453,7 +453,7 @@ impl UnittestAssert {
|
|||
Ok(assert(&node.into(), msg))
|
||||
}
|
||||
}
|
||||
_ => bail!("Cannot autofix `{self}`"),
|
||||
_ => bail!("Cannot fix `{self}`"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ PT018.py:33:5: PT018 [*] Assertion should be broken down into multiple parts
|
|||
34 |+ assert (b or c)
|
||||
34 35 | assert not (a or not (b and c))
|
||||
35 36 |
|
||||
36 37 | # detected, but no autofix for messages
|
||||
36 37 | # detected, but no fix for messages
|
||||
|
||||
PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts
|
||||
|
|
||||
|
@ -237,7 +237,7 @@ PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts
|
|||
34 | assert not (a or not (b and c))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
|
||||
35 |
|
||||
36 | # detected, but no autofix for messages
|
||||
36 | # detected, but no fix for messages
|
||||
|
|
||||
= help: Break down assertion into multiple parts
|
||||
|
||||
|
@ -249,26 +249,26 @@ PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts
|
|||
34 |+ assert not a
|
||||
35 |+ assert (b and c)
|
||||
35 36 |
|
||||
36 37 | # detected, but no autofix for messages
|
||||
36 37 | # detected, but no fix for messages
|
||||
37 38 | assert something and something_else, "error message"
|
||||
|
||||
PT018.py:37:5: PT018 Assertion should be broken down into multiple parts
|
||||
|
|
||||
36 | # detected, but no autofix for messages
|
||||
36 | # detected, but no fix for messages
|
||||
37 | assert something and something_else, "error message"
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
|
||||
38 | assert not (something or something_else and something_third), "with message"
|
||||
39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`)
|
||||
39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`)
|
||||
|
|
||||
= help: Break down assertion into multiple parts
|
||||
|
||||
PT018.py:38:5: PT018 Assertion should be broken down into multiple parts
|
||||
|
|
||||
36 | # detected, but no autofix for messages
|
||||
36 | # detected, but no fix for messages
|
||||
37 | assert something and something_else, "error message"
|
||||
38 | assert not (something or something_else and something_third), "with message"
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
|
||||
39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`)
|
||||
39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`)
|
||||
40 | assert not (something or something_else and something_third)
|
||||
|
|
||||
= help: Break down assertion into multiple parts
|
||||
|
@ -276,7 +276,7 @@ PT018.py:38:5: PT018 Assertion should be broken down into multiple parts
|
|||
PT018.py:40:5: PT018 Assertion should be broken down into multiple parts
|
||||
|
|
||||
38 | assert not (something or something_else and something_third), "with message"
|
||||
39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`)
|
||||
39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`)
|
||||
40 | assert not (something or something_else and something_third)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
|
||||
|
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_python_parser::lexer::LexResult;
|
|||
use ruff_python_parser::Tok;
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
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::Locator;
|
||||
|
||||
|
@ -37,7 +37,7 @@ pub struct BadQuotesInlineString {
|
|||
quote: Quote,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for BadQuotesInlineString {
|
||||
impl AlwaysFixableViolation for BadQuotesInlineString {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BadQuotesInlineString { quote } = self;
|
||||
|
@ -47,7 +47,7 @@ impl AlwaysAutofixableViolation for BadQuotesInlineString {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let BadQuotesInlineString { quote } = self;
|
||||
match quote {
|
||||
Quote::Double => "Replace single quotes with double quotes".to_string(),
|
||||
|
@ -86,7 +86,7 @@ pub struct BadQuotesMultilineString {
|
|||
quote: Quote,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for BadQuotesMultilineString {
|
||||
impl AlwaysFixableViolation for BadQuotesMultilineString {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BadQuotesMultilineString { quote } = self;
|
||||
|
@ -96,7 +96,7 @@ impl AlwaysAutofixableViolation for BadQuotesMultilineString {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let BadQuotesMultilineString { quote } = self;
|
||||
match quote {
|
||||
Quote::Double => "Replace single multiline quotes with double quotes".to_string(),
|
||||
|
@ -134,7 +134,7 @@ pub struct BadQuotesDocstring {
|
|||
quote: Quote,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for BadQuotesDocstring {
|
||||
impl AlwaysFixableViolation for BadQuotesDocstring {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let BadQuotesDocstring { quote } = self;
|
||||
|
@ -144,7 +144,7 @@ impl AlwaysAutofixableViolation for BadQuotesDocstring {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let BadQuotesDocstring { quote } = self;
|
||||
match quote {
|
||||
Quote::Double => "Replace single quotes docstring with double quotes".to_string(),
|
||||
|
@ -173,13 +173,13 @@ impl AlwaysAutofixableViolation for BadQuotesDocstring {
|
|||
#[violation]
|
||||
pub struct AvoidableEscapedQuote;
|
||||
|
||||
impl AlwaysAutofixableViolation for AvoidableEscapedQuote {
|
||||
impl AlwaysFixableViolation for AvoidableEscapedQuote {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Change outer quotes to avoid escaping inner quotes")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Change outer quotes to avoid escaping inner quotes".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::{self as ast, Expr};
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -31,13 +31,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct UnnecessaryParenOnRaiseException;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryParenOnRaiseException {
|
||||
impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Unnecessary parentheses on raised exception")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Remove unnecessary parentheses")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::ops::Add;
|
|||
use ruff_python_ast::{self as ast, ElifElseClause, Expr, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
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::helpers::is_const_none;
|
||||
|
@ -14,8 +14,8 @@ use ruff_python_ast::whitespace::indentation;
|
|||
use ruff_python_semantic::SemanticModel;
|
||||
use ruff_python_trivia::is_python_whitespace;
|
||||
|
||||
use crate::autofix::edits;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::edits;
|
||||
use crate::registry::{AsRule, Rule};
|
||||
use crate::rules::flake8_return::helpers::end_of_last_statement;
|
||||
|
||||
|
@ -51,7 +51,7 @@ use super::super::visitor::{ReturnVisitor, Stack};
|
|||
#[violation]
|
||||
pub struct UnnecessaryReturnNone;
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryReturnNone {
|
||||
impl AlwaysFixableViolation for UnnecessaryReturnNone {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!(
|
||||
|
@ -59,7 +59,7 @@ impl AlwaysAutofixableViolation for UnnecessaryReturnNone {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove explicit `return None`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -93,13 +93,13 @@ impl AlwaysAutofixableViolation for UnnecessaryReturnNone {
|
|||
#[violation]
|
||||
pub struct ImplicitReturnValue;
|
||||
|
||||
impl AlwaysAutofixableViolation for ImplicitReturnValue {
|
||||
impl AlwaysFixableViolation for ImplicitReturnValue {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Do not implicitly `return None` in function able to return non-`None` value")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add explicit `None` return value".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -131,13 +131,13 @@ impl AlwaysAutofixableViolation for ImplicitReturnValue {
|
|||
#[violation]
|
||||
pub struct ImplicitReturn;
|
||||
|
||||
impl AlwaysAutofixableViolation for ImplicitReturn {
|
||||
impl AlwaysFixableViolation for ImplicitReturn {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing explicit `return` at the end of function able to return non-`None` value")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Add explicit `return` statement".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -167,14 +167,14 @@ pub struct UnnecessaryAssign {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for UnnecessaryAssign {
|
||||
impl AlwaysFixableViolation for UnnecessaryAssign {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let UnnecessaryAssign { name } = self;
|
||||
format!("Unnecessary assignment to `{name}` before `return` statement")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove unnecessary assignment".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ RET504.py:342:12: RET504 [*] Unnecessary assignment to `b` before `return` state
|
|||
= help: Remove unnecessary assignment
|
||||
|
||||
ℹ Suggested fix
|
||||
338 338 | # Autofix cases
|
||||
338 338 | # Fix cases
|
||||
339 339 | def foo():
|
||||
340 340 | a = 1
|
||||
341 |- b=a
|
||||
|
|
|
@ -7,7 +7,7 @@ use ruff_python_ast::{self as ast, Arguments, BoolOp, CmpOp, Expr, ExprContext,
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::comparable::ComparableExpr;
|
||||
use ruff_python_ast::helpers::{contains_effect, Truthiness};
|
||||
|
@ -49,7 +49,7 @@ pub struct DuplicateIsinstanceCall {
|
|||
}
|
||||
|
||||
impl Violation for DuplicateIsinstanceCall {
|
||||
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 DuplicateIsinstanceCall {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let DuplicateIsinstanceCall { name } = self;
|
||||
|
||||
Some(if let Some(name) = name {
|
||||
|
@ -99,14 +99,14 @@ pub struct CompareWithTuple {
|
|||
replacement: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for CompareWithTuple {
|
||||
impl AlwaysFixableViolation for CompareWithTuple {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let CompareWithTuple { replacement } = self;
|
||||
format!("Use `{replacement}` instead of multiple equality comparisons")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let CompareWithTuple { replacement } = self;
|
||||
format!("Replace with `{replacement}`")
|
||||
}
|
||||
|
@ -132,14 +132,14 @@ pub struct ExprAndNotExpr {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for ExprAndNotExpr {
|
||||
impl AlwaysFixableViolation for ExprAndNotExpr {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ExprAndNotExpr { name } = self;
|
||||
format!("Use `False` instead of `{name} and not {name}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `False`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -164,14 +164,14 @@ pub struct ExprOrNotExpr {
|
|||
name: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for ExprOrNotExpr {
|
||||
impl AlwaysFixableViolation for ExprOrNotExpr {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ExprOrNotExpr { name } = self;
|
||||
format!("Use `True` instead of `{name} or not {name}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `True`".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ pub struct ExprOrTrue {
|
|||
remove: ContentAround,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for ExprOrTrue {
|
||||
impl AlwaysFixableViolation for ExprOrTrue {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ExprOrTrue { expr, remove } = self;
|
||||
|
@ -229,7 +229,7 @@ impl AlwaysAutofixableViolation for ExprOrTrue {
|
|||
format!("Use `{expr}` instead of `{replaced}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let ExprOrTrue { expr, .. } = self;
|
||||
format!("Replace with `{expr}`")
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ pub struct ExprAndFalse {
|
|||
remove: ContentAround,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for ExprAndFalse {
|
||||
impl AlwaysFixableViolation for ExprAndFalse {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let ExprAndFalse { expr, remove } = self;
|
||||
|
@ -281,7 +281,7 @@ impl AlwaysAutofixableViolation for ExprAndFalse {
|
|||
format!("Use `{expr}` instead of `{replaced}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let ExprAndFalse { expr, .. } = self;
|
||||
format!("Replace with `{expr}`")
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Constant, Expr};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix::snippet::SourceCodeSnippet;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use crate::fix::snippet::SourceCodeSnippet;
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::is_const_none;
|
||||
|
||||
|
@ -41,7 +41,7 @@ pub struct UncapitalizedEnvironmentVariables {
|
|||
}
|
||||
|
||||
impl Violation for UncapitalizedEnvironmentVariables {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -53,7 +53,7 @@ impl Violation for UncapitalizedEnvironmentVariables {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let UncapitalizedEnvironmentVariables { expected, actual } = self;
|
||||
if let (Some(expected), Some(actual)) = (expected.full_display(), actual.full_display()) {
|
||||
Some(format!("Replace `{actual}` with `{expected}`"))
|
||||
|
@ -90,7 +90,7 @@ pub struct DictGetWithNoneDefault {
|
|||
actual: SourceCodeSnippet,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for DictGetWithNoneDefault {
|
||||
impl AlwaysFixableViolation for DictGetWithNoneDefault {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let DictGetWithNoneDefault { expected, actual } = self;
|
||||
|
@ -101,7 +101,7 @@ impl AlwaysAutofixableViolation for DictGetWithNoneDefault {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let DictGetWithNoneDefault { expected, actual } = self;
|
||||
if let (Some(expected), Some(actual)) = (expected.full_display(), actual.full_display()) {
|
||||
format!("Replace `{actual}` with `{expected}`")
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_python_ast::{
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
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::comparable::{ComparableConstant, ComparableExpr, ComparableStmt};
|
||||
use ruff_python_ast::helpers::{any_over_expr, contains_effect};
|
||||
|
@ -56,14 +56,14 @@ fn compare_stmt(stmt1: &ComparableStmt, stmt2: &ComparableStmt) -> bool {
|
|||
pub struct CollapsibleIf;
|
||||
|
||||
impl Violation for CollapsibleIf {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use a single `if` statement instead of nested `if` statements")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Combine `if` statements using `and`".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ pub struct NeedlessBool {
|
|||
}
|
||||
|
||||
impl Violation for NeedlessBool {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -104,7 +104,7 @@ impl Violation for NeedlessBool {
|
|||
format!("Return the condition `{condition}` directly")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let NeedlessBool { condition } = self;
|
||||
Some(format!("Replace with `return {condition}`"))
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ pub struct IfElseBlockInsteadOfIfExp {
|
|||
}
|
||||
|
||||
impl Violation for IfElseBlockInsteadOfIfExp {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -176,7 +176,7 @@ impl Violation for IfElseBlockInsteadOfIfExp {
|
|||
format!("Use ternary operator `{contents}` instead of `if`-`else`-block")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let IfElseBlockInsteadOfIfExp { contents } = self;
|
||||
Some(format!("Replace `if`-`else`-block with `{contents}`"))
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ pub struct IfElseBlockInsteadOfDictGet {
|
|||
}
|
||||
|
||||
impl Violation for IfElseBlockInsteadOfDictGet {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -250,7 +250,7 @@ impl Violation for IfElseBlockInsteadOfDictGet {
|
|||
format!("Use `{contents}` instead of an `if` block")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let IfElseBlockInsteadOfDictGet { contents } = self;
|
||||
Some(format!("Replace with `{contents}`"))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, UnaryOp};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::{is_const_false, is_const_true};
|
||||
use ruff_python_ast::parenthesize::parenthesized_range;
|
||||
|
@ -35,7 +35,7 @@ pub struct IfExprWithTrueFalse {
|
|||
}
|
||||
|
||||
impl Violation for IfExprWithTrueFalse {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -47,7 +47,7 @@ impl Violation for IfExprWithTrueFalse {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let IfExprWithTrueFalse { is_compare } = self;
|
||||
if *is_compare {
|
||||
Some(format!("Remove unnecessary `True if ... else False`"))
|
||||
|
@ -81,13 +81,13 @@ impl Violation for IfExprWithTrueFalse {
|
|||
#[violation]
|
||||
pub struct IfExprWithFalseTrue;
|
||||
|
||||
impl AlwaysAutofixableViolation for IfExprWithFalseTrue {
|
||||
impl AlwaysFixableViolation for IfExprWithFalseTrue {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Use `not ...` instead of `False if ... else True`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Replace with `not ...`")
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ pub struct IfExprWithTwistedArms {
|
|||
expr_else: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for IfExprWithTwistedArms {
|
||||
impl AlwaysFixableViolation for IfExprWithTwistedArms {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let IfExprWithTwistedArms {
|
||||
|
@ -130,7 +130,7 @@ impl AlwaysAutofixableViolation for IfExprWithTwistedArms {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let IfExprWithTwistedArms {
|
||||
expr_body,
|
||||
expr_else,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, CmpOp, Expr, ExprContext, Stmt, UnaryOp};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::ScopeKind;
|
||||
|
||||
|
@ -33,14 +33,14 @@ pub struct NegateEqualOp {
|
|||
right: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for NegateEqualOp {
|
||||
impl AlwaysFixableViolation for NegateEqualOp {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let NegateEqualOp { left, right } = self;
|
||||
format!("Use `{left} != {right}` instead of `not {left} == {right}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `!=` operator".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -70,14 +70,14 @@ pub struct NegateNotEqualOp {
|
|||
right: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for NegateNotEqualOp {
|
||||
impl AlwaysFixableViolation for NegateNotEqualOp {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let NegateNotEqualOp { left, right } = self;
|
||||
format!("Use `{left} == {right}` instead of `not {left} != {right}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Replace with `==` operator".to_string()
|
||||
}
|
||||
}
|
||||
|
@ -106,14 +106,14 @@ pub struct DoubleNegation {
|
|||
expr: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for DoubleNegation {
|
||||
impl AlwaysFixableViolation for DoubleNegation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let DoubleNegation { expr } = self;
|
||||
format!("Use `{expr}` instead of `not (not {expr})`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let DoubleNegation { expr } = self;
|
||||
format!("Replace with `{expr}`")
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use log::error;
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix};
|
||||
use ruff_diagnostics::{FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Stmt, WithItem};
|
||||
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
|
||||
|
@ -45,7 +45,7 @@ use super::fix_with;
|
|||
pub struct MultipleWithStatements;
|
||||
|
||||
impl Violation for MultipleWithStatements {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -55,7 +55,7 @@ impl Violation for MultipleWithStatements {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Combine `with` statements".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ use ruff_python_codegen::Stylist;
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::cst::helpers::space;
|
||||
use crate::cst::matchers::{match_function_def, match_if, match_indented_block, match_statement};
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
|
||||
fn parenthesize_and_operand(expr: Expression) -> Expression {
|
||||
match &expr {
|
||||
|
|
|
@ -8,8 +8,8 @@ use ruff_python_codegen::Stylist;
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::codemods::CodegenStylist;
|
||||
use crate::cst::matchers::{match_function_def, match_indented_block, match_statement, match_with};
|
||||
use crate::fix::codemods::CodegenStylist;
|
||||
|
||||
/// (SIM117) Convert `with a: with b:` to `with a, b:`.
|
||||
pub(crate) fn fix_multiple_with_statements(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ruff_diagnostics::Edit;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::parenthesize::parenthesized_range;
|
||||
|
@ -35,14 +35,14 @@ pub struct InDictKeys {
|
|||
operator: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for InDictKeys {
|
||||
impl AlwaysFixableViolation for InDictKeys {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let InDictKeys { operator } = self;
|
||||
format!("Use `key {operator} dict` instead of `key {operator} dict.keys()`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let InDictKeys { operator: _ } = self;
|
||||
format!("Remove `.keys()`")
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::{
|
|||
};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
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::helpers::any_over_expr;
|
||||
use ruff_python_ast::traversal;
|
||||
|
@ -43,7 +43,7 @@ pub struct ReimplementedBuiltin {
|
|||
}
|
||||
|
||||
impl Violation for ReimplementedBuiltin {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -51,7 +51,7 @@ impl Violation for ReimplementedBuiltin {
|
|||
format!("Use `{replacement}` instead of `for` loop")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let ReimplementedBuiltin { replacement } = self;
|
||||
Some(format!("Replace with `{replacement}`"))
|
||||
}
|
||||
|
|
|
@ -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::call_path::compose_call_path;
|
||||
use ruff_python_ast::helpers;
|
||||
|
@ -48,7 +48,7 @@ pub struct SuppressibleException {
|
|||
}
|
||||
|
||||
impl Violation for SuppressibleException {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -56,7 +56,7 @@ impl Violation for SuppressibleException {
|
|||
format!("Use `contextlib.suppress({exception})` instead of `try`-`except`-`pass`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let SuppressibleException { exception } = self;
|
||||
Some(format!("Replace with `contextlib.suppress({exception})`"))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use anyhow::Result;
|
||||
use libcst_native::CompOp;
|
||||
|
||||
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::{self as ast, CmpOp, Expr, UnaryOp};
|
||||
use ruff_python_codegen::Stylist;
|
||||
|
@ -9,11 +9,11 @@ use ruff_python_stdlib::str::{self};
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix::edits::pad;
|
||||
use crate::autofix::snippet::SourceCodeSnippet;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::cst::helpers::or_space;
|
||||
use crate::cst::matchers::{match_comparison, transform_expression};
|
||||
use crate::fix::edits::pad;
|
||||
use crate::fix::snippet::SourceCodeSnippet;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -52,7 +52,7 @@ pub struct YodaConditions {
|
|||
}
|
||||
|
||||
impl Violation for YodaConditions {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -67,7 +67,7 @@ impl Violation for YodaConditions {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let YodaConditions { suggestion } = self;
|
||||
suggestion.as_ref().map(|suggestion| {
|
||||
if let Some(suggestion) = suggestion.full_display() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_python_ast::{self as ast, Identifier, Stmt};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
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::helpers::resolve_imported_module_path;
|
||||
use ruff_python_codegen::Generator;
|
||||
|
@ -51,7 +51,7 @@ pub struct RelativeImports {
|
|||
}
|
||||
|
||||
impl Violation for RelativeImports {
|
||||
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 RelativeImports {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let RelativeImports { strictness } = self;
|
||||
Some(match strictness {
|
||||
Strictness::Parents => {
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruff_python_index::Indexer;
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::settings::LinterSettings;
|
||||
|
@ -184,14 +184,14 @@ pub struct InvalidTodoCapitalization {
|
|||
tag: String,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for InvalidTodoCapitalization {
|
||||
impl AlwaysFixableViolation for InvalidTodoCapitalization {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let InvalidTodoCapitalization { tag } = self;
|
||||
format!("Invalid TODO capitalization: `{tag}` should be `TODO`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let InvalidTodoCapitalization { tag } = self;
|
||||
format!("Replace `{tag}` with `TODO`")
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use ruff_python_ast as ast;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix;
|
||||
use crate::registry::AsRule;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -35,13 +35,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct EmptyTypeCheckingBlock;
|
||||
|
||||
impl AlwaysAutofixableViolation for EmptyTypeCheckingBlock {
|
||||
impl AlwaysFixableViolation for EmptyTypeCheckingBlock {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Found empty type-checking block")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
format!("Delete empty type-checking block")
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtI
|
|||
// Delete the entire type-checking block.
|
||||
let stmt = checker.semantic().current_statement();
|
||||
let parent = checker.semantic().current_statement_parent();
|
||||
let edit = autofix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer());
|
||||
let edit = fix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer());
|
||||
diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(
|
||||
checker.semantic().current_statement_parent_id(),
|
||||
)));
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::borrow::Cow;
|
|||
use anyhow::Result;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::{AnyImport, Imported, NodeId, ResolvedReferenceId, Scope};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::codes::Rule;
|
||||
use crate::fix;
|
||||
use crate::importer::ImportedMembers;
|
||||
|
||||
/// ## What it does
|
||||
|
@ -49,7 +49,7 @@ pub struct RuntimeImportInTypeCheckingBlock {
|
|||
}
|
||||
|
||||
impl Violation for RuntimeImportInTypeCheckingBlock {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -59,7 +59,7 @@ impl Violation for RuntimeImportInTypeCheckingBlock {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Move out of type-checking block".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) ->
|
|||
.expect("Expected at least one import");
|
||||
|
||||
// Step 1) Remove the import.
|
||||
let remove_import_edit = autofix::edits::remove_unused_imports(
|
||||
let remove_import_edit = fix::edits::remove_unused_imports(
|
||||
member_names.iter().map(AsRef::as_ref),
|
||||
statement,
|
||||
parent,
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::borrow::Cow;
|
|||
use anyhow::Result;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff_diagnostics::{AutofixKind, Diagnostic, DiagnosticKind, Fix, Violation};
|
||||
use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix, FixKind, Violation};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_semantic::{AnyImport, Binding, Imported, NodeId, ResolvedReferenceId, Scope};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::codes::Rule;
|
||||
use crate::fix;
|
||||
use crate::importer::ImportedMembers;
|
||||
use crate::rules::isort::{categorize, ImportSection, ImportType};
|
||||
|
||||
|
@ -67,7 +67,7 @@ pub struct TypingOnlyFirstPartyImport {
|
|||
}
|
||||
|
||||
impl Violation for TypingOnlyFirstPartyImport {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -77,7 +77,7 @@ impl Violation for TypingOnlyFirstPartyImport {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Move into type-checking block".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ pub struct TypingOnlyThirdPartyImport {
|
|||
}
|
||||
|
||||
impl Violation for TypingOnlyThirdPartyImport {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -145,7 +145,7 @@ impl Violation for TypingOnlyThirdPartyImport {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Move into type-checking block".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ pub struct TypingOnlyStandardLibraryImport {
|
|||
}
|
||||
|
||||
impl Violation for TypingOnlyStandardLibraryImport {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -213,7 +213,7 @@ impl Violation for TypingOnlyStandardLibraryImport {
|
|||
)
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Move into type-checking block".to_string())
|
||||
}
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) ->
|
|||
.expect("Expected at least one import");
|
||||
|
||||
// Step 1) Remove the import.
|
||||
let remove_import_edit = autofix::edits::remove_unused_imports(
|
||||
let remove_import_edit = fix::edits::remove_unused_imports(
|
||||
member_names.iter().map(AsRef::as_ref),
|
||||
statement,
|
||||
parent,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprCall, ExprConstant};
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
@ -33,13 +33,13 @@ use crate::registry::AsRule;
|
|||
#[violation]
|
||||
pub struct PathConstructorCurrentDirectory;
|
||||
|
||||
impl AlwaysAutofixableViolation for PathConstructorCurrentDirectory {
|
||||
impl AlwaysFixableViolation for PathConstructorCurrentDirectory {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Do not pass the current directory explicitly to `Path`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
"Remove the current directory argument".to_string()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use itertools::Itertools;
|
||||
|
||||
use crate::autofix::edits::pad;
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
|
||||
use crate::fix::edits::pad;
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::{self as ast, Arguments, Constant, Expr};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::autofix::snippet::SourceCodeSnippet;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::fix::snippet::SourceCodeSnippet;
|
||||
use crate::registry::AsRule;
|
||||
use crate::rules::flynt::helpers;
|
||||
|
||||
|
@ -34,7 +34,7 @@ pub struct StaticJoinToFString {
|
|||
expression: SourceCodeSnippet,
|
||||
}
|
||||
|
||||
impl AlwaysAutofixableViolation for StaticJoinToFString {
|
||||
impl AlwaysFixableViolation for StaticJoinToFString {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let StaticJoinToFString { expression } = self;
|
||||
|
@ -45,7 +45,7 @@ impl AlwaysAutofixableViolation for StaticJoinToFString {
|
|||
}
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let StaticJoinToFString { expression } = self;
|
||||
if let Some(expression) = expression.full_display() {
|
||||
format!("Replace with `{expression}`")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use log::error;
|
||||
|
||||
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
|
||||
use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_ast::helpers::is_docstring_stmt;
|
||||
use ruff_python_ast::imports::{Alias, AnyImport, FutureImport, Import, ImportFrom};
|
||||
|
@ -40,14 +40,14 @@ use crate::settings::LinterSettings;
|
|||
#[violation]
|
||||
pub struct MissingRequiredImport(pub String);
|
||||
|
||||
impl AlwaysAutofixableViolation for MissingRequiredImport {
|
||||
impl AlwaysFixableViolation for MissingRequiredImport {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let MissingRequiredImport(name) = self;
|
||||
format!("Missing required import: `{name}`")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> String {
|
||||
fn fix_title(&self) -> String {
|
||||
let MissingRequiredImport(name) = self;
|
||||
format!("Insert required import: `{name}`")
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::path::Path;
|
|||
|
||||
use itertools::{EitherOrBoth, Itertools};
|
||||
|
||||
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::whitespace::trailing_lines_end;
|
||||
use ruff_python_ast::{PySourceType, Stmt};
|
||||
|
@ -41,14 +41,14 @@ use super::super::{comments, format_imports};
|
|||
pub struct UnsortedImports;
|
||||
|
||||
impl Violation for UnsortedImports {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Import block is un-sorted or un-formatted")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some("Organize imports".to_string())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::Expr;
|
||||
use ruff_text_size::Ranged;
|
||||
|
@ -37,7 +37,7 @@ pub struct NumpyDeprecatedFunction {
|
|||
}
|
||||
|
||||
impl Violation for NumpyDeprecatedFunction {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Sometimes;
|
||||
const FIX_KIND: FixKind = FixKind::Sometimes;
|
||||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
|
@ -48,7 +48,7 @@ impl Violation for NumpyDeprecatedFunction {
|
|||
format!("`np.{existing}` is deprecated; use `np.{replacement}` instead")
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
let NumpyDeprecatedFunction { replacement, .. } = self;
|
||||
Some(format!("Replace with `np.{replacement}`"))
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue