mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Replace --show-source
and --no-show-source
with --output_format=<full|concise>
(#9687)
Fixes #7350 ## Summary * `--show-source` and `--no-show-source` are now deprecated. * `output-format` supports two new variants, `full` and `concise`. `text` is now a deprecated variant, and any use of it is treated as the default serialization format. * `--output-format` now default to `concise` * In preview mode, `--output-format` defaults to `full` * `--show-source` will still set `--output-format` to `full` if the output format is not otherwise specified. * likewise, `--no-show-source` can override an output format that was set in a file-based configuration, though it will also be overridden by `--output-format` ## Test Plan A lot of tests were updated to use `--output-format=full`. Additional tests were added to ensure the correct deprecation warnings appeared, and that deprecated options behaved as intended. # Conflicts: # crates/ruff/tests/integration_test.rs
This commit is contained in:
parent
ae13d8fddf
commit
6aa643346f
13 changed files with 352 additions and 81 deletions
|
@ -118,7 +118,6 @@ pub struct Configuration {
|
|||
pub required_version: Option<Version>,
|
||||
pub extension: Option<ExtensionMapping>,
|
||||
pub show_fixes: Option<bool>,
|
||||
pub show_source: Option<bool>,
|
||||
|
||||
// File resolver options
|
||||
pub exclude: Option<Vec<FilePattern>>,
|
||||
|
@ -221,9 +220,10 @@ impl Configuration {
|
|||
fix: self.fix.unwrap_or(false),
|
||||
fix_only: self.fix_only.unwrap_or(false),
|
||||
unsafe_fixes: self.unsafe_fixes.unwrap_or_default(),
|
||||
output_format: self.output_format.unwrap_or_default(),
|
||||
output_format: self
|
||||
.output_format
|
||||
.unwrap_or_else(|| SerializationFormat::default(global_preview.is_enabled())),
|
||||
show_fixes: self.show_fixes.unwrap_or(false),
|
||||
show_source: self.show_source.unwrap_or(false),
|
||||
|
||||
file_resolver: FileResolverSettings {
|
||||
exclude: FilePatternSet::try_from_iter(
|
||||
|
@ -417,6 +417,32 @@ impl Configuration {
|
|||
options.indent_width.or(options.tab_size)
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
let output_format = {
|
||||
if options.show_source.is_some() {
|
||||
warn_user_once!(
|
||||
r#"The `show-source` option has been deprecated in favor of `output-format`'s "full" and "concise" variants. Please update your configuration to use `output-format = <full|concise>` instead."#
|
||||
);
|
||||
}
|
||||
|
||||
options
|
||||
.output_format
|
||||
.map(|format| match format {
|
||||
SerializationFormat::Text => {
|
||||
warn_user!(r#"Setting `output_format` to "text" is deprecated. Use "full" or "concise" instead. "text" will be treated as "{}"."#, SerializationFormat::default(options.preview.unwrap_or_default()));
|
||||
SerializationFormat::default(options.preview.unwrap_or_default())
|
||||
},
|
||||
other => other
|
||||
})
|
||||
.or(options.show_source.map(|show_source| {
|
||||
if show_source {
|
||||
SerializationFormat::Full
|
||||
} else {
|
||||
SerializationFormat::Concise
|
||||
}
|
||||
}))
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
builtins: options.builtins,
|
||||
cache_dir: options
|
||||
|
@ -481,7 +507,7 @@ impl Configuration {
|
|||
fix: options.fix,
|
||||
fix_only: options.fix_only,
|
||||
unsafe_fixes: options.unsafe_fixes.map(UnsafeFixes::from),
|
||||
output_format: options.output_format,
|
||||
output_format,
|
||||
force_exclude: options.force_exclude,
|
||||
line_length: options.line_length,
|
||||
indent_width,
|
||||
|
@ -492,7 +518,6 @@ impl Configuration {
|
|||
preview: options.preview.map(PreviewMode::from),
|
||||
required_version: options.required_version,
|
||||
respect_gitignore: options.respect_gitignore,
|
||||
show_source: options.show_source,
|
||||
show_fixes: options.show_fixes,
|
||||
src: options
|
||||
.src
|
||||
|
@ -539,7 +564,6 @@ impl Configuration {
|
|||
namespace_packages: self.namespace_packages.or(config.namespace_packages),
|
||||
required_version: self.required_version.or(config.required_version),
|
||||
respect_gitignore: self.respect_gitignore.or(config.respect_gitignore),
|
||||
show_source: self.show_source.or(config.show_source),
|
||||
show_fixes: self.show_fixes.or(config.show_fixes),
|
||||
src: self.src.or(config.src),
|
||||
target_version: self.target_version.or(config.target_version),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue