refactor: Using default derive macro instead of manual implementation for Enum
MODIFY
crates/rome_formatter/src/lib.rs
crates/rome_formatter/src/lib.rs
@@ -73,8 +73,10 @@ use std::str::FromStr;
feature = "serde",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
+#[derive(Default)]
pub enum IndentStyle {
/// Tab
+ #[default]
Tab,
/// Space, with its quantity
Space(u8),
@@ -94,12 +96,6 @@ impl IndentStyle {
}
}
-impl Default for IndentStyle {
- fn default() -> Self {
- Self::Tab
- }
-}
-
impl FromStr for IndentStyle {
type Err = &'static str;

MODIFY
crates/rome_formatter/src/token.rs
crates/rome_formatter/src/token.rs
@@ -467,18 +467,13 @@ where
/// Determines if the whitespace separating comment trivia
/// from their associated tokens should be printed or trimmed
-#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
pub enum TriviaPrintMode {
+ #[default]
Full,
Trim,
}
-impl Default for TriviaPrintMode {
- fn default() -> Self {
- Self::Full
- }
-}
-
/// Formats the leading trivia (comments, skipped token trivia) of a token
pub fn format_leading_trivia<L: Language>(token: &SyntaxToken<L>) -> FormatLeadingTrivia<L> {
FormatLeadingTrivia {

MODIFY
crates/rome_js_formatter/src/context.rs
crates/rome_js_formatter/src/context.rs
@@ -186,17 +186,13 @@ impl CommentStyle<JsLanguage> for JsCommentStyle {
feature = "serde",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
+#[derive(Default)]
pub enum QuoteStyle {
+ #[default]
Double,
Single,
}
-impl Default for QuoteStyle {
- fn default() -> Self {
- Self::Double
- }
-}
-
impl FromStr for QuoteStyle {
type Err = &'static str;

MODIFY
crates/rome_js_formatter/src/separated.rs
crates/rome_js_formatter/src/separated.rs
@@ -178,9 +178,10 @@ pub trait FormatAstSeparatedListExtension: AstSeparatedList<Language = JsLanguag
impl<T> FormatAstSeparatedListExtension for T where T: AstSeparatedList<Language = JsLanguage> {}
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum TrailingSeparator {
/// A trailing separator is allowed and preferred
+ #[default]
Allowed,
/// A trailing separator is not allowed
@@ -194,12 +195,6 @@ pub enum TrailingSeparator {
Omit,
}
-impl Default for TrailingSeparator {
- fn default() -> Self {
- TrailingSeparator::Allowed
- }
-}
-
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct FormatSeparatedOptions {
trailing_separator: TrailingSeparator,

MODIFY
crates/rome_js_parser/src/lexer/mod.rs
crates/rome_js_parser/src/lexer/mod.rs
@@ -70,9 +70,10 @@ fn is_id_continue(c: char) -> bool {
}
/// Context in which the lexer should lex the next token
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum LexContext {
/// Default context for if the lexer isn't in any specific other context
+ #[default]
Regular,
/// For lexing the elements of a JS template literal or TS template type.
@@ -93,12 +94,6 @@ pub enum LexContext {
JsxAttributeValue,
}
-impl Default for LexContext {
- fn default() -> Self {
- LexContext::Regular
- }
-}
-
impl LexContext {
/// Returns true if this is [LexContext::Regular]
pub fn is_regular(&self) -> bool {

MODIFY
crates/rome_js_syntax/src/source_type.rs
crates/rome_js_syntax/src/source_type.rs
@@ -28,12 +28,13 @@ impl Default for LanguageVersion {
/// Is the source file an ECMAScript Module or Script.
/// Changes the parsing semantic.
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum ModuleKind {
/// An ECMAScript [Script](https://tc39.es/ecma262/multipage/ecmascript-language-scripts-and-modules.html#sec-scripts)
Script,
/// AN ECMAScript [Module](https://tc39.es/ecma262/multipage/ecmascript-language-scripts-and-modules.html#sec-modules)
+ #[default]
Module,
}
@@ -46,15 +47,10 @@ impl ModuleKind {
}
}
-impl Default for ModuleKind {
- fn default() -> Self {
- ModuleKind::Module
- }
-}
-
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum LanguageVariant {
/// Standard JavaScript or TypeScript syntax without any extensions
+ #[default]
Standard,
/// Allows JSX syntax inside a JavaScript or TypeScript file
@@ -70,21 +66,14 @@ impl LanguageVariant {
}
}
-impl Default for LanguageVariant {
- fn default() -> Self {
- LanguageVariant::Standard
- }
-}
-
-#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
pub enum Language {
+ #[default]
JavaScript,
/// TypeScript source with or without JSX.
/// `definition_file` must be true for `d.ts` files.
- TypeScript {
- definition_file: bool,
- },
+ TypeScript { definition_file: bool },
}
impl Language {
@@ -96,12 +85,6 @@ impl Language {
}
}
-impl Default for Language {
- fn default() -> Self {
- Language::JavaScript
- }
-}
-
#[derive(Clone, Copy, Debug, Default)]
pub struct SourceType {
language: Language,

MODIFY
crates/rome_service/src/configuration/formatter.rs
crates/rome_service/src/configuration/formatter.rs
@@ -69,18 +69,13 @@ where
s.serialize_u16(line_width.value())
}
-#[derive(Deserialize, Serialize, Debug, Eq, PartialEq)]
+#[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum PlainIndentStyle {
/// Tab
+ #[default]
Tab,
/// Space
Space,
}
-
-impl Default for PlainIndentStyle {
- fn default() -> Self {
- Self::Tab
- }
-}

MODIFY
crates/rome_service/src/configuration/javascript.rs
crates/rome_service/src/configuration/javascript.rs
@@ -85,16 +85,11 @@ pub struct JavascriptFormatter {
pub quote_style: QuoteStyle,
}
-#[derive(Deserialize, Serialize, Debug, Eq, PartialEq)]
+#[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", remote = "QuoteStyle")]
pub enum PlainQuoteStyle {
+ #[default]
Double,
Single,
}
-
-impl Default for PlainQuoteStyle {
- fn default() -> Self {
- Self::Double
- }
-}

refactor: Using default derive macro instead of manual implementation for Enum (#3069)