Skip to content

Commit 523f542

Browse files
authored
Remove support for providing output format via format option (#7984)
See the provided breaking changes note for details. Removes support for the deprecated `--format`option in the `ruff check` CLI, `format` inference as `output-format` in the configuration file, and the `RUFF_FORMAT` environment variable. The error message for use of `format` in the configuration file could be better, but would require some awkward serde wrappers and it seems hard to present the correct schema to the user still.
1 parent ee7575e commit 523f542

9 files changed

Lines changed: 50 additions & 144 deletions

File tree

BREAKING_CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## 0.1.0
44

5+
### The deprecated `format` setting has been removed
6+
7+
Ruff previously used the `format` setting, `--format` CLI option, and `RUFF_FORMAT` environment variable to
8+
configure the output format of the CLI. This usage was deprecated in `v0.0.291` — the `format` setting is now used
9+
to control Ruff's code formatting. As of this release:
10+
11+
- The `format` setting cannot be used to configure the output format, use `output-format` instead
12+
- The `RUFF_FORMAT` environment variable is ignored, use `RUFF_OUTPUT_FORMAT` instead
13+
- The `--format` option has been removed from `ruff check`, use `--output-format` instead
14+
515
### Unsafe fixes are not applied by default ([#7769](https://github.com/astral-sh/ruff/pull/7769))
616

717
Ruff labels fixes as "safe" and "unsafe". The meaning and intent of your code will be retained when applying safe

crates/ruff_cli/src/args.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ pub struct CheckCommand {
117117
#[arg(long)]
118118
ignore_noqa: bool,
119119

120-
/// Output serialization format for violations. (Deprecated: Use `--output-format` instead).
121-
#[arg(
122-
long,
123-
value_enum,
124-
env = "RUFF_FORMAT",
125-
conflicts_with = "output_format",
126-
hide = true
127-
)]
128-
pub format: Option<SerializationFormat>,
129-
130120
/// Output serialization format for violations.
131121
#[arg(long, value_enum, env = "RUFF_OUTPUT_FORMAT")]
132122
pub output_format: Option<SerializationFormat>,
@@ -507,7 +497,7 @@ impl CheckCommand {
507497
unsafe_fixes: resolve_bool_arg(self.unsafe_fixes, self.no_unsafe_fixes)
508498
.map(UnsafeFixes::from),
509499
force_exclude: resolve_bool_arg(self.force_exclude, self.no_force_exclude),
510-
output_format: self.output_format.or(self.format),
500+
output_format: self.output_format,
511501
show_fixes: resolve_bool_arg(self.show_fixes, self.no_show_fixes),
512502
},
513503
)

crates/ruff_cli/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ fn format(args: FormatCommand, log_level: LogLevel) -> Result<ExitStatus> {
177177
}
178178

179179
pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
180-
if args.format.is_some() {
181-
if std::env::var("RUFF_FORMAT").is_ok() {
182-
warn_user!("The environment variable `RUFF_FORMAT` is deprecated. Use `RUFF_OUTPUT_FORMAT` instead.");
183-
} else {
184-
warn_user!("The argument `--format=<FORMAT>` is deprecated. Use `--output-format=<FORMAT>` instead.");
185-
}
186-
}
187-
188180
let (cli, overrides) = args.partition();
189181

190182
// Construct the "default" settings. These are used when no `pyproject.toml`

crates/ruff_cli/tests/format.rs

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if condition:
144144
Ok(())
145145
}
146146

147-
/// Tests that the legacy `format` option continues to work but emits a warning.
147+
/// Since 0.1.0 the legacy format option is no longer supported
148148
#[test]
149149
fn legacy_format_option() -> Result<()> {
150150
let tempdir = TempDir::new()?;
@@ -156,53 +156,29 @@ format = "json"
156156
"#,
157157
)?;
158158

