Skip to content

Commit

Permalink
Rename SerializationFormat to OutputFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jun 24, 2024
1 parent e74f679 commit 2f5817e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 74 deletions.
18 changes: 9 additions & 9 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<SerializationFormat>,
pub output_format: Option<OutputFormat>,

/// Specify file to write the linter output to (default: stdout).
#[arg(short, long, env = "RUFF_OUTPUT_FILE")]
Expand Down Expand Up @@ -925,16 +925,16 @@ The path `{value}` does not point to a configuration file"
}

fn resolve_output_format(
output_format: Option<SerializationFormat>,
output_format: Option<OutputFormat>,
preview: bool,
) -> Option<SerializationFormat> {
) -> Option<OutputFormat> {
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
})
Expand Down Expand Up @@ -1189,7 +1189,7 @@ struct ExplicitConfigOverrides {
fix_only: Option<bool>,
unsafe_fixes: Option<UnsafeFixes>,
force_exclude: Option<bool>,
output_format: Option<SerializationFormat>,
output_format: Option<OutputFormat>,
show_fixes: Option<bool>,
extension: Option<Vec<ExtensionPair>>,
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -351,10 +351,10 @@ pub fn check(args: CheckCommand, global_options: GlobalConfigArgs) -> Result<Exi
let preview = pyproject_config.settings.linter.preview.is_enabled();

if cli.watch {
if output_format != SerializationFormat::default(preview) {
if output_format != OutputFormat::default(preview) {
warn_user!(
"`--output-format {}` is always used in watch mode.",
SerializationFormat::default(preview)
OutputFormat::default(preview)
);
}

Expand Down
48 changes: 23 additions & 25 deletions crates/ruff/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ruff_linter::message::{
use ruff_linter::notify_user;
use ruff_linter::registry::{AsRule, Rule};
use ruff_linter::settings::flags::{self};
use ruff_linter::settings::types::{SerializationFormat, UnsafeFixes};
use ruff_linter::settings::types::{OutputFormat, UnsafeFixes};

use crate::diagnostics::{Diagnostics, FixMap};

Expand Down Expand Up @@ -67,7 +67,7 @@ impl From<Rule> for SerializeRuleAsCode {
}

pub(crate) struct Printer {
format: SerializationFormat,
format: OutputFormat,
log_level: LogLevel,
fix_mode: flags::FixMode,
unsafe_fixes: UnsafeFixes,
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand All @@ -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)?;

Expand All @@ -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)
Expand All @@ -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()?;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -393,7 +391,7 @@ impl Printer {
}
return Ok(());
}
SerializationFormat::Json => {
OutputFormat::Json => {
writeln!(writer, "{}", serde_json::to_string_pretty(&statistics)?)?;
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/tests/deprecation.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -11,7 +11,7 @@ const STDIN: &str = "l = 1";

fn ruff_check(output_format: Option<String>) -> 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)
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl FromIterator<ExtensionPair> 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,
Expand All @@ -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"),
Expand All @@ -540,7 +540,7 @@ impl Display for SerializationFormat {
}
}

impl SerializationFormat {
impl OutputFormat {
pub fn default(preview: bool) -> Self {
if preview {
Self::Full
Expand Down
15 changes: 7 additions & 8 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -116,7 +116,7 @@ pub struct Configuration {
pub fix: Option<bool>,
pub fix_only: Option<bool>,
pub unsafe_fixes: Option<UnsafeFixes>,
pub output_format: Option<SerializationFormat>,
pub output_format: Option<OutputFormat>,
pub preview: Option<PreviewMode>,
pub required_version: Option<RequiredVersion>,
pub extension: Option<ExtensionMapping>,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -86,7 +86,7 @@ pub struct Options {
output-format = "grouped"
"#
)]
pub output_format: Option<SerializationFormat>,
pub output_format: Option<OutputFormat>,

/// Enable fix behavior by-default when running `ruff` (overridden
/// by the `--fix` and `--no-fix` command-line flags).
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_workspace/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,

Expand All @@ -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),
Expand Down
38 changes: 19 additions & 19 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f5817e

Please sign in to comment.