Skip to content

Commit

Permalink
fix: deprecate javascript.trailingComma in favor of `javascript.tra…
Browse files Browse the repository at this point in the history
…ilingCommas`
  • Loading branch information
Sec-ant committed Apr 17, 2024
1 parent 2608c16 commit 102737d
Show file tree
Hide file tree
Showing 310 changed files with 482 additions and 986 deletions.
2 changes: 1 addition & 1 deletion crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ 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)}))}
Expand Down
12 changes: 6 additions & 6 deletions crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -93,7 +93,7 @@ pub(crate) struct OverrideOptions {
print_width: Option<u16>,
/// https://prettier.io/docs/en/options#use-tabs
use_tabs: Option<bool>,
/// https://prettier.io/docs/en/options#trailing-comma
/// https://prettier.io/docs/en/options#trailing-commas
trailing_comma: Option<PrettierTrailingComma>,
/// https://prettier.io/docs/en/options#tab-width
tab_width: Option<u8>,
Expand Down Expand Up @@ -147,7 +147,7 @@ enum QuoteProps {
Preserve,
}

impl From<PrettierTrailingComma> for TrailingComma {
impl From<PrettierTrailingComma> for TrailingCommas {
fn from(value: PrettierTrailingComma) -> Self {
match value {
PrettierTrailingComma::All => Self::All,
Expand Down Expand Up @@ -240,7 +240,7 @@ impl TryFrom<PrettierConfiguration> 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()),
quote_style: Some(quote_style),
quote_properties: Some(value.quote_props.into()),
bracket_spacing: Some(value.bracket_spacing),
Expand Down Expand Up @@ -335,7 +335,7 @@ impl TryFrom<Override> 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,
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ fn applies_custom_trailing_comma() {
Args::from(
[
("format"),
("--trailing-comma"),
("--trailing-commas"),
("none"),
("--write"),
file_path.as_os_str().to_str().unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The configuration that is contained inside the file `biome.json`
default auto.
--jsx-quote-style=<double|single> The type of quotes used in JSX. Defaults to double.
--quote-properties=<preserve|as-needed> When properties in objects are quoted. Defaults to asNeeded.
--trailing-comma=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
--trailing-commas=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
syntactic structures. Defaults to "all".
--semicolons=<always|as-needed> Whether the formatter prints semicolons for all statements or
only in for statements where it is necessary because of ASI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The configuration that is contained inside the file `biome.json`
default auto.
--jsx-quote-style=<double|single> The type of quotes used in JSX. Defaults to double.
--quote-properties=<preserve|as-needed> When properties in objects are quoted. Defaults to asNeeded.
--trailing-comma=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
--trailing-commas=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
syntactic structures. Defaults to "all".
--semicolons=<always|as-needed> Whether the formatter prints semicolons for all statements or
only in for statements where it is necessary because of ASI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Generic options applied to all files
Formatting options specific to the JavaScript files
--jsx-quote-style=<double|single> The type of quotes used in JSX. Defaults to double.
--quote-properties=<preserve|as-needed> When properties in objects are quoted. Defaults to asNeeded.
--trailing-comma=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
--trailing-commas=<all|es5|none> Print trailing commas wherever possible in multi-line comma-separated
syntactic structures. Defaults to "all".
--semicolons=<always|as-needed> Whether the formatter prints semicolons for all statements or
only in for statements where it is necessary because of ASI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ flags/invalid ━━━━━━━━━━━━━━━━━━━━━━
```


Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ biome.json migrate ━━━━━━━━━━━━━━━━━━━━
13 │ + → → "formatter":·{
14 │ + → → → "jsxQuoteStyle":·"double",
15 │ + → → → "quoteProperties":·"asNeeded",
16 │ + → → → "trailingComma":·"all",
16 │ + → → → "trailingCommas":·"all",
17 │ + → → → "semicolons":·"always",
18 │ + → → → "arrowParentheses":·"always",
19 │ + → → → "bracketSpacing":·true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ biome.json migrate ━━━━━━━━━━━━━━━━━━━━
12 │ + → → "formatter":·{
13 │ + → → → "jsxQuoteStyle":·"double",
14 │ + → → → "quoteProperties":·"asNeeded",
15 │ + → → → "trailingComma":·"all",
15 │ + → → → "trailingCommas":·"all",
16 │ + → → → "semicolons":·"asNeeded",
17 │ + → → → "arrowParentheses":·"always",
18 │ + → → → "bracketSpacing":·true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ biome.jsonc migrate ━━━━━━━━━━━━━━━━━━━━
13 │ + → → "formatter":·{
14 │ + → → → "jsxQuoteStyle":·"double",
15 │ + → → → "quoteProperties":·"asNeeded",
16 │ + → → → "trailingComma":·"all",
16 │ + → → → "trailingCommas":·"all",
17 │ + → → → "semicolons":·"always",
18 │ + → → → "arrowParentheses":·"always",
19 │ + → → → "bracketSpacing":·true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ biome.json migrate ━━━━━━━━━━━━━━━━━━━━
12 │ + → → "formatter":·{
13 │ + → → → "jsxQuoteStyle":·"double",
14 │ + → → → "quoteProperties":·"asNeeded",
15 │ + → → → "trailingComma":·"all",
15 │ + → → → "trailingCommas":·"all",
16 │ + → → → "semicolons":·"asNeeded",
17 │ + → → → "arrowParentheses":·"always",
18 │ + → → → "bracketSpacing":·true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ biome.json migrate ━━━━━━━━━━━━━━━━━━━━
14 │ + → → "formatter":·{
15 │ + → → → "jsxQuoteStyle":·"double",
16 │ + → → → "quoteProperties":·"asNeeded",
17 │ + → → → "trailingComma":·"all",
17 │ + → → → "trailingCommas":·"all",
18 │ + → → → "semicolons":·"always",
19 │ + → → → "arrowParentheses":·"always",
20 │ + → → → "bracketSpacing":·true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expression: content
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expression: content
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expression: content
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ expression: content
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expression: content
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "all",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ JavaScript Formatter:
Enabled: true
JSX quote style: Single
Quote properties: AsNeeded
Trailing comma: All
Trailing commas: All
Semicolons: Always
Arrow parentheses: Always
Bracket spacing: false
Expand Down
18 changes: 13 additions & 5 deletions crates/biome_configuration/src/javascript/formatter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::PlainIndentStyle;
use biome_deserialize_macros::{Deserializable, Merge, Partial};
use biome_formatter::{AttributePosition, LineEnding, LineWidth, QuoteStyle};
use biome_js_formatter::context::trailing_comma::TrailingComma;
use biome_js_formatter::context::trailing_commas::TrailingCommas;
use biome_js_formatter::context::{ArrowParentheses, QuoteProperties, Semicolons};
use bpaf::Bpaf;
use serde::{Deserialize, Serialize};
Expand All @@ -21,8 +21,16 @@ pub struct JavascriptFormatter {
pub quote_properties: QuoteProperties,

/// Print trailing commas wherever possible in multi-line comma-separated syntactic structures. Defaults to "all".
#[partial(bpaf(long("trailing-comma"), argument("all|es5|none"), optional))]
pub trailing_comma: TrailingComma,
#[partial(bpaf(
long("trailing-commas"),
// TODO: Remove in 2.0.0
long("trailing-comma"),
argument("all|es5|none"),
optional
))]
// TODO: Remove in 2.0.0
#[partial(serde(alias = "trailingComma"))]
pub trailing_commas: TrailingCommas,

/// Whether the formatter prints semicolons for all statements or only in for statements where it is necessary because of ASI.
#[partial(bpaf(long("semicolons"), argument("always|as-needed"), optional))]
Expand Down Expand Up @@ -99,7 +107,7 @@ impl PartialJavascriptFormatter {
enabled: self.enabled.unwrap_or_default(),
jsx_quote_style: self.jsx_quote_style.unwrap_or_default(),
quote_properties: self.quote_properties.unwrap_or_default(),
trailing_comma: self.trailing_comma.unwrap_or_default(),
trailing_commas: self.trailing_commas.unwrap_or_default(),
semicolons: self.semicolons.unwrap_or_default(),
arrow_parentheses: self.arrow_parentheses.unwrap_or_default(),
bracket_spacing: self.bracket_spacing.unwrap_or_default(),
Expand All @@ -121,7 +129,7 @@ impl Default for JavascriptFormatter {
enabled: true,
jsx_quote_style: Default::default(),
quote_properties: Default::default(),
trailing_comma: Default::default(),
trailing_commas: Default::default(),
semicolons: Default::default(),
arrow_parentheses: Default::default(),
bracket_spacing: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Rule for UseEnumInitializers {
has_mutations = true;

// When creating the replacement node we first need to remove the trailing trivia.
// Otherwise nodes without trailing comma will add [JsSyntacKind::EQ] and [EnumInitializer]
// Otherwise nodes without a trailing comma will add [JsSyntacKind::EQ] and [EnumInitializer]
// after it.
let new_enum_member = enum_member
.clone()
Expand Down
22 changes: 11 additions & 11 deletions crates/biome_js_formatter/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod trailing_comma;
pub mod trailing_commas;

use crate::comments::{FormatJsLeadingComment, JsCommentStyle, JsComments};
use biome_deserialize_macros::{Deserializable, Merge};
Expand All @@ -12,7 +12,7 @@ use std::fmt;
use std::fmt::Debug;
use std::rc::Rc;
use std::str::FromStr;
pub use trailing_comma::TrailingComma;
pub use trailing_commas::TrailingCommas;

#[derive(Debug, Clone)]
pub struct JsFormatContext {
Expand Down Expand Up @@ -153,7 +153,7 @@ pub struct JsFormatOptions {
quote_properties: QuoteProperties,

/// Print trailing commas wherever possible in multi-line comma-separated syntactic structures. Defaults to "all".
trailing_comma: TrailingComma,
trailing_commas: TrailingCommas,

/// Whether the formatter prints semicolons for all statements, class members, and type members or only when necessary because of [ASI](https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-automatic-semicolon-insertion).
semicolons: Semicolons,
Expand Down Expand Up @@ -185,7 +185,7 @@ impl JsFormatOptions {
quote_style: QuoteStyle::default(),
jsx_quote_style: QuoteStyle::default(),
quote_properties: QuoteProperties::default(),
trailing_comma: TrailingComma::default(),
trailing_commas: TrailingCommas::default(),
semicolons: Semicolons::default(),
arrow_parentheses: ArrowParentheses::default(),
bracket_spacing: BracketSpacing::default(),
Expand Down Expand Up @@ -244,8 +244,8 @@ impl JsFormatOptions {
self
}

pub fn with_trailing_comma(mut self, trailing_comma: TrailingComma) -> Self {
self.trailing_comma = trailing_comma;
pub fn with_trailing_commas(mut self, trailing_commas: TrailingCommas) -> Self {
self.trailing_commas = trailing_commas;
self
}

Expand Down Expand Up @@ -299,8 +299,8 @@ impl JsFormatOptions {
self.quote_properties = quote_properties;
}

pub fn set_trailing_comma(&mut self, trailing_comma: TrailingComma) {
self.trailing_comma = trailing_comma;
pub fn set_trailing_commas(&mut self, trailing_commas: TrailingCommas) {
self.trailing_commas = trailing_commas;
}
pub fn set_attribute_position(&mut self, attribute_position: AttributePosition) {
self.attribute_position = attribute_position;
Expand Down Expand Up @@ -338,8 +338,8 @@ impl JsFormatOptions {
self.source_type
}

pub fn trailing_comma(&self) -> TrailingComma {
self.trailing_comma
pub fn trailing_commas(&self) -> TrailingCommas {
self.trailing_commas
}

pub fn semicolons(&self) -> Semicolons {
Expand Down Expand Up @@ -390,7 +390,7 @@ impl fmt::Display for JsFormatOptions {
writeln!(f, "Quote style: {}", self.quote_style)?;
writeln!(f, "JSX quote style: {}", self.jsx_quote_style)?;
writeln!(f, "Quote properties: {}", self.quote_properties)?;
writeln!(f, "Trailing comma: {}", self.trailing_comma)?;
writeln!(f, "Trailing commas: {}", self.trailing_commas)?;
writeln!(f, "Semicolons: {}", self.semicolons)?;
writeln!(f, "Arrow parentheses: {}", self.arrow_parentheses)?;
writeln!(f, "Bracket spacing: {}", self.bracket_spacing.value())?;
Expand Down

0 comments on commit 102737d

Please sign in to comment.