Skip to content

Commit

Permalink
Remove output format text and use format full by default (#12010)
Browse files Browse the repository at this point in the history
Resolves #7349
  • Loading branch information
MichaReiser authored Jun 26, 2024
1 parent b6fb45e commit 0501afd
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 72 deletions.
28 changes: 10 additions & 18 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;

use anyhow::bail;
use anyhow::{anyhow, bail};
use clap::builder::{TypedValueParser, ValueParserFactory};
use clap::{command, Parser};
use colored::Colorize;
Expand All @@ -21,7 +21,7 @@ use ruff_linter::settings::types::{
ExtensionPair, FilePattern, OutputFormat, PatternPrefixPair, PerFileIgnore, PreviewMode,
PythonVersion, UnsafeFixes,
};
use ruff_linter::{warn_user, RuleParser, RuleSelector, RuleSelectorParser};
use ruff_linter::{RuleParser, RuleSelector, RuleSelectorParser};
use ruff_source_file::{LineIndex, OneIndexed};
use ruff_text_size::TextRange;
use ruff_workspace::configuration::{Configuration, RuleSelection};
Expand Down Expand Up @@ -691,10 +691,7 @@ impl CheckCommand {
unsafe_fixes: resolve_bool_arg(self.unsafe_fixes, self.no_unsafe_fixes)
.map(UnsafeFixes::from),
force_exclude: resolve_bool_arg(self.force_exclude, self.no_force_exclude),
output_format: resolve_output_format(
self.output_format,
resolve_bool_arg(self.preview, self.no_preview).unwrap_or_default(),
),
output_format: resolve_output_format(self.output_format)?,
show_fixes: resolve_bool_arg(self.show_fixes, self.no_show_fixes),
extension: self.extension,
};
Expand Down Expand Up @@ -922,20 +919,15 @@ The path `{value}` does not point to a configuration file"
}
}

#[allow(deprecated)]
fn resolve_output_format(
output_format: Option<OutputFormat>,
preview: bool,
) -> Option<OutputFormat> {
Some(match output_format {
Some(o) => o,
None => return None
}).map(|format| match format {
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
})
) -> anyhow::Result<Option<OutputFormat>> {
if let Some(OutputFormat::Text) = output_format {
Err(anyhow!("`--output-format=text` is no longer supported. Use `--output-format=full` or `--output-format=concise` instead."))
} else {
Ok(output_format)
}
}

/// CLI settings that are distinct from configuration (commands, lists of files,
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,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 != OutputFormat::default(preview) {
if output_format != OutputFormat::default() {
warn_user!(
"`--output-format {}` is always used in watch mode.",
OutputFormat::default(preview)
OutputFormat::default()
);
}

Expand Down
6 changes: 4 additions & 2 deletions crates/ruff/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ impl Printer {
}

if !self.flags.intersects(Flags::SHOW_VIOLATIONS) {
#[allow(deprecated)]
if matches!(
self.format,
OutputFormat::Text
Expand Down Expand Up @@ -275,8 +276,7 @@ impl Printer {
OutputFormat::Junit => {
JunitEmitter.emit(writer, &diagnostics.messages, &context)?;
}
OutputFormat::Concise
| OutputFormat::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))
Expand Down Expand Up @@ -324,6 +324,7 @@ impl Printer {
OutputFormat::Sarif => {
SarifEmitter.emit(writer, &diagnostics.messages, &context)?;
}
#[allow(deprecated)]
OutputFormat::Text => unreachable!("Text is deprecated and should have been automatically converted to the default serialization format")
}

Expand Down Expand Up @@ -367,6 +368,7 @@ impl Printer {
}

match self.format {
#[allow(deprecated)]
OutputFormat::Text | OutputFormat::Full | OutputFormat::Concise => {
// Compute the maximum number of digits in the count and code, for all messages,
// to enable pretty-printing.
Expand Down
14 changes: 7 additions & 7 deletions crates/ruff/tests/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const BIN_NAME: &str = "ruff";

const STDIN: &str = "l = 1";

fn ruff_check(output_format: Option<String>) -> Command {
fn ruff_check(output_format: OutputFormat) -> Command {
let mut cmd = Command::new(get_cargo_bin(BIN_NAME));
let output_format = output_format.unwrap_or(format!("{}", OutputFormat::default(false)));
let output_format = output_format.to_string();
cmd.arg("check")
.arg("--output-format")
.arg(output_format)
Expand All @@ -22,15 +22,15 @@ fn ruff_check(output_format: Option<String>) -> Command {
}

#[test]
#[allow(deprecated)]
fn ensure_output_format_is_deprecated() {
assert_cmd_snapshot!(ruff_check(Some("text".into())).pass_stdin(STDIN), @r###"
assert_cmd_snapshot!(ruff_check(OutputFormat::Text).pass_stdin(STDIN), @r###"
success: false
exit_code: 1
exit_code: 2
----- stdout -----
-:1:1: E741 Ambiguous variable name: `l`
Found 1 error.
----- stderr -----
warning: `--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `concise`.
ruff failed
Cause: `--output-format=text` is no longer supported. Use `--output-format=full` or `--output-format=concise` instead.
"###);
}
Loading

0 comments on commit 0501afd

Please sign in to comment.