159-
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
160-
.args(["check", "--select", "F401", "--no-cache", "--config"])
161-
.arg(&ruff_toml)
162-
.arg("-")
163-
.pass_stdin(r#"
164-
import os
165-
"#), @r###"
166-
success: false
167-
exit_code: 1
168-
----- stdout -----
169-
[
170-
{
171-
"cell": null,
172-
"code": "F401",
173-
"end_location": {
174-
"column": 10,
175-
"row": 2
176-
},
177-
"filename": "-",
178-
"fix": {
179-
"applicability": "safe",
180-
"edits": [
181-
{
182-
"content": "",
183-
"end_location": {
184-
"column": 1,
185-
"row": 3
186-
},
187-
"location": {
188-
"column": 1,
189-
"row": 2
190-
}
191-
}
192-
],
193-
"message": "Remove unused import: `os`"
194-
},
195-
"location": {
196-
"column": 8,
197-
"row": 2
198-
},
199-
"message": "`os` imported but unused",
200-
"noqa_row": 2,
201-
"url": "https://docs.astral.sh/ruff/rules/unused-import"
202-
}
203-
]
204-
----- stderr -----
205-
warning: The option `format` has been deprecated to avoid ambiguity with Ruff's upcoming formatter. Use `output-format` instead.
206-
"###);
159+
insta::with_settings!({filters => vec![
160+
(&*regex::escape(ruff_toml.to_str().unwrap()), "[RUFF-TOML-PATH]"),
161+
]}, {
162+
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
163+
.args(["check", "--select", "F401", "--no-cache", "--config"])
164+
.arg(&ruff_toml)
165+
.arg("-")
166+
.pass_stdin(r#"
167+
import os
168+
"#), @r###"
169+
success: false
170+
exit_code: 2
171+
----- stdout -----
172+
173+
----- stderr -----
174+
ruff failed
175+
Cause: Failed to parse `[RUFF-TOML-PATH]`: TOML parse error at line 2, column 10
176+
|
177+
2 | format = "json"
178+
| ^^^^^^
179+
invalid type: string "json", expected struct FormatOptions
180+
181+
"###);
182+
});
207183
Ok(())
208184
}

crates/ruff_wasm/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ruff_python_trivia::CommentRanges;
2222
use ruff_source_file::{Locator, SourceLocation};
2323
use ruff_text_size::Ranged;
2424
use ruff_workspace::configuration::Configuration;
25-
use ruff_workspace::options::{FormatOptions, FormatOrOutputFormat, LintOptions, Options};
25+
use ruff_workspace::options::{FormatOptions, LintOptions, Options};
2626
use ruff_workspace::Settings;
2727

2828
#[wasm_bindgen(typescript_custom_section)]
@@ -140,11 +140,11 @@ impl Workspace {
140140

141141
..LintOptions::default()
142142
}),
143-
format: Some(FormatOrOutputFormat::Format(FormatOptions {
143+
format: Some(FormatOptions {
144144
indent_style: Some(IndentStyle::Space),
145145
quote_style: Some(QuoteStyle::Double),
146146
..FormatOptions::default()
147-
})),
147+
}),
148148
..Options::default()
149149
})
150150
.map_err(into_error)

crates/ruff_workspace/src/configuration.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use crate::options::{
3939
Flake8ComprehensionsOptions, Flake8CopyrightOptions, Flake8ErrMsgOptions, Flake8GetTextOptions,
4040
Flake8ImplicitStrConcatOptions, Flake8ImportConventionsOptions, Flake8PytestStyleOptions,
4141
Flake8QuotesOptions, Flake8SelfOptions, Flake8TidyImportsOptions, Flake8TypeCheckingOptions,
42-
Flake8UnusedArgumentsOptions, FormatOptions, FormatOrOutputFormat, IsortOptions, LintOptions,
43-
McCabeOptions, Options, Pep8NamingOptions, PyUpgradeOptions, PycodestyleOptions,
44-
PydocstyleOptions, PyflakesOptions, PylintOptions,
42+
Flake8UnusedArgumentsOptions, FormatOptions, IsortOptions, LintOptions, McCabeOptions, Options,
43+
Pep8NamingOptions, PyUpgradeOptions, PycodestyleOptions, PydocstyleOptions, PyflakesOptions,
44+
PylintOptions,
4545
};
4646
use crate::settings::{
4747
FileResolverSettings, FormatterSettings, LineEnding, Settings, EXCLUDE, INCLUDE,
@@ -435,12 +435,7 @@ impl Configuration {
435435
fix: options.fix,
436436
fix_only: options.fix_only,
437437
unsafe_fixes: options.unsafe_fixes.map(UnsafeFixes::from),
438-
output_format: options.output_format.or_else(|| {
439-
options
440-
.format
441-
.as_ref()
442-
.and_then(FormatOrOutputFormat::as_output_format)
443-
}),
438+
output_format: options.output_format,
444439
force_exclude: options.force_exclude,
445440
line_length: options.line_length,
446441
tab_size: options.tab_size,
@@ -460,11 +455,7 @@ impl Configuration {
460455
target_version: options.target_version,
461456

462457
lint: LintConfiguration::from_options(lint, project_root)?,
463-
format: if let Some(FormatOrOutputFormat::Format(format)) = options.format {
464-
FormatConfiguration::from_options(format)?
465-
} else {
466-
FormatConfiguration::default()
467-
},
458+
format: FormatConfiguration::from_options(options.format.unwrap_or_default())?,
468459
})
469460
}
470461

