Skip to content

Commit

Permalink
Rename Autofix to Fix
Browse files Browse the repository at this point in the history
**Summary** Mostly mechanical rename symbol, with small changes to the markdown docs to read better
  • Loading branch information
konstin committed Sep 25, 2023
1 parent 8ce1387 commit e402183
Show file tree
Hide file tree
Showing 231 changed files with 930 additions and 946 deletions.
2 changes: 1 addition & 1 deletion .github/release.yml
Expand Up @@ -12,7 +12,7 @@ changelog:
- title: Rules
labels:
- rule
- autofix
- fix
- title: Settings
labels:
- configuration
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []

Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_cli/src/args.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = ',',
Expand All @@ -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 = ',',
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_cli/src/commands/check.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/commands/check_stdin.rs
Expand Up @@ -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)? {
Expand All @@ -33,7 +33,7 @@ pub(crate) fn check_stdin(
stdin,
&pyproject_config.settings,
noqa,
autofix,
fix_mode,
)?;
diagnostics.messages.sort_unstable();
Ok(diagnostics)
Expand Down
14 changes: 7 additions & 7 deletions crates/ruff_cli/src/commands/rule.rs
Expand Up @@ -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;
Expand All @@ -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,
}
Expand All @@ -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(),
}
Expand All @@ -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');
}
Expand Down
20 changes: 10 additions & 10 deletions crates/ruff_cli/src/diagnostics.rs
Expand Up @@ -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
Expand All @@ -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");
Expand Down Expand Up @@ -220,15 +220,15 @@ 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,
fixed,
}) = 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())?;
Expand Down Expand Up @@ -302,7 +302,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)
Expand Down Expand Up @@ -370,7 +370,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 {
Expand All @@ -393,7 +393,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,
Expand All @@ -406,7 +406,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())?;
Expand Down Expand Up @@ -435,7 +435,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,
Expand All @@ -447,7 +447,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())?;
}

Expand Down
18 changes: 9 additions & 9 deletions crates/ruff_cli/src/lib.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand All @@ -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 {
Expand All @@ -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)?;

Expand Down Expand Up @@ -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)?;
}
Expand All @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit e402183

Please sign in to comment.