mirror of https://github.com/astral-sh/ruff
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
|
|
@ -4,6 +4,7 @@ crates/ruff/resources/test/cpython
|
||||||
mkdocs.yml
|
mkdocs.yml
|
||||||
.overrides
|
.overrides
|
||||||
github_search.jsonl
|
github_search.jsonl
|
||||||
|
ruff-old
|
||||||
|
|
||||||
###
|
###
|
||||||
# Rust.gitignore
|
# Rust.gitignore
|
||||||
|
|
|
||||||
|
|
@ -83,3 +83,4 @@ default = []
|
||||||
schemars = ["dep:schemars"]
|
schemars = ["dep:schemars"]
|
||||||
logical_lines = []
|
logical_lines = []
|
||||||
jupyter_notebook = []
|
jupyter_notebook = []
|
||||||
|
ecosystem_ci = []
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ ureq = { version = "2.6.2", features = [] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
jupyter_notebook = ["ruff/jupyter_notebook"]
|
jupyter_notebook = ["ruff/jupyter_notebook"]
|
||||||
|
ecosystem_ci = ["ruff/ecosystem_ci"]
|
||||||
|
|
||||||
[package.metadata.maturin]
|
[package.metadata.maturin]
|
||||||
name = "ruff"
|
name = "ruff"
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,10 @@ pub struct CheckArgs {
|
||||||
conflicts_with = "watch",
|
conflicts_with = "watch",
|
||||||
)]
|
)]
|
||||||
pub show_settings: bool,
|
pub show_settings: bool,
|
||||||
|
/// Dev-only argument to show fixes
|
||||||
|
#[cfg(feature = "ecosystem_ci")]
|
||||||
|
#[arg(long, hide = true)]
|
||||||
|
pub ecosystem_ci: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
|
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,8 @@ mod test {
|
||||||
LogLevel::Default,
|
LogLevel::Default,
|
||||||
FixMode::None,
|
FixMode::None,
|
||||||
Flags::SHOW_VIOLATIONS,
|
Flags::SHOW_VIOLATIONS,
|
||||||
|
#[cfg(feature = "ecosystem_ci")]
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let mut writer: Vec<u8> = Vec::new();
|
let mut writer: Vec<u8> = Vec::new();
|
||||||
// Mute the terminal color codes
|
// Mute the terminal color codes
|
||||||
|
|
|
||||||
|
|
@ -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> {
|
fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
|
||||||
|
#[cfg(feature = "ecosystem_ci")]
|
||||||
|
let ecosystem_ci = args.ecosystem_ci;
|
||||||
let (cli, overrides) = args.partition();
|
let (cli, overrides) = args.partition();
|
||||||
|
|
||||||
// Construct the "default" settings. These are used when no `pyproject.toml`
|
// 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);
|
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 cli.watch {
|
||||||
if format != SerializationFormat::Text {
|
if format != SerializationFormat::Text {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ pub(crate) struct Printer {
|
||||||
log_level: LogLevel,
|
log_level: LogLevel,
|
||||||
autofix_level: flags::FixMode,
|
autofix_level: flags::FixMode,
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
|
/// Dev-only argument to show fixes
|
||||||
|
#[cfg(feature = "ecosystem_ci")]
|
||||||
|
ecosystem_ci: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Printer {
|
impl Printer {
|
||||||
|
|
@ -78,12 +81,15 @@ impl Printer {
|
||||||
log_level: LogLevel,
|
log_level: LogLevel,
|
||||||
autofix_level: flags::FixMode,
|
autofix_level: flags::FixMode,
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
|
#[cfg(feature = "ecosystem_ci")] ecosystem_ci: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
format,
|
format,
|
||||||
log_level,
|
log_level,
|
||||||
autofix_level,
|
autofix_level,
|
||||||
flags,
|
flags,
|
||||||
|
#[cfg(feature = "ecosystem_ci")]
|
||||||
|
ecosystem_ci,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -179,8 +185,14 @@ impl Printer {
|
||||||
JunitEmitter::default().emit(writer, &diagnostics.messages, &context)?;
|
JunitEmitter::default().emit(writer, &diagnostics.messages, &context)?;
|
||||||
}
|
}
|
||||||
SerializationFormat::Text => {
|
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()
|
TextEmitter::default()
|
||||||
.with_show_fix_status(show_fix_status(self.autofix_level))
|
.with_show_fix_status(show_fix_status(self.autofix_level))
|
||||||
|
.with_show_fix(show_fixes)
|
||||||
.with_show_source(self.flags.contains(Flags::SHOW_SOURCE))
|
.with_show_source(self.flags.contains(Flags::SHOW_SOURCE))
|
||||||
.emit(writer, &diagnostics.messages, &context)?;
|
.emit(writer, &diagnostics.messages, &context)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,15 @@
|
||||||
# ```
|
# ```
|
||||||
# From the project root:
|
# From the project root:
|
||||||
# ```
|
# ```
|
||||||
# cargo build --target x86_64-unknown-linux-musl
|
# cargo build --target x86_64-unknown-linux-musl --features ecosystem_ci
|
||||||
# docker buildx build -f scripts/Dockerfile.ecosystem -t ruff-ecosystem-checker --load .
|
# docker buildx build -f scripts/Dockerfile.ecosystem -t ruff-ecosystem-checker --load .
|
||||||
# docker run --rm ruff-ecosystem-checker
|
# docker run --rm -v ./target/x86_64-unknown-linux-musl/debug/ruff:/app/ruff-new -v ./ruff-old:/app/ruff-old ruff-ecosystem-checker
|
||||||
# ```
|
# ```
|
||||||
|
|
||||||
FROM python:3.11
|
FROM python:3.11
|
||||||
RUN python -m venv .venv && .venv/bin/pip install ruff
|
RUN mkdir /app
|
||||||
|
WORKDIR /app
|
||||||
ADD scripts/check_ecosystem.py check_ecosystem.py
|
ADD scripts/check_ecosystem.py check_ecosystem.py
|
||||||
ADD github_search.jsonl github_search.jsonl
|
ADD github_search.jsonl github_search.jsonl
|
||||||
ADD target/x86_64-unknown-linux-musl/debug/ruff ruff-new
|
|
||||||
|
|
||||||
CMD ["python", "check_ecosystem.py", "--verbose", "--projects", "github_search.jsonl", "ruff-new", ".venv/bin/ruff"]
|
CMD ["python", "check_ecosystem.py", "--verbose", "--projects", "github_search.jsonl", "ruff-new", "ruff-old"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue