diff --git a/CHANGELOG.md b/CHANGELOG.md
index 15b00303be4f..1eddfafbc10d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
### Configuration
+#### Enhancements
+
+- The `javascript.formatter.trailingComma` option is deprecated and renamed to `javascript.formatter.trailingCommas`. The corresponding CLI option `--trailing-comma` is also deprecated and renamed to `--trailing-commas`. Details can be checked in [#2492](https://github.com/biomejs/biome/pull/2492). Contributed by @Sec-ant
+
### Editors
#### New features
diff --git a/Cargo.lock b/Cargo.lock
index 425adb71419b..251c96dd9bd9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -832,6 +832,7 @@ dependencies = [
"biome_analyze",
"biome_console",
"biome_diagnostics",
+ "biome_json_analyze",
"biome_json_factory",
"biome_json_parser",
"biome_json_syntax",
diff --git a/crates/biome_cli/src/commands/format.rs b/crates/biome_cli/src/commands/format.rs
index 7efae9ddaf6d..61577c7b4125 100644
--- a/crates/biome_cli/src/commands/format.rs
+++ b/crates/biome_cli/src/commands/format.rs
@@ -82,7 +82,9 @@ pub(crate) fn format(
{PrintDiagnostic::simple(&diagnostic)}
});
- config.indent_width = Some(indent_size);
+ if config.indent_width.is_none() {
+ config.indent_width = Some(indent_size);
+ }
}
}
// TODO: remove in biome 2.0
@@ -95,7 +97,22 @@ pub(crate) fn format(
{PrintDiagnostic::simple(&diagnostic)}
});
- js_formatter.indent_width = Some(indent_size);
+ if js_formatter.indent_width.is_none() {
+ js_formatter.indent_width = Some(indent_size);
+ }
+ }
+
+ if let Some(trailing_comma) = js_formatter.trailing_comma {
+ let diagnostic = DeprecatedArgument::new(markup! {
+ "The argument ""--trailing-comma"" is deprecated, it will be removed in the next major release. Use ""--trailing-commas"" instead."
+ });
+ console.error(markup! {
+ {PrintDiagnostic::simple(&diagnostic)}
+ });
+
+ if js_formatter.trailing_commas.is_none() {
+ js_formatter.trailing_commas = Some(trailing_comma);
+ }
}
}
// TODO: remove in biome 2.0
@@ -108,7 +125,9 @@ pub(crate) fn format(
{PrintDiagnostic::simple(&diagnostic)}
});
- json_formatter.indent_width = Some(indent_size);
+ if json_formatter.indent_width.is_none() {
+ json_formatter.indent_width = Some(indent_size);
+ }
}
}
// TODO: remove in biome 2.0
@@ -121,7 +140,9 @@ pub(crate) fn format(
{PrintDiagnostic::simple(&diagnostic)}
});
- css_formatter.indent_width = Some(indent_size);
+ if css_formatter.indent_width.is_none() {
+ css_formatter.indent_width = Some(indent_size);
+ }
}
}
diff --git a/crates/biome_cli/src/commands/rage.rs b/crates/biome_cli/src/commands/rage.rs
index ff841bb8a4a3..7d3edd44e9c5 100644
--- a/crates/biome_cli/src/commands/rage.rs
+++ b/crates/biome_cli/src/commands/rage.rs
@@ -216,7 +216,6 @@ impl Display for RageConfiguration<'_, '_> {
{Section("Formatter")}
{KeyValuePair("Format with errors", markup!({DebugDisplay(configuration.get_formatter_configuration().format_with_errors)}))}
{KeyValuePair("Indent style", markup!({DebugDisplay(formatter_configuration.indent_style)}))}
- {KeyValuePair("Indent size", markup!({DebugDisplay(formatter_configuration.indent_size)}))}
{KeyValuePair("Indent width", markup!({DebugDisplay(formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplay(formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplay(formatter_configuration.line_width.get())}))}
@@ -232,14 +231,13 @@ impl Display for RageConfiguration<'_, '_> {
{KeyValuePair("Enabled", markup!({DebugDisplay(javascript_formatter_configuration.enabled)}))}
{KeyValuePair("JSX quote style", markup!({DebugDisplay(javascript_formatter_configuration.jsx_quote_style)}))}
{KeyValuePair("Quote properties", markup!({DebugDisplay(javascript_formatter_configuration.quote_properties)}))}
- {KeyValuePair("Trailing comma", markup!({DebugDisplay(javascript_formatter_configuration.trailing_comma)}))}
+ {KeyValuePair("Trailing commas", markup!({DebugDisplay(javascript_formatter_configuration.trailing_commas)}))}
{KeyValuePair("Semicolons", markup!({DebugDisplay(javascript_formatter_configuration.semicolons)}))}
{KeyValuePair("Arrow parentheses", markup!({DebugDisplay(javascript_formatter_configuration.arrow_parentheses)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplay(javascript_formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Bracket same line", markup!({DebugDisplay(javascript_formatter_configuration.bracket_same_line)}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(javascript_formatter_configuration.quote_style)}))}
{KeyValuePair("Indent style", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_style)}))}
- {KeyValuePair("Indent size", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_size)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_width)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(javascript_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(javascript_formatter_configuration.line_width.map(|lw| lw.get()))}))}
@@ -254,7 +252,6 @@ impl Display for RageConfiguration<'_, '_> {
{KeyValuePair("Enabled", markup!({DebugDisplay(json_formatter_configuration.enabled)}))}
{KeyValuePair("Indent style", markup!({DebugDisplayOption(json_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(json_formatter_configuration.indent_width)}))}
- {KeyValuePair("Indent size", markup!({DebugDisplayOption(json_formatter_configuration.indent_size)}))}
{KeyValuePair("Line ending", markup!({DebugDisplayOption(json_formatter_configuration.line_ending)}))}
{KeyValuePair("Line width", markup!({DebugDisplayOption(json_formatter_configuration.line_width.map(|lw| lw.get()))}))}
{KeyValuePair("Trailing Commas", markup!({DebugDisplayOption(json_formatter_configuration.trailing_commas)}))}
diff --git a/crates/biome_cli/src/execute/migrate/prettier.rs b/crates/biome_cli/src/execute/migrate/prettier.rs
index 14a99f261311..89a10d414ee8 100644
--- a/crates/biome_cli/src/execute/migrate/prettier.rs
+++ b/crates/biome_cli/src/execute/migrate/prettier.rs
@@ -8,7 +8,7 @@ use biome_formatter::{
AttributePosition, LineEnding, LineWidth, LineWidthFromIntError, QuoteStyle,
};
use biome_fs::{FileSystem, OpenOptions};
-use biome_js_formatter::context::{ArrowParentheses, QuoteProperties, Semicolons, TrailingComma};
+use biome_js_formatter::context::{ArrowParentheses, QuoteProperties, Semicolons, TrailingCommas};
use biome_json_parser::JsonParserOptions;
use biome_service::DynRef;
use std::path::Path;
@@ -36,7 +36,7 @@ pub(crate) struct PrettierConfiguration {
print_width: u16,
/// https://prettier.io/docs/en/options#use-tabs
use_tabs: bool,
- /// https://prettier.io/docs/en/options#trailing-comma
+ /// https://prettier.io/docs/en/options#trailing-commas
trailing_comma: PrettierTrailingComma,
/// https://prettier.io/docs/en/options#tab-width
tab_width: u8,
@@ -93,7 +93,7 @@ pub(crate) struct OverrideOptions {
print_width: Option,
/// https://prettier.io/docs/en/options#use-tabs
use_tabs: Option,
- /// https://prettier.io/docs/en/options#trailing-comma
+ /// https://prettier.io/docs/en/options#trailing-commas
trailing_comma: Option,
/// https://prettier.io/docs/en/options#tab-width
tab_width: Option,
@@ -147,7 +147,7 @@ enum QuoteProps {
Preserve,
}
-impl From for TrailingComma {
+impl From for TrailingCommas {
fn from(value: PrettierTrailingComma) -> Self {
match value {
PrettierTrailingComma::All => Self::All,
@@ -240,7 +240,9 @@ impl TryFrom for biome_configuration::PartialConfiguratio
bracket_same_line: Some(value.bracket_line),
arrow_parentheses: Some(value.arrow_parens.into()),
semicolons: Some(semicolons),
- trailing_comma: Some(value.trailing_comma.into()),
+ trailing_commas: Some(value.trailing_comma.into()),
+ // deprecated
+ trailing_comma: None,
quote_style: Some(quote_style),
quote_properties: Some(value.quote_props.into()),
bracket_spacing: Some(value.bracket_spacing),
@@ -335,7 +337,7 @@ impl TryFrom for biome_configuration::OverridePattern {
bracket_same_line: options.bracket_line,
arrow_parentheses: options.arrow_parens.map(|arrow_parens| arrow_parens.into()),
semicolons,
- trailing_comma: options
+ trailing_commas: options
.trailing_comma
.map(|trailing_comma| trailing_comma.into()),
quote_style,
diff --git a/crates/biome_cli/tests/commands/format.rs b/crates/biome_cli/tests/commands/format.rs
index 1decf72ded5e..f0f6b0f0aa7d 100644
--- a/crates/biome_cli/tests/commands/format.rs
+++ b/crates/biome_cli/tests/commands/format.rs
@@ -79,7 +79,7 @@ const hello: string = "world";
"#;
-const APPLY_TRAILING_COMMA_BEFORE: &str = r#"
+const APPLY_TRAILING_COMMAS_BEFORE: &str = r#"
const a = [
longlonglonglongItem1longlonglonglongItem1,
longlonglonglongItem1longlonglonglongItem2,
@@ -87,7 +87,7 @@ const a = [
];
"#;
-const APPLY_TRAILING_COMMA_AFTER: &str = r#"const a = [
+const APPLY_TRAILING_COMMAS_AFTER: &str = r#"const a = [
longlonglonglongItem1longlonglonglongItem1,
longlonglonglongItem1longlonglonglongItem2,
longlonglonglongItem1longlonglonglongItem3
@@ -743,12 +743,48 @@ fn applies_custom_css_quote_style() {
}
#[test]
-fn applies_custom_trailing_comma() {
+fn applies_custom_trailing_commas() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
let file_path = Path::new("file.js");
- fs.insert(file_path.into(), APPLY_TRAILING_COMMA_BEFORE.as_bytes());
+ fs.insert(file_path.into(), APPLY_TRAILING_COMMAS_BEFORE.as_bytes());
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ &mut console,
+ Args::from(
+ [
+ ("format"),
+ ("--trailing-commas"),
+ ("none"),
+ ("--write"),
+ file_path.as_os_str().to_str().unwrap(),
+ ]
+ .as_slice(),
+ ),
+ );
+
+ assert!(result.is_ok(), "run_cli returned {result:?}");
+
+ assert_file_contents(&fs, file_path, APPLY_TRAILING_COMMAS_AFTER);
+
+ assert_cli_snapshot(SnapshotPayload::new(
+ module_path!(),
+ "applies_custom_trailing_commas",
+ fs,
+ console,
+ result,
+ ));
+}
+
+#[test]
+fn applies_custom_trailing_commas_using_the_deprecated_option() {
+ let mut fs = MemoryFileSystem::default();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("file.js");
+ fs.insert(file_path.into(), APPLY_TRAILING_COMMAS_BEFORE.as_bytes());
let result = run_cli(
DynRef::Borrowed(&mut fs),
@@ -767,11 +803,49 @@ fn applies_custom_trailing_comma() {
assert!(result.is_ok(), "run_cli returned {result:?}");
- assert_file_contents(&fs, file_path, APPLY_TRAILING_COMMA_AFTER);
+ assert_file_contents(&fs, file_path, APPLY_TRAILING_COMMAS_AFTER);
+
+ assert_cli_snapshot(SnapshotPayload::new(
+ module_path!(),
+ "applies_custom_trailing_commas_using_the_deprecated_option",
+ fs,
+ console,
+ result,
+ ));
+}
+
+#[test]
+fn applies_custom_trailing_commas_overriding_the_deprecated_option() {
+ let mut fs = MemoryFileSystem::default();
+ let mut console = BufferConsole::default();
+
+ let file_path = Path::new("file.js");
+ fs.insert(file_path.into(), APPLY_TRAILING_COMMAS_BEFORE.as_bytes());
+
+ let result = run_cli(
+ DynRef::Borrowed(&mut fs),
+ &mut console,
+ Args::from(
+ [
+ ("format"),
+ ("--trailing-commas"),
+ ("none"),
+ ("--trailing-comma"),
+ ("all"),
+ ("--write"),
+ file_path.as_os_str().to_str().unwrap(),
+ ]
+ .as_slice(),
+ ),
+ );
+
+ assert!(result.is_ok(), "run_cli returned {result:?}");
+
+ assert_file_contents(&fs, file_path, APPLY_TRAILING_COMMAS_AFTER);
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
- "applies_custom_trailing_comma",
+ "applies_custom_trailing_commas_overriding_the_deprecated_option",
fs,
console,
result,
@@ -923,21 +997,21 @@ fn applies_custom_bracket_same_line() {
}
#[test]
-fn trailing_comma_parse_errors() {
+fn trailing_commas_parse_errors() {
let mut console = BufferConsole::default();
let mut fs = MemoryFileSystem::default();
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
- Args::from([("format"), ("--trailing-comma"), ("NONE"), ("file.js")].as_slice()),
+ Args::from([("format"), ("--trailing-commas"), ("NONE"), ("file.js")].as_slice()),
);
assert!(result.is_err(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
- "trailing_comma_parse_errors",
+ "trailing_commas_parse_errors",
fs,
console,
result,
diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap
index 89c5be7d04f9..b3fab644ca85 100644
--- a/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap
+++ b/crates/biome_cli/tests/snapshots/main_commands_check/check_help.snap
@@ -35,6 +35,8 @@ The configuration that is contained inside the file `biome.json`
--quote-properties= When properties in objects are quoted. Defaults to asNeeded.
--trailing-comma= Print trailing commas wherever possible in multi-line comma-separated
syntactic structures. Defaults to "all".
+ --trailing-commas= Print trailing commas wherever possible in multi-line comma-separated
+ syntactic structures. Defaults to "all".
--semicolons= Whether the formatter prints semicolons for all statements or
only in for statements where it is necessary because of ASI.
--arrow-parentheses= Whether to add non-necessary parentheses to arrow functions.
diff --git a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap
index 8bb1b4e40933..d430c10412dc 100644
--- a/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap
+++ b/crates/biome_cli/tests/snapshots/main_commands_ci/ci_help.snap
@@ -37,6 +37,8 @@ The configuration that is contained inside the file `biome.json`
--quote-properties= When properties in objects are quoted. Defaults to asNeeded.
--trailing-comma= Print trailing commas wherever possible in multi-line comma-separated
syntactic structures. Defaults to "all".
+ --trailing-commas= Print trailing commas wherever possible in multi-line comma-separated
+ syntactic structures. Defaults to "all".
--semicolons= Whether the formatter prints semicolons for all statements or
only in for statements where it is necessary because of ASI.
--arrow-parentheses= Whether to add non-necessary parentheses to arrow functions.
diff --git a/crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_comma.snap b/crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_commas.snap
similarity index 100%
rename from crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_comma.snap
rename to crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_commas.snap
diff --git a/crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_commas_overriding_the_deprecated_option.snap b/crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_commas_overriding_the_deprecated_option.snap
new file mode 100644
index 000000000000..473ed6571268
--- /dev/null
+++ b/crates/biome_cli/tests/snapshots/main_commands_format/applies_custom_trailing_commas_overriding_the_deprecated_option.snap
@@ -0,0 +1,28 @@
+---
+source: crates/biome_cli/tests/snap_test.rs
+expression: content
+---
+## `file.js`
+
+```js
+const a = [
+ longlonglonglongItem1longlonglonglongItem1,
+ longlonglonglongItem1longlonglonglongItem2,
+ longlonglonglongItem1longlonglonglongItem3
+];
+
+```
+
+# Emitted Messages
+
+```block
+internalError/fs DEPRECATED ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+ ! The argument --trailing-comma is deprecated, it will be removed in the next major release. Use --trailing-commas instead.
+
+
+```
+
+```block
+Formatted 1 file in