mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-07 21:25:08 +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
.github/release.yml
vendored
1
.github/release.yml
vendored
|
@ -12,7 +12,6 @@ changelog:
|
|||
- title: Rules
|
||||
labels:
|
||||
- rule
|
||||
- autofix
|
||||
- title: Settings
|
||||
labels:
|
||||
- configuration
|
||||
|
|
|
@ -204,7 +204,7 @@ As such, rule names should...
|
|||
For example, `AssertFalse` guards against `assert False` statements.
|
||||
|
||||
- _Not_ contain instructions on how to fix the violation, which instead belong in the rule
|
||||
documentation and the `autofix_title`.
|
||||
documentation and the `fix_title`.
|
||||
|
||||
- _Not_ contain a redundant prefix, like `Disallow` or `Banned`, which are already implied by the
|
||||
convention.
|
||||
|
|
|
@ -29,7 +29,7 @@ An extremely fast Python linter, written in Rust.
|
|||
- 🛠️ `pyproject.toml` support
|
||||
- 🤝 Python 3.11 compatibility
|
||||
- 📦 Built-in caching, to avoid re-analyzing unchanged files
|
||||
- 🔧 Autofix support, for automatic error correction (e.g., automatically remove unused imports)
|
||||
- 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports)
|
||||
- 📏 Over [700 built-in rules](https://docs.astral.sh/ruff/rules/)
|
||||
- ⚖️ [Near-parity](https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-flake8) with the
|
||||
built-in Flake8 rule set
|
||||
|
@ -176,7 +176,7 @@ If left unspecified, the default configuration is equivalent to:
|
|||
select = ["E", "F"]
|
||||
ignore = []
|
||||
|
||||
# Allow autofix for all enabled rules (when `--fix`) is provided.
|
||||
# Allow fix for all enabled rules (when `--fix`) is provided.
|
||||
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
|
||||
unfixable = []
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ pub struct CheckCommand {
|
|||
show_source: bool,
|
||||
#[clap(long, overrides_with("show_source"), hide = true)]
|
||||
no_show_source: bool,
|
||||
/// Show an enumeration of all autofixed lint violations.
|
||||
/// Show an enumeration of all fixed lint violations.
|
||||
/// Use `--no-show-fixes` to disable.
|
||||
#[arg(long, overrides_with("no_show_fixes"))]
|
||||
show_fixes: bool,
|
||||
|
@ -202,7 +202,7 @@ pub struct CheckCommand {
|
|||
help_heading = "File selection"
|
||||
)]
|
||||
pub extend_exclude: Option<Vec<FilePattern>>,
|
||||
/// List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`).
|
||||
/// List of rule codes to treat as eligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`).
|
||||
#[arg(
|
||||
long,
|
||||
value_delimiter = ',',
|
||||
|
@ -212,7 +212,7 @@ pub struct CheckCommand {
|
|||
hide_possible_values = true
|
||||
)]
|
||||
pub fixable: Option<Vec<RuleSelector>>,
|
||||
/// List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`).
|
||||
/// List of rule codes to treat as ineligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`).
|
||||
#[arg(
|
||||
long,
|
||||
value_delimiter = ',',
|
||||
|
@ -288,7 +288,7 @@ pub struct CheckCommand {
|
|||
conflicts_with = "exit_non_zero_on_fix"
|
||||
)]
|
||||
pub exit_zero: bool,
|
||||
/// Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain.
|
||||
/// Exit with a non-zero status code if any files were modified via fix, even if no lint violations remain.
|
||||
#[arg(long, help_heading = "Miscellaneous", conflicts_with = "exit_zero")]
|
||||
pub exit_non_zero_on_fix: bool,
|
||||
/// Show counts for every rule with at least one violation.
|
||||
|
|
|
@ -35,7 +35,7 @@ pub(crate) fn check(
|
|||
overrides: &CliOverrides,
|
||||
cache: flags::Cache,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
// Collect all the Python files to check.
|
||||
let start = Instant::now();
|
||||
|
@ -119,7 +119,7 @@ pub(crate) fn check(
|
|||
}
|
||||
});
|
||||
|
||||
lint_path(path, package, &settings.linter, cache, noqa, autofix).map_err(|e| {
|
||||
lint_path(path, package, &settings.linter, cache, noqa, fix_mode).map_err(|e| {
|
||||
(Some(path.to_owned()), {
|
||||
let mut error = e.to_string();
|
||||
for cause in e.chain() {
|
||||
|
@ -198,10 +198,10 @@ fn lint_path(
|
|||
settings: &LinterSettings,
|
||||
cache: Option<&Cache>,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
let result = catch_unwind(|| {
|
||||
crate::diagnostics::lint_path(path, package, settings, cache, noqa, autofix)
|
||||
crate::diagnostics::lint_path(path, package, settings, cache, noqa, fix_mode)
|
||||
});
|
||||
|
||||
match result {
|
||||
|
|
|
@ -16,7 +16,7 @@ pub(crate) fn check_stdin(
|
|||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &CliOverrides,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
if let Some(filename) = filename {
|
||||
if !python_file_at_path(filename, pyproject_config, overrides)? {
|
||||
|
@ -33,7 +33,7 @@ pub(crate) fn check_stdin(
|
|||
stdin,
|
||||
&pyproject_config.settings,
|
||||
noqa,
|
||||
autofix,
|
||||
fix_mode,
|
||||
)?;
|
||||
diagnostics.messages.sort_unstable();
|
||||
Ok(diagnostics)
|
||||
|
|
|
@ -5,7 +5,7 @@ use serde::ser::SerializeSeq;
|
|||
use serde::{Serialize, Serializer};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff_diagnostics::AutofixKind;
|
||||
use ruff_diagnostics::FixKind;
|
||||
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
|
||||
|
||||
use crate::args::HelpFormat;
|
||||
|
@ -17,7 +17,7 @@ struct Explanation<'a> {
|
|||
linter: &'a str,
|
||||
summary: &'a str,
|
||||
message_formats: &'a [&'a str],
|
||||
autofix: String,
|
||||
fix: String,
|
||||
explanation: Option<&'a str>,
|
||||
preview: bool,
|
||||
}
|
||||
|
@ -26,14 +26,14 @@ impl<'a> Explanation<'a> {
|
|||
fn from_rule(rule: &'a Rule) -> Self {
|
||||
let code = rule.noqa_code().to_string();
|
||||
let (linter, _) = Linter::parse_code(&code).unwrap();
|
||||
let autofix = rule.autofixable().to_string();
|
||||
let fix = rule.fixable().to_string();
|
||||
Self {
|
||||
name: rule.as_ref(),
|
||||
code,
|
||||
linter: linter.name(),
|
||||
summary: rule.message_formats()[0],
|
||||
message_formats: rule.message_formats(),
|
||||
autofix,
|
||||
fix,
|
||||
explanation: rule.explanation(),
|
||||
preview: rule.is_preview(),
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ fn format_rule_text(rule: Rule) -> String {
|
|||
output.push('\n');
|
||||
output.push('\n');
|
||||
|
||||
let autofix = rule.autofixable();
|
||||
if matches!(autofix, AutofixKind::Always | AutofixKind::Sometimes) {
|
||||
output.push_str(&autofix.to_string());
|
||||
let fix_kind = rule.fixable();
|
||||
if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) {
|
||||
output.push_str(&fix_kind.to_string());
|
||||
output.push('\n');
|
||||
output.push('\n');
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ pub(crate) fn lint_path(
|
|||
settings: &LinterSettings,
|
||||
cache: Option<&Cache>,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
// Check the cache.
|
||||
// TODO(charlie): `fixer::Mode::Apply` and `fixer::Mode::Diff` both have
|
||||
|
@ -156,7 +156,7 @@ pub(crate) fn lint_path(
|
|||
// write the fixes to disk, thus invalidating the cache. But it's a bit hard
|
||||
// to reason about. We need to come up with a better solution here.)
|
||||
let caching = match cache {
|
||||
Some(cache) if noqa.into() && autofix.is_generate() => {
|
||||
Some(cache) if noqa.into() && fix_mode.is_generate() => {
|
||||
let relative_path = cache
|
||||
.relative_path(path)
|
||||
.expect("wrong package cache for file");
|
||||
|
@ -220,7 +220,7 @@ pub(crate) fn lint_path(
|
|||
error: parse_error,
|
||||
},
|
||||
fixed,
|
||||
) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
) = if matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
if let Ok(FixerResult {
|
||||
result,
|
||||
transformed,
|
||||
|
@ -228,7 +228,7 @@ pub(crate) fn lint_path(
|
|||
}) = lint_fix(path, package, noqa, settings, &source_kind, source_type)
|
||||
{
|
||||
if !fixed.is_empty() {
|
||||
match autofix {
|
||||
match fix_mode {
|
||||
flags::FixMode::Apply => match transformed.as_ref() {
|
||||
SourceKind::Python(transformed) => {
|
||||
write(path, transformed.as_bytes())?;
|
||||
|
@ -301,7 +301,7 @@ pub(crate) fn lint_path(
|
|||
}
|
||||
(result, fixed)
|
||||
} else {
|
||||
// If we fail to autofix, lint the original source code.
|
||||
// If we fail to fix, lint the original source code.
|
||||
let result = lint_only(path, package, settings, noqa, &source_kind, source_type);
|
||||
let fixed = FxHashMap::default();
|
||||
(result, fixed)
|
||||
|
@ -369,7 +369,7 @@ pub(crate) fn lint_stdin(
|
|||
contents: String,
|
||||
settings: &Settings,
|
||||
noqa: flags::Noqa,
|
||||
autofix: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
// TODO(charlie): Support `pyproject.toml`.
|
||||
let SourceType::Python(source_type) = path.map(SourceType::from).unwrap_or_default() else {
|
||||
|
@ -392,7 +392,7 @@ pub(crate) fn lint_stdin(
|
|||
error: parse_error,
|
||||
},
|
||||
fixed,
|
||||
) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
) = if matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
if let Ok(FixerResult {
|
||||
result,
|
||||
transformed,
|
||||
|
@ -405,7 +405,7 @@ pub(crate) fn lint_stdin(
|
|||
&source_kind,
|
||||
source_type,
|
||||
) {
|
||||
match autofix {
|
||||
match fix_mode {
|
||||
flags::FixMode::Apply => {
|
||||
// Write the contents to stdout, regardless of whether any errors were fixed.
|
||||
io::stdout().write_all(transformed.source_code().as_bytes())?;
|
||||
|
@ -434,7 +434,7 @@ pub(crate) fn lint_stdin(
|
|||
|
||||
(result, fixed)
|
||||
} else {
|
||||
// If we fail to autofix, lint the original source code.
|
||||
// If we fail to fix, lint the original source code.
|
||||
let result = lint_only(
|
||||
path.unwrap_or_else(|| Path::new("-")),
|
||||
package,
|
||||
|
@ -446,7 +446,7 @@ pub(crate) fn lint_stdin(
|
|||
let fixed = FxHashMap::default();
|
||||
|
||||
// Write the contents to stdout anyway.
|
||||
if autofix.is_apply() {
|
||||
if fix_mode.is_apply() {
|
||||
io::stdout().write_all(source_kind.source_code().as_bytes())?;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,13 +234,13 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
..
|
||||
} = pyproject_config.settings;
|
||||
|
||||
// Autofix rules are as follows:
|
||||
// Fix rules are as follows:
|
||||
// - By default, generate all fixes, but don't apply them to the filesystem.
|
||||
// - If `--fix` or `--fix-only` is set, always apply fixes to the filesystem (or
|
||||
// print them to stdout, if we're reading from stdin).
|
||||
// - If `--diff` or `--fix-only` are set, don't print any violations (only
|
||||
// fixes).
|
||||
let autofix = if cli.diff {
|
||||
let fix_mode = if cli.diff {
|
||||
flags::FixMode::Diff
|
||||
} else if fix || fix_only {
|
||||
flags::FixMode::Apply
|
||||
|
@ -275,7 +275,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
}
|
||||
|
||||
if cli.add_noqa {
|
||||
if !autofix.is_generate() {
|
||||
if !fix_mode.is_generate() {
|
||||
warn_user!("--fix is incompatible with --add-noqa.");
|
||||
}
|
||||
let modifications =
|
||||
|
@ -290,7 +290,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
return Ok(ExitStatus::Success);
|
||||
}
|
||||
|
||||
let printer = Printer::new(output_format, log_level, autofix, printer_flags);
|
||||
let printer = Printer::new(output_format, log_level, fix_mode, printer_flags);
|
||||
|
||||
if cli.watch {
|
||||
if output_format != SerializationFormat::Text {
|
||||
|
@ -317,7 +317,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
&overrides,
|
||||
cache.into(),
|
||||
noqa.into(),
|
||||
autofix,
|
||||
fix_mode,
|
||||
)?;
|
||||
printer.write_continuously(&mut writer, &messages)?;
|
||||
|
||||
|
@ -349,7 +349,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
&overrides,
|
||||
cache.into(),
|
||||
noqa.into(),
|
||||
autofix,
|
||||
fix_mode,
|
||||
)?;
|
||||
printer.write_continuously(&mut writer, &messages)?;
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
&pyproject_config,
|
||||
&overrides,
|
||||
noqa.into(),
|
||||
autofix,
|
||||
fix_mode,
|
||||
)?
|
||||
} else {
|
||||
commands::check::check(
|
||||
|
@ -375,14 +375,14 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
|
|||
&overrides,
|
||||
cache.into(),
|
||||
noqa.into(),
|
||||
autofix,
|
||||
fix_mode,
|
||||
)?
|
||||
};
|
||||
|
||||
// Always try to print violations (the printer itself may suppress output),
|
||||
// unless we're writing fixes via stdin (in which case, the transformed
|
||||
// source code goes to stdout).
|
||||
if !(is_stdin && matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff)) {
|
||||
if !(is_stdin && matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff)) {
|
||||
if cli.statistics {
|
||||
printer.write_statistics(&diagnostics, &mut writer)?;
|
||||
} else {
|
||||
|
|
|
@ -72,7 +72,7 @@ impl From<Rule> for SerializeRuleAsCode {
|
|||
pub(crate) struct Printer {
|
||||
format: SerializationFormat,
|
||||
log_level: LogLevel,
|
||||
autofix_level: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
flags: Flags,
|
||||
}
|
||||
|
||||
|
@ -80,13 +80,13 @@ impl Printer {
|
|||
pub(crate) const fn new(
|
||||
format: SerializationFormat,
|
||||
log_level: LogLevel,
|
||||
autofix_level: flags::FixMode,
|
||||
fix_mode: flags::FixMode,
|
||||
flags: Flags,
|
||||
) -> Self {
|
||||
Self {
|
||||
format,
|
||||
log_level,
|
||||
autofix_level,
|
||||
fix_mode,
|
||||
flags,
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl Printer {
|
|||
writeln!(writer, "Found {remaining} error{s}.")?;
|
||||
}
|
||||
|
||||
if show_fix_status(self.autofix_level) {
|
||||
if show_fix_status(self.fix_mode) {
|
||||
let num_fixable = diagnostics
|
||||
.messages
|
||||
.iter()
|
||||
|
@ -140,7 +140,7 @@ impl Printer {
|
|||
.sum::<usize>();
|
||||
if fixed > 0 {
|
||||
let s = if fixed == 1 { "" } else { "s" };
|
||||
if self.autofix_level.is_apply() {
|
||||
if self.fix_mode.is_apply() {
|
||||
writeln!(writer, "Fixed {fixed} error{s}.")?;
|
||||
} else {
|
||||
writeln!(writer, "Would fix {fixed} error{s}.")?;
|
||||
|
@ -191,7 +191,7 @@ impl Printer {
|
|||
}
|
||||
SerializationFormat::Text => {
|
||||
TextEmitter::default()
|
||||
.with_show_fix_status(show_fix_status(self.autofix_level))
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode))
|
||||
.with_show_fix_diff(self.flags.intersects(Flags::SHOW_FIX_DIFF))
|
||||
.with_show_source(self.flags.intersects(Flags::SHOW_SOURCE))
|
||||
.emit(writer, &diagnostics.messages, &context)?;
|
||||
|
@ -209,7 +209,7 @@ impl Printer {
|
|||
SerializationFormat::Grouped => {
|
||||
GroupedEmitter::default()
|
||||
.with_show_source(self.flags.intersects(Flags::SHOW_SOURCE))
|
||||
.with_show_fix_status(show_fix_status(self.autofix_level))
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode))
|
||||
.emit(writer, &diagnostics.messages, &context)?;
|
||||
|
||||
if self.flags.intersects(Flags::SHOW_FIX_SUMMARY) {
|
||||
|
@ -366,7 +366,7 @@ impl Printer {
|
|||
|
||||
let context = EmitterContext::new(&diagnostics.notebook_indexes);
|
||||
TextEmitter::default()
|
||||
.with_show_fix_status(show_fix_status(self.autofix_level))
|
||||
.with_show_fix_status(show_fix_status(self.fix_mode))
|
||||
.with_show_source(self.flags.intersects(Flags::SHOW_SOURCE))
|
||||
.emit(writer, &diagnostics.messages, &context)?;
|
||||
}
|
||||
|
@ -390,13 +390,13 @@ fn num_digits(n: usize) -> usize {
|
|||
}
|
||||
|
||||
/// Return `true` if the [`Printer`] should indicate that a rule is fixable.
|
||||
const fn show_fix_status(autofix_level: flags::FixMode) -> bool {
|
||||
const fn show_fix_status(fix_mode: flags::FixMode) -> bool {
|
||||
// If we're in application mode, avoid indicating that a rule is fixable.
|
||||
// If the specific violation were truly fixable, it would've been fixed in
|
||||
// this pass! (We're occasionally unable to determine whether a specific
|
||||
// violation is fixable without trying to fix it, so if autofix is not
|
||||
// violation is fixable without trying to fix it, so if fix is not
|
||||
// enabled, we may inadvertently indicate that a rule is fixable.)
|
||||
!autofix_level.is_apply()
|
||||
!fix_mode.is_apply()
|
||||
}
|
||||
|
||||
fn print_fix_summary(writer: &mut dyn Write, fixed: &FxHashMap<String, FixTable>) -> Result<()> {
|
||||
|
|
|
@ -136,7 +136,7 @@ fn stdin_json() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn stdin_autofix() {
|
||||
fn stdin_fix() {
|
||||
let args = ["--fix"];
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(STDIN_BASE_OPTIONS)
|
||||
|
@ -154,7 +154,7 @@ fn stdin_autofix() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn stdin_autofix_when_not_fixable_should_still_print_contents() {
|
||||
fn stdin_fix_when_not_fixable_should_still_print_contents() {
|
||||
let args = ["--fix"];
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(STDIN_BASE_OPTIONS)
|
||||
|
@ -173,7 +173,7 @@ fn stdin_autofix_when_not_fixable_should_still_print_contents() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn stdin_autofix_when_no_issues_should_still_print_contents() {
|
||||
fn stdin_fix_when_no_issues_should_still_print_contents() {
|
||||
let args = ["--fix"];
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(STDIN_BASE_OPTIONS)
|
||||
|
|
|
@ -13,7 +13,7 @@ exit_code: 0
|
|||
|
||||
Derived from the **Pyflakes** linter.
|
||||
|
||||
Autofix is sometimes available.
|
||||
Fix is sometimes available.
|
||||
|
||||
## What it does
|
||||
Checks for unused imports.
|
||||
|
|
|
@ -8,7 +8,7 @@ use anyhow::Result;
|
|||
use regex::{Captures, Regex};
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff_diagnostics::AutofixKind;
|
||||
use ruff_diagnostics::FixKind;
|
||||
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
|
||||
use ruff_workspace::options::Options;
|
||||
use ruff_workspace::options_base::OptionsMetadata;
|
||||
|
@ -37,9 +37,9 @@ pub(crate) fn main(args: &Args) -> Result<()> {
|
|||
output.push('\n');
|
||||
}
|
||||
|
||||
let autofix = rule.autofixable();
|
||||
if matches!(autofix, AutofixKind::Always | AutofixKind::Sometimes) {
|
||||
output.push_str(&autofix.to_string());
|
||||
let fix_kind = rule.fixable();
|
||||
if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) {
|
||||
output.push_str(&fix_kind.to_string());
|
||||
output.push('\n');
|
||||
output.push('\n');
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use itertools::Itertools;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
use ruff_diagnostics::AutofixKind;
|
||||
use ruff_diagnostics::FixKind;
|
||||
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
|
||||
use ruff_linter::upstream_categories::UpstreamCategoryAndPrefix;
|
||||
use ruff_workspace::options::Options;
|
||||
|
@ -20,11 +20,11 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
|
|||
table_out.push_str("| ---- | ---- | ------- | ------: |");
|
||||
table_out.push('\n');
|
||||
for rule in rules {
|
||||
let fix_token = match rule.autofixable() {
|
||||
AutofixKind::Always | AutofixKind::Sometimes => {
|
||||
let fix_token = match rule.fixable() {
|
||||
FixKind::Always | FixKind::Sometimes => {
|
||||
format!("<span style='opacity: 1'>{FIX_SYMBOL}</span>")
|
||||
}
|
||||
AutofixKind::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"),
|
||||
FixKind::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"),
|
||||
};
|
||||
let preview_token = if rule.is_preview() || rule.is_nursery() {
|
||||
format!("<span style='opacity: 1'>{PREVIEW_SYMBOL}</span>")
|
||||
|
|
|
@ -2,7 +2,7 @@ pub use diagnostic::{Diagnostic, DiagnosticKind};
|
|||
pub use edit::Edit;
|
||||
pub use fix::{Applicability, Fix, IsolationLevel};
|
||||
pub use source_map::{SourceMap, SourceMarker};
|
||||
pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation};
|
||||
pub use violation::{AlwaysFixableViolation, FixKind, Violation};
|
||||
|
||||
mod diagnostic;
|
||||
mod edit;
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
use std::fmt::{Debug, Display};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum AutofixKind {
|
||||
pub enum FixKind {
|
||||
Sometimes,
|
||||
Always,
|
||||
None,
|
||||
}
|
||||
|
||||
impl Display for AutofixKind {
|
||||
impl Display for FixKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
AutofixKind::Sometimes => write!(f, "Autofix is sometimes available."),
|
||||
AutofixKind::Always => write!(f, "Autofix is always available."),
|
||||
AutofixKind::None => write!(f, "Autofix is not available."),
|
||||
FixKind::Sometimes => write!(f, "Fix is sometimes available."),
|
||||
FixKind::Always => write!(f, "Fix is always available."),
|
||||
FixKind::None => write!(f, "Fix is not available."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Violation: Debug + PartialEq + Eq {
|
||||
/// `None` in the case an autofix is never available or otherwise Some
|
||||
/// [`AutofixKind`] describing the available autofix.
|
||||
const AUTOFIX: AutofixKind = AutofixKind::None;
|
||||
/// `None` in the case an fix is never available or otherwise Some
|
||||
/// [`FixKind`] describing the available fix.
|
||||
const FIX_KIND: FixKind = FixKind::None;
|
||||
|
||||
/// The message used to describe the violation.
|
||||
fn message(&self) -> String;
|
||||
|
@ -30,13 +30,13 @@ pub trait Violation: Debug + PartialEq + Eq {
|
|||
None
|
||||
}
|
||||
|
||||
// TODO(micha): Move `autofix_title` to `Fix`, add new `advice` method that is shown as an advice.
|
||||
// TODO(micha): Move `fix_title` to `Fix`, add new `advice` method that is shown as an advice.
|
||||
// Change the `Diagnostic` renderer to show the advice, and render the fix message after the `Suggested fix: <here>`
|
||||
|
||||
/// Returns the title for the autofix. The message is also shown as an advice as part of the diagnostics.
|
||||
/// Returns the title for the fix. The message is also shown as an advice as part of the diagnostics.
|
||||
///
|
||||
/// Required for rules that have autofixes.
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
/// Required for rules that have fixes.
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ pub trait Violation: Debug + PartialEq + Eq {
|
|||
}
|
||||
|
||||
/// This trait exists just to make implementing the [`Violation`] trait more
|
||||
/// convenient for violations that can always be autofixed.
|
||||
pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq {
|
||||
/// convenient for violations that can always be fixed.
|
||||
pub trait AlwaysFixableViolation: Debug + PartialEq + Eq {
|
||||
/// The message used to describe the violation.
|
||||
fn message(&self) -> String;
|
||||
|
||||
|
@ -55,31 +55,31 @@ pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq {
|
|||
None
|
||||
}
|
||||
|
||||
/// The title displayed for the available autofix.
|
||||
fn autofix_title(&self) -> String;
|
||||
/// The title displayed for the available fix.
|
||||
fn fix_title(&self) -> String;
|
||||
|
||||
/// Returns the format strings used by
|
||||
/// [`message`](AlwaysAutofixableViolation::message).
|
||||
/// [`message`](AlwaysFixableViolation::message).
|
||||
fn message_formats() -> &'static [&'static str];
|
||||
}
|
||||
|
||||
/// A blanket implementation.
|
||||
impl<VA: AlwaysAutofixableViolation> Violation for VA {
|
||||
const AUTOFIX: AutofixKind = AutofixKind::Always;
|
||||
impl<V: AlwaysFixableViolation> Violation for V {
|
||||
const FIX_KIND: FixKind = FixKind::Always;
|
||||
|
||||
fn message(&self) -> String {
|
||||
<Self as AlwaysAutofixableViolation>::message(self)
|
||||
<Self as AlwaysFixableViolation>::message(self)
|
||||
}
|
||||
|
||||
fn explanation() -> Option<&'static str> {
|
||||
<Self as AlwaysAutofixableViolation>::explanation()
|
||||
<Self as AlwaysFixableViolation>::explanation()
|
||||
}
|
||||
|
||||
fn autofix_title(&self) -> Option<String> {
|
||||
Some(<Self as AlwaysAutofixableViolation>::autofix_title(self))
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
Some(<Self as AlwaysFixableViolation>::fix_title(self))
|
||||
}
|
||||
|
||||
fn message_formats() -> &'static [&'static str] {
|
||||
<Self as AlwaysAutofixableViolation>::message_formats()
|
||||
<Self as AlwaysFixableViolation>::message_formats()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -627,7 +627,7 @@ result = function(
|
|||
**{'ham': spam}
|
||||
)
|
||||
|
||||
# Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error.
|
||||
# Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error.
|
||||
the_first_one = next(
|
||||
(i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket
|
||||
)
|
||||
|
|
|
@ -33,10 +33,10 @@ message
|
|||
assert not (a or not (b or c))
|
||||
assert not (a or not (b and c))
|
||||
|
||||
# detected, but no autofix for messages
|
||||
# detected, but no fix for messages
|
||||
assert something and something_else, "error message"
|
||||
assert not (something or something_else and something_third), "with message"
|
||||
# detected, but no autofix for mixed conditions (e.g. `a or b and c`)
|
||||
# detected, but no fix for mixed conditions (e.g. `a or b and c`)
|
||||
assert not (something or something_else and something_third)
|
||||
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@ def foo():
|
|||
return x
|
||||
|
||||
|
||||
# Autofix cases
|
||||
# Fix cases
|
||||
def foo():
|
||||
a = 1
|
||||
b=a
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
"""Test case for autofixing F841 violations."""
|
||||
"""Test case for fixing F841 violations."""
|
||||
|
||||
|
||||
def f():
|
||||
|
|
|
@ -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}`")
|
||||
|
|
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