crates/ruff_workspace/src/options.rs

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use ruff_linter::{warn_user_once, RuleSelector};
2929
use ruff_macros::{CombineOptions, OptionsMetadata};
3030
use ruff_python_formatter::QuoteStyle;
3131

32-
use crate::options_base::{OptionsMetadata, Visit};
3332
use crate::settings::LineEnding;
3433

3534
#[derive(Debug, PartialEq, Eq, Default, OptionsMetadata, Serialize, Deserialize)]
@@ -380,19 +379,9 @@ pub struct Options {
380379
#[serde(flatten)]
381380
pub lint_top_level: LintOptions,
382381

383-
/// Options to configure the code formatting.
384-
///
385-
/// Previously:
386-
/// The style in which violation messages should be formatted: `"text"`
387-
/// (default), `"grouped"` (group messages by file), `"json"`
388-
/// (machine-readable), `"junit"` (machine-readable XML), `"github"` (GitHub
389-
/// Actions annotations), `"gitlab"` (GitLab CI code quality report),
390-
/// `"pylint"` (Pylint text format) or `"azure"` (Azure Pipeline logging commands).
391-
///
392-
/// This option has been **deprecated** in favor of `output-format`
393-
/// to avoid ambiguity with Ruff's upcoming formatter.
382+
/// Options to configure code formatting.
394383
#[option_group]
395-
pub format: Option<FormatOrOutputFormat>,
384+
pub format: Option<FormatOptions>,
396385
}
397386

398387
/// Experimental section to configure Ruff's linting. This new section will eventually
@@ -2465,38 +2454,11 @@ impl PyUpgradeOptions {
24652454
}
24662455
}
24672456

2468-
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
2469-
#[serde(untagged)]
2470-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
2471-
pub enum FormatOrOutputFormat {
2472-
Format(FormatOptions),
2473-
OutputFormat(SerializationFormat),
2474-
}
2475-
2476-
impl FormatOrOutputFormat {
2477-
pub const fn as_output_format(&self) -> Option<SerializationFormat> {
2478-
match self {
2479-
FormatOrOutputFormat::Format(_) => None,
2480-
FormatOrOutputFormat::OutputFormat(format) => Some(*format),
2481-
}
2482-
}
2483-
}
2484-
2485-
impl OptionsMetadata for FormatOrOutputFormat {
2486-
fn record(visit: &mut dyn Visit) {
2487-
FormatOptions::record(visit);
2488-
}
2489-
2490-
fn documentation() -> Option<&'static str> {
2491-
FormatOptions::documentation()
2492-
}
2493-
}
2494-
24952457
/// Experimental: Configures how `ruff format` formats your code.
24962458
///
24972459
/// Please provide feedback in [this discussion](https://github.com/astral-sh/ruff/discussions/7310).
24982460
#[derive(
2499-
Debug, PartialEq, Eq, Default, Serialize, Deserialize, OptionsMetadata, CombineOptions,
2461+
Debug, PartialEq, Eq, Default, Deserialize, Serialize, OptionsMetadata, CombineOptions,
25002462
)]
25012463
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
25022464
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]

crates/ruff_workspace/src/resolver.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use log::debug;
1313
use path_absolutize::path_dedot;
1414
use rustc_hash::{FxHashMap, FxHashSet};
1515

16+
use ruff_linter::fs;
1617
use ruff_linter::packaging::is_package;
17-
use ruff_linter::{fs, warn_user_once};
1818

1919
use crate::configuration::Configuration;
20-
use crate::options::FormatOrOutputFormat;
2120
use crate::pyproject;
2221
use crate::pyproject::settings_toml;
2322
use crate::settings::Settings;
@@ -221,10 +220,6 @@ fn resolve_configuration(
221220
let options = pyproject::load_options(&path)
222221
.map_err(|err| anyhow!("Failed to parse `{}`: {}", path.display(), err))?;
223222

224-
if matches!(options.format, Some(FormatOrOutputFormat::OutputFormat(_))) {
225-
warn_user_once!("The option `format` has been deprecated to avoid ambiguity with Ruff's upcoming formatter. Use `output-format` instead.");
226-
}
227-
228223
let project_root = relativity.resolve(&path);
229224
let configuration = Configuration::from_options(options, &project_root)?;
230225

ruff.schema.json

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)