mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Optionally show fixes when using --features ecosystem_ci
with cargo and --show-fixes
at runtime (#4191)
* Generate fixes when using --show-fixes Example command: `cargo run --bin ruff -- --no-cache --select F401 --show-source --show-fixes crates/ruff/resources/test/fixtures/pyflakes/F401_9.py` Before, `--show-fixes` was ignored: ``` crates/ruff/resources/test/fixtures/pyflakes/F401_9.py:4:22: F401 [*] `foo.baz` imported but unused | 4 | __all__ = ("bar",) 5 | from foo import bar, baz | ^^^ F401 | = help: Remove unused import: `foo.baz` Found 1 error. [*] 1 potentially fixable with the --fix option. ``` After: ``` crates/ruff/resources/test/fixtures/pyflakes/F401_9.py:4:22: F401 [*] `foo.baz` imported but unused | 4 | __all__ = ("bar",) 5 | from foo import bar, baz | ^^^ F401 | = help: Remove unused import: `foo.baz` ℹ Suggested fix 1 1 | """Test: late-binding of `__all__`.""" 2 2 | 3 3 | __all__ = ("bar",) 4 |-from foo import bar, baz 4 |+from foo import bar Found 1 error. [*] 1 potentially fixable with the --fix option. ``` * Add `--format ecosystem-ci` * cargo dev generate-all * Put behind cargo feature * Regenerate docs * Don't test ecosystem_ci feature on CI * Use top level flag instead * Fix * Simplify code based on #4191 * Remove old TODO comment
This commit is contained in:
parent
853d8354cb
commit
0096938789
8 changed files with 36 additions and 6 deletions
|
@ -70,6 +70,9 @@ pub(crate) struct Printer {
|
|||
log_level: LogLevel,
|
||||
autofix_level: flags::FixMode,
|
||||
flags: Flags,
|
||||
/// Dev-only argument to show fixes
|
||||
#[cfg(feature = "ecosystem_ci")]
|
||||
ecosystem_ci: bool,
|
||||
}
|
||||
|
||||
impl Printer {
|
||||
|
@ -78,12 +81,15 @@ impl Printer {
|
|||
log_level: LogLevel,
|
||||
autofix_level: flags::FixMode,
|
||||
flags: Flags,
|
||||
#[cfg(feature = "ecosystem_ci")] ecosystem_ci: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
format,
|
||||
log_level,
|
||||
autofix_level,
|
||||
flags,
|
||||
#[cfg(feature = "ecosystem_ci")]
|
||||
ecosystem_ci,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,8 +185,14 @@ impl Printer {
|
|||
JunitEmitter::default().emit(writer, &diagnostics.messages, &context)?;
|
||||
}
|
||||
SerializationFormat::Text => {
|
||||
#[cfg(feature = "ecosystem_ci")]
|
||||
let show_fixes = self.ecosystem_ci && self.flags.contains(Flags::SHOW_FIXES);
|
||||
#[cfg(not(feature = "ecosystem_ci"))]
|
||||
let show_fixes = false;
|
||||
|
||||
TextEmitter::default()
|
||||
.with_show_fix_status(show_fix_status(self.autofix_level))
|
||||
.with_show_fix(show_fixes)
|
||||
.with_show_source(self.flags.contains(Flags::SHOW_SOURCE))
|
||||
.emit(writer, &diagnostics.messages, &context)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue