From 2f5817ef64a27c152a01edddf2b272c5c4d9496a Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 24 Jun 2024 10:43:44 +0200 Subject: [PATCH] Rename `SerializationFormat` to `OutputFormat` --- crates/ruff/src/args.rs | 18 ++++---- crates/ruff/src/lib.rs | 6 +-- crates/ruff/src/printer.rs | 48 +++++++++++----------- crates/ruff/tests/deprecation.rs | 4 +- crates/ruff_linter/src/settings/types.rs | 6 +-- crates/ruff_workspace/src/configuration.rs | 15 ++++--- crates/ruff_workspace/src/options.rs | 4 +- crates/ruff_workspace/src/settings.rs | 6 +-- ruff.schema.json | 38 ++++++++--------- 9 files changed, 71 insertions(+), 74 deletions(-) diff --git a/crates/ruff/src/args.rs b/crates/ruff/src/args.rs index cc2f9b43d168d..162ccd912462b 100644 --- a/crates/ruff/src/args.rs +++ b/crates/ruff/src/args.rs @@ -18,8 +18,8 @@ use ruff_linter::line_width::LineLength; use ruff_linter::logging::LogLevel; use ruff_linter::registry::Rule; use ruff_linter::settings::types::{ - ExtensionPair, FilePattern, PatternPrefixPair, PerFileIgnore, PreviewMode, PythonVersion, - SerializationFormat, UnsafeFixes, + ExtensionPair, FilePattern, OutputFormat, PatternPrefixPair, PerFileIgnore, PreviewMode, + PythonVersion, UnsafeFixes, }; use ruff_linter::{warn_user, RuleParser, RuleSelector, RuleSelectorParser}; use ruff_source_file::{LineIndex, OneIndexed}; @@ -187,7 +187,7 @@ pub struct CheckCommand { /// The default serialization format is "concise". /// In preview mode, the default serialization format is "full". #[arg(long, value_enum, env = "RUFF_OUTPUT_FORMAT")] - pub output_format: Option, + pub output_format: Option, /// Specify file to write the linter output to (default: stdout). #[arg(short, long, env = "RUFF_OUTPUT_FILE")] @@ -925,16 +925,16 @@ The path `{value}` does not point to a configuration file" } fn resolve_output_format( - output_format: Option, + output_format: Option, preview: bool, -) -> Option { +) -> Option { Some(match output_format { Some(o) => o, None => return None }).map(|format| match format { - SerializationFormat::Text => { - warn_user!("`--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `{}`.", SerializationFormat::default(preview)); - SerializationFormat::default(preview) + OutputFormat::Text => { + warn_user!("`--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `{}`.", OutputFormat::default(preview)); + OutputFormat::default(preview) }, other => other }) @@ -1189,7 +1189,7 @@ struct ExplicitConfigOverrides { fix_only: Option, unsafe_fixes: Option, force_exclude: Option, - output_format: Option, + output_format: Option, show_fixes: Option, extension: Option>, } diff --git a/crates/ruff/src/lib.rs b/crates/ruff/src/lib.rs index 7281a3be87266..2bada3e6df389 100644 --- a/crates/ruff/src/lib.rs +++ b/crates/ruff/src/lib.rs @@ -16,7 +16,7 @@ use notify::{recommended_watcher, RecursiveMode, Watcher}; use ruff_linter::logging::{set_up_logging, LogLevel}; use ruff_linter::settings::flags::FixMode; -use ruff_linter::settings::types::SerializationFormat; +use ruff_linter::settings::types::OutputFormat; use ruff_linter::{fs, warn_user, warn_user_once}; use ruff_workspace::Settings; @@ -351,10 +351,10 @@ pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result for SerializeRuleAsCode { } pub(crate) struct Printer { - format: SerializationFormat, + format: OutputFormat, log_level: LogLevel, fix_mode: flags::FixMode, unsafe_fixes: UnsafeFixes, @@ -76,7 +76,7 @@ pub(crate) struct Printer { impl Printer { pub(crate) const fn new( - format: SerializationFormat, + format: OutputFormat, log_level: LogLevel, fix_mode: flags::FixMode, unsafe_fixes: UnsafeFixes, @@ -219,10 +219,10 @@ impl Printer { if !self.flags.intersects(Flags::SHOW_VIOLATIONS) { if matches!( self.format, - SerializationFormat::Text - | SerializationFormat::Full - | SerializationFormat::Concise - | SerializationFormat::Grouped + OutputFormat::Text + | OutputFormat::Full + | OutputFormat::Concise + | OutputFormat::Grouped ) { if self.flags.intersects(Flags::SHOW_FIX_SUMMARY) { if !diagnostics.fixed.is_empty() { @@ -240,24 +240,24 @@ impl Printer { let fixables = FixableStatistics::try_from(diagnostics, self.unsafe_fixes); match self.format { - SerializationFormat::Json => { + OutputFormat::Json => { JsonEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Rdjson => { + OutputFormat::Rdjson => { RdjsonEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::JsonLines => { + OutputFormat::JsonLines => { JsonLinesEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Junit => { + OutputFormat::Junit => { JunitEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Concise - | SerializationFormat::Full => { + OutputFormat::Concise + | OutputFormat::Full => { TextEmitter::default() .with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref())) .with_show_fix_diff(self.flags.intersects(Flags::SHOW_FIX_DIFF)) - .with_show_source(self.format == SerializationFormat::Full) + .with_show_source(self.format == OutputFormat::Full) .with_unsafe_fixes(self.unsafe_fixes) .emit(writer, &diagnostics.messages, &context)?; @@ -271,7 +271,7 @@ impl Printer { self.write_summary_text(writer, diagnostics)?; } - SerializationFormat::Grouped => { + OutputFormat::Grouped => { GroupedEmitter::default() .with_show_fix_status(show_fix_status(self.fix_mode, fixables.as_ref())) .with_unsafe_fixes(self.unsafe_fixes) @@ -286,22 +286,22 @@ impl Printer { } self.write_summary_text(writer, diagnostics)?; } - SerializationFormat::Github => { + OutputFormat::Github => { GithubEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Gitlab => { + OutputFormat::Gitlab => { GitlabEmitter::default().emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Pylint => { + OutputFormat::Pylint => { PylintEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Azure => { + OutputFormat::Azure => { AzureEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Sarif => { + OutputFormat::Sarif => { SarifEmitter.emit(writer, &diagnostics.messages, &context)?; } - SerializationFormat::Text => unreachable!("Text is deprecated and should have been automatically converted to the default serialization format") + OutputFormat::Text => unreachable!("Text is deprecated and should have been automatically converted to the default serialization format") } writer.flush()?; @@ -350,9 +350,7 @@ impl Printer { } match self.format { - SerializationFormat::Text - | SerializationFormat::Full - | SerializationFormat::Concise => { + OutputFormat::Text | OutputFormat::Full | OutputFormat::Concise => { // Compute the maximum number of digits in the count and code, for all messages, // to enable pretty-printing. let count_width = num_digits( @@ -393,7 +391,7 @@ impl Printer { } return Ok(()); } - SerializationFormat::Json => { + OutputFormat::Json => { writeln!(writer, "{}", serde_json::to_string_pretty(&statistics)?)?; } _ => { diff --git a/crates/ruff/tests/deprecation.rs b/crates/ruff/tests/deprecation.rs index ea5aad2a75115..b78ee9f3b1741 100644 --- a/crates/ruff/tests/deprecation.rs +++ b/crates/ruff/tests/deprecation.rs @@ -1,6 +1,6 @@ //! A test suite that ensures deprecated command line options have appropriate warnings / behaviors -use ruff_linter::settings::types::SerializationFormat; +use ruff_linter::settings::types::OutputFormat; use std::process::Command; use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; @@ -11,7 +11,7 @@ const STDIN: &str = "l = 1"; fn ruff_check(output_format: Option) -> Command { let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); - let output_format = output_format.unwrap_or(format!("{}", SerializationFormat::default(false))); + let output_format = output_format.unwrap_or(format!("{}", OutputFormat::default(false))); cmd.arg("check") .arg("--output-format") .arg(output_format) diff --git a/crates/ruff_linter/src/settings/types.rs b/crates/ruff_linter/src/settings/types.rs index 25f7223b76aea..39ec68142680c 100644 --- a/crates/ruff_linter/src/settings/types.rs +++ b/crates/ruff_linter/src/settings/types.rs @@ -504,7 +504,7 @@ impl FromIterator for ExtensionMapping { #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[serde(rename_all = "kebab-case")] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub enum SerializationFormat { +pub enum OutputFormat { Text, Concise, Full, @@ -520,7 +520,7 @@ pub enum SerializationFormat { Sarif, } -impl Display for SerializationFormat { +impl Display for OutputFormat { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Self::Text => write!(f, "text"), @@ -540,7 +540,7 @@ impl Display for SerializationFormat { } } -impl SerializationFormat { +impl OutputFormat { pub fn default(preview: bool) -> Self { if preview { Self::Full diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index bde13db0eea81..a278f77307a5f 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -27,8 +27,8 @@ use ruff_linter::rules::pycodestyle; use ruff_linter::settings::fix_safety_table::FixSafetyTable; use ruff_linter::settings::rule_table::RuleTable; use ruff_linter::settings::types::{ - CompiledPerFileIgnoreList, ExtensionMapping, FilePattern, FilePatternSet, PerFileIgnore, - PreviewMode, PythonVersion, RequiredVersion, SerializationFormat, UnsafeFixes, + CompiledPerFileIgnoreList, ExtensionMapping, FilePattern, FilePatternSet, OutputFormat, + PerFileIgnore, PreviewMode, PythonVersion, RequiredVersion, UnsafeFixes, }; use ruff_linter::settings::{LinterSettings, DEFAULT_SELECTORS, DUMMY_VARIABLE_RGX, TASK_TAGS}; use ruff_linter::{ @@ -116,7 +116,7 @@ pub struct Configuration { pub fix: Option, pub fix_only: Option, pub unsafe_fixes: Option, - pub output_format: Option, + pub output_format: Option, pub preview: Option, pub required_version: Option, pub extension: Option, @@ -222,7 +222,7 @@ impl Configuration { unsafe_fixes: self.unsafe_fixes.unwrap_or_default(), output_format: self .output_format - .unwrap_or_else(|| SerializationFormat::default(global_preview.is_enabled())), + .unwrap_or_else(|| OutputFormat::default(global_preview.is_enabled())), show_fixes: self.show_fixes.unwrap_or(false), file_resolver: FileResolverSettings { @@ -429,14 +429,13 @@ impl Configuration { options.indent_width.or(options.tab_size) }; - #[allow(deprecated)] let output_format = { options .output_format .map(|format| match format { - SerializationFormat::Text => { - warn_user_once!(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()) + OutputFormat::Text => { + warn_user_once!(r#"Setting `output_format` to "text" is deprecated. Use "full" or "concise" instead. "text" will be treated as "{}"."#, OutputFormat::default(options.preview.unwrap_or_default())); + OutputFormat::default(options.preview.unwrap_or_default()) }, other => other }) diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 4f26746e32e19..9180371c7bcd2 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -24,7 +24,7 @@ use ruff_linter::rules::{ pycodestyle, pydocstyle, pyflakes, pylint, pyupgrade, }; use ruff_linter::settings::types::{ - IdentifierPattern, PythonVersion, RequiredVersion, SerializationFormat, + IdentifierPattern, OutputFormat, PythonVersion, RequiredVersion, }; use ruff_linter::{warn_user_once, RuleSelector}; use ruff_macros::{CombineOptions, OptionsMetadata}; @@ -86,7 +86,7 @@ pub struct Options { output-format = "grouped" "# )] - pub output_format: Option, + pub output_format: Option, /// Enable fix behavior by-default when running `ruff` (overridden /// by the `--fix` and `--no-fix` command-line flags). diff --git a/crates/ruff_workspace/src/settings.rs b/crates/ruff_workspace/src/settings.rs index a650f93d19742..7631c427f0632 100644 --- a/crates/ruff_workspace/src/settings.rs +++ b/crates/ruff_workspace/src/settings.rs @@ -3,7 +3,7 @@ use ruff_cache::cache_dir; use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth}; use ruff_linter::display_settings; use ruff_linter::settings::types::{ - ExtensionMapping, FilePattern, FilePatternSet, SerializationFormat, UnsafeFixes, + ExtensionMapping, FilePattern, FilePatternSet, OutputFormat, UnsafeFixes, }; use ruff_linter::settings::LinterSettings; use ruff_macros::CacheKey; @@ -28,7 +28,7 @@ pub struct Settings { #[cache_key(ignore)] pub unsafe_fixes: UnsafeFixes, #[cache_key(ignore)] - pub output_format: SerializationFormat, + pub output_format: OutputFormat, #[cache_key(ignore)] pub show_fixes: bool, @@ -44,7 +44,7 @@ impl Default for Settings { cache_dir: cache_dir(project_root), fix: false, fix_only: false, - output_format: SerializationFormat::default(false), + output_format: OutputFormat::default(false), show_fixes: false, unsafe_fixes: UnsafeFixes::default(), linter: LinterSettings::new(project_root), diff --git a/ruff.schema.json b/ruff.schema.json index 6a5eb454fbbbb..5d390e2408019 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -534,7 +534,7 @@ "description": "The style in which violation messages should be formatted: `\"full\"` (shows source),`\"concise\"` (default), `\"grouped\"` (group messages by file), `\"json\"` (machine-readable), `\"junit\"` (machine-readable XML), `\"github\"` (GitHub Actions annotations), `\"gitlab\"` (GitLab CI code quality report), `\"pylint\"` (Pylint text format) or `\"azure\"` (Azure Pipeline logging commands).", "anyOf": [ { - "$ref": "#/definitions/SerializationFormat" + "$ref": "#/definitions/OutputFormat" }, { "type": "null" @@ -2293,6 +2293,24 @@ }, "additionalProperties": false }, + "OutputFormat": { + "type": "string", + "enum": [ + "text", + "concise", + "full", + "json", + "json-lines", + "junit", + "grouped", + "github", + "gitlab", + "pylint", + "rdjson", + "azure", + "sarif" + ] + }, "ParametrizeNameType": { "type": "string", "enum": [ @@ -3931,24 +3949,6 @@ "YTT303" ] }, - "SerializationFormat": { - "type": "string", - "enum": [ - "text", - "concise", - "full", - "json", - "json-lines", - "junit", - "grouped", - "github", - "gitlab", - "pylint", - "rdjson", - "azure", - "sarif" - ] - }, "Strictness": { "oneOf": [ {