Add --color cli option to force colored output#22806
Add --color cli option to force colored output#22806MichaReiser merged 2 commits intoastral-sh:mainfrom
--color cli option to force colored output#22806Conversation
|
crates/ruff/src/lib.rs
Outdated
| } | ||
| // Default to no override, but respect FORCE_COLOR. | ||
| Some(TerminalColor::Auto) | None => { | ||
| colored::control::unset_override(); |
There was a problem hiding this comment.
What's the reason that we need to call unset_override here?
There was a problem hiding this comment.
This is added whilst looking at ty's implementation.
Was thinking that it might be necessary to unset it here so that it'll reset any manual override before it.
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test_set_colored_override { |
There was a problem hiding this comment.
Unfortunately, we can't keep those unit tests as they'll mess up the colored output of other tests (they modify global state).
If you want to test this code, I suggest changing set_colored_override to colored_override(color_option: Option<TerminalColor>, force_color_env: Option<OsString>) -> Option<bool>
There was a problem hiding this comment.
Ah, I missed this. Thanks for pointing this out!
|
@MichaReiser Thanks for the review! |
* main: (62 commits) [`refurb`] Do not add `abc.ABC` if already present (`FURB180`) (#22234) [ty] Add a new `assert-type-unspellable-subtype` diagnostic (#22815) [ty] Avoid duplicate syntax errors for `await` outside functions (#22826) [ty] Fix unary operator false-positive for constrained TypeVars (#22783) [ty] Fix binary operator false-positive for constrained TypeVars (#22782) [ty] Fix false-positive `unsupported-operator` for "symmetric" TypeVars (#22756) [`pydocstyle`] Clarify which quote styles are allowed (`D300`) (#22825) [ty] Use distributed versions of AND and OR on constraint sets (#22614) [ty] Add support for dict literals and dict() calls as default values for parameters with TypedDict types (#22161) Document `-` stdin convention in CLI help text (#22817) [ty] Make `infer_subscript_expression_types` a method on `Type` (#22731) [ty] Simplify `OverloadLiteral::spans` and `OverloadLiteral::parameter_span` (#22823) [ty] Require both `*args` and `**kwargs` when calling a `ParamSpec` callable (#22820) [ty] Handle tagged errors in conformance (#22746) Add `--color` cli option to force colored output (#22806) Identify notebooks by LSP didOpen instead of `.ipynb` file extension (#22810) [ty] Fix docstring rendering for literal blocks after doctests (#22676) [ty] Update salsa to fix out-of-order query validation (#22498) [ty] Inline cycle initial and recovery functions (#22814) [ty] Pass the generic context through the decorator (#22544) ...
Summary
Closes #22716.
This PR adds a new
--colorcli global options toruffthat allows turning the colored output on or off, similar to that ofty.ruff --color always check `/path/to/file.py`.This should solve issues with the environment variables for forcing color mentioned in #22716.
New
--colorcli optionScreenshots
--color always
--color never
With the new changes, it should still support environment variables that enable/disable the color output, but
--colorcli option will take precedence over environment variables: that is, givenFORCE_COLORand--color never,ruffwill respect--color neverand output without color.--colortakes precedencesTest Plan
I've added 2 tests specifically to test for how the environment variables will interact with each other:
--colorvalue is passed via cli.--color