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:
konstin 2023-05-10 17:45:57 +02:00 committed by GitHub
parent 853d8354cb
commit 0096938789
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 6 deletions

View file

@ -123,6 +123,8 @@ quoting the executed command, along with the relevant file contents and `pyproje
}
fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
#[cfg(feature = "ecosystem_ci")]
let ecosystem_ci = args.ecosystem_ci;
let (cli, overrides) = args.partition();
// Construct the "default" settings. These are used when no `pyproject.toml`
@ -209,7 +211,14 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
return Ok(ExitStatus::Success);
}
let printer = Printer::new(format, log_level, autofix, printer_flags);
let printer = Printer::new(
format,
log_level,
autofix,
printer_flags,
#[cfg(feature = "ecosystem_ci")]
ecosystem_ci,
);
if cli.watch {
if format != SerializationFormat::Text {