From 250a55c26f738591ff0d27a31fb2b2b99e6c5c2e Mon Sep 17 00:00:00 2001 From: unvalley Date: Sun, 4 Dec 2022 15:58:12 +0900 Subject: [PATCH 1/7] test: update test case and rule comment --- .../style/use_shorthand_array_type.rs | 21 ++++++++++++------- .../specs/style/useShorthandArrayType.ts | 8 ++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs index 17337ccc4be..22a3603b652 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs @@ -14,31 +14,36 @@ declare_rule! { /// /// ### Invalid /// ```ts,expect_diagnostic - /// let valid: Array; + /// let incorrect: Array; /// ``` /// /// ```ts,expect_diagnostic - /// let invalid2: Promise>; + /// let incorrect: Promise>; /// ``` /// /// ```ts,expect_diagnostic - /// let invalid3: Array>; + /// let incorrect: Array>; /// ``` /// /// ```ts,expect_diagnostic - /// let invalid: Array<[number, number]>; + /// let incorrect: Array<[number, number]>; /// ``` /// /// ```ts,expect_diagnostic - /// let invalid: Array<[number, number]>; + /// let incorrect: Array<[number, number]>; + /// ``` + /// + /// ```ts,expect_diagnostic + /// let incorrect: ReadonlyArray; /// ``` /// /// ### Valid /// /// ```ts - /// let valid: Array; - /// let valid: Array; - /// let valid: Array; + /// let correct: Array; + /// let correct: Array; + /// let correct: Array; + /// let correct: readonly string[]; /// ``` pub(crate) UseShorthandArrayType { version: "0.7.0", diff --git a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts index 99d675dd77e..b0b7eb6ddf4 100644 --- a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts +++ b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts @@ -8,17 +8,19 @@ let invalid1: Array>; let invalid2: Promise>; let invalid3: Array>; let invalid4: Array<[number, number]>; +let invalid5: ReadonlyArray; // valid let valid5: Array; let valid6: Array<() => string>; -type valid7 = Array -type valid8 = Array string> +type valid7 = Array; +type valid8 = Array string>; // valid end //parenthesized type -let valid8: Array<(string & number)>; +let valid8: Array; // infer type type valid9 = T extends Array ? R : any; // mapped type type valid10 = { [K in keyof T]: T[K] }; +let valid11: readonly string[]; From 4bac9b1e81420999a0dce6596ccdc8aa9cb80b69 Mon Sep 17 00:00:00 2001 From: unvalley Date: Mon, 5 Dec 2022 20:30:54 +0900 Subject: [PATCH 2/7] feat: add readonly modifier to TsArrayType --- .../src/generated/node_factory.rs | 39 ++++++++++++++----- .../src/generated/syntax_factory.rs | 9 ++++- crates/rome_js_syntax/src/generated/nodes.rs | 13 +++++-- .../rome_js_syntax/src/generated/nodes_mut.rs | 12 ++++-- crates/rome_js_unicode_table/src/tables.rs | 8 +--- xtask/codegen/js.ungram | 1 + 6 files changed, 60 insertions(+), 22 deletions(-) diff --git a/crates/rome_js_factory/src/generated/node_factory.rs b/crates/rome_js_factory/src/generated/node_factory.rs index e3ebbe5db45..f1e0ed5ebed 100644 --- a/crates/rome_js_factory/src/generated/node_factory.rs +++ b/crates/rome_js_factory/src/generated/node_factory.rs @@ -3865,15 +3865,36 @@ pub fn ts_array_type( element_type: AnyTsType, l_brack_token: SyntaxToken, r_brack_token: SyntaxToken, -) -> TsArrayType { - TsArrayType::unwrap_cast(SyntaxNode::new_detached( - JsSyntaxKind::TS_ARRAY_TYPE, - [ - Some(SyntaxElement::Node(element_type.into_syntax())), - Some(SyntaxElement::Token(l_brack_token)), - Some(SyntaxElement::Token(r_brack_token)), - ], - )) +) -> TsArrayTypeBuilder { + TsArrayTypeBuilder { + element_type, + l_brack_token, + r_brack_token, + readonly_token: None, + } +} +pub struct TsArrayTypeBuilder { + element_type: AnyTsType, + l_brack_token: SyntaxToken, + r_brack_token: SyntaxToken, + readonly_token: Option, +} +impl TsArrayTypeBuilder { + pub fn with_readonly_token(mut self, readonly_token: SyntaxToken) -> Self { + self.readonly_token = Some(readonly_token); + self + } + pub fn build(self) -> TsArrayType { + TsArrayType::unwrap_cast(SyntaxNode::new_detached( + JsSyntaxKind::TS_ARRAY_TYPE, + [ + self.readonly_token.map(|token| SyntaxElement::Token(token)), + Some(SyntaxElement::Node(self.element_type.into_syntax())), + Some(SyntaxElement::Token(self.l_brack_token)), + Some(SyntaxElement::Token(self.r_brack_token)), + ], + )) + } } pub fn ts_as_assignment( assignment: AnyJsAssignment, diff --git a/crates/rome_js_factory/src/generated/syntax_factory.rs b/crates/rome_js_factory/src/generated/syntax_factory.rs index a1d54778e5f..3e7f11351fe 100644 --- a/crates/rome_js_factory/src/generated/syntax_factory.rs +++ b/crates/rome_js_factory/src/generated/syntax_factory.rs @@ -6012,8 +6012,15 @@ impl SyntaxFactory for JsSyntaxFactory { } TS_ARRAY_TYPE => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); let mut current_element = elements.next(); + if let Some(element) = ¤t_element { + if element.kind() == T![readonly] { + slots.mark_present(); + current_element = elements.next(); + } + } + slots.next_slot(); if let Some(element) = ¤t_element { if AnyTsType::can_cast(element.kind()) { slots.mark_present(); diff --git a/crates/rome_js_syntax/src/generated/nodes.rs b/crates/rome_js_syntax/src/generated/nodes.rs index 94b8ff1e1d7..a6d01aa88fe 100644 --- a/crates/rome_js_syntax/src/generated/nodes.rs +++ b/crates/rome_js_syntax/src/generated/nodes.rs @@ -7509,19 +7509,21 @@ impl TsArrayType { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } pub fn as_fields(&self) -> TsArrayTypeFields { TsArrayTypeFields { + readonly_token: self.readonly_token(), element_type: self.element_type(), l_brack_token: self.l_brack_token(), r_brack_token: self.r_brack_token(), } } + pub fn readonly_token(&self) -> Option { support::token(&self.syntax, 0usize) } pub fn element_type(&self) -> SyntaxResult { - support::required_node(&self.syntax, 0usize) + support::required_node(&self.syntax, 1usize) } pub fn l_brack_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 1usize) + support::required_token(&self.syntax, 2usize) } pub fn r_brack_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 2usize) + support::required_token(&self.syntax, 3usize) } } #[cfg(feature = "serde")] @@ -7535,6 +7537,7 @@ impl Serialize for TsArrayType { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct TsArrayTypeFields { + pub readonly_token: Option, pub element_type: SyntaxResult, pub l_brack_token: SyntaxResult, pub r_brack_token: SyntaxResult, @@ -21006,6 +21009,10 @@ impl AstNode for TsArrayType { impl std::fmt::Debug for TsArrayType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("TsArrayType") + .field( + "readonly_token", + &support::DebugOptionalElement(self.readonly_token()), + ) .field( "element_type", &support::DebugSyntaxResult(self.element_type()), diff --git a/crates/rome_js_syntax/src/generated/nodes_mut.rs b/crates/rome_js_syntax/src/generated/nodes_mut.rs index 3d29fcbbedf..e8ef2862492 100644 --- a/crates/rome_js_syntax/src/generated/nodes_mut.rs +++ b/crates/rome_js_syntax/src/generated/nodes_mut.rs @@ -3687,22 +3687,28 @@ impl TsAnyType { } } impl TsArrayType { + pub fn with_readonly_token(self, element: Option) -> Self { + Self::unwrap_cast( + self.syntax + .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), + ) + } pub fn with_element_type(self, element: AnyTsType) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), + .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), ) } pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into()))), + .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } pub fn with_r_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into()))), + .splice_slots(3usize..=3usize, once(Some(element.into()))), ) } } diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index 7f67057597c..eb783866c93 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,9 +787,7 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { - super::bsearch_range_table(c, ID_Continue_table) - } + pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1451,7 +1449,5 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { - super::bsearch_range_table(c, ID_Start_table) - } + pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } } diff --git a/xtask/codegen/js.ungram b/xtask/codegen/js.ungram index 78e7cbb8219..b2e5c51ff06 100644 --- a/xtask/codegen/js.ungram +++ b/xtask/codegen/js.ungram @@ -2069,6 +2069,7 @@ TsImportTypeQualifier = TsArrayType = + 'readonly'? element_type: AnyTsType '[' ']' From 39cf6cd03bf46e62da5b2f7d0342ae78aa31fb0d Mon Sep 17 00:00:00 2001 From: unvalley Date: Mon, 5 Dec 2022 20:31:57 +0900 Subject: [PATCH 3/7] feat(rome_js_analyze): handle ReadonlyArray test: add test case fix diagnostic and action for readonly refactor: filter_map logic test: update snapshot fix: around array type for ungram change test: remove compile failed test case test: update snapshot test: update failed parser test chore: fmt doc: update website doc fix: use TsTypeOperatorType for readonly_token chore: restore ungram chore: restore parser test_data chore: restore and fmt chore: restore fix: array_type build --- .../style/use_shorthand_array_type.rs | 125 +++++++++++----- .../specs/style/useShorthandArrayType.ts | 26 +++- .../specs/style/useShorthandArrayType.ts.snap | 135 ++++++++++++++++++ .../src/generated/node_factory.rs | 39 ++--- .../src/generated/syntax_factory.rs | 9 +- crates/rome_js_syntax/src/generated/nodes.rs | 13 +- .../rome_js_syntax/src/generated/nodes_mut.rs | 12 +- crates/rome_js_unicode_table/src/tables.rs | 8 +- .../pages/lint/rules/useShorthandArrayType.md | 86 ++++++----- xtask/codegen/js.ungram | 1 - 10 files changed, 319 insertions(+), 135 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs index 22a3603b652..4c70655ac13 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs @@ -2,8 +2,10 @@ use rome_analyze::{context::RuleContext, declare_rule, ActionCategory, Ast, Rule use rome_console::markup; use rome_diagnostics::Applicability; use rome_js_factory::make; -use rome_js_syntax::{AnyTsType, TriviaPieceKind, TsReferenceType, TsTypeArguments, T}; -use rome_rowan::{AstNode, AstSeparatedList, BatchMutationExt}; +use rome_js_syntax::{ + AnyTsType, JsSyntaxKind, JsSyntaxToken, TriviaPieceKind, TsReferenceType, TsTypeArguments, T, +}; +use rome_rowan::{AstNode, AstSeparatedList, BatchMutationExt, TriviaPiece}; use crate::JsRuleAction; @@ -43,7 +45,6 @@ declare_rule! { /// let correct: Array; /// let correct: Array; /// let correct: Array; - /// let correct: readonly string[]; /// ``` pub(crate) UseShorthandArrayType { version: "0.7.0", @@ -52,6 +53,14 @@ declare_rule! { } } +#[derive(Debug)] +enum TsArrayKind { + /// `Array` + Simple, + /// `ReadonlyArray` + Readonly, +} + impl Rule for UseShorthandArrayType { type Query = Ast; type State = AnyTsType; @@ -61,26 +70,30 @@ impl Rule for UseShorthandArrayType { fn run(ctx: &RuleContext) -> Option { let node = ctx.query(); let type_arguments = node.type_arguments()?; - is_array_reference(node).and_then(|ret| { - if ret { - convert_to_array_type(type_arguments) - } else { - None - } - }) + + match get_array_kind_by_reference(node) { + Some(array_kind) => convert_to_array_type(type_arguments, array_kind), + None => None, + } } fn diagnostic(ctx: &RuleContext, _: &Self::State) -> Option { let node = ctx.query(); - - Some(RuleDiagnostic::new( - rule_category!(), - node.range(), - markup! { - - "Use ""shorthand T[] syntax"" instead of ""Array syntax." - }, - )) + if let Some(kind) = get_array_kind_by_reference(node) { + return Some(RuleDiagnostic::new( + rule_category!(), + node.range(), + match kind { + TsArrayKind::Simple => { + markup! {"Use ""shorthand T[] syntax"" instead of ""Array syntax."} + } + TsArrayKind::Readonly => { + markup! {"Use ""shorthand readonly T[] syntax"" instead of ""ReadonlyArray syntax."} + } + }, + )); + }; + None } fn action(ctx: &RuleContext, state: &Self::State) -> Option { @@ -89,25 +102,44 @@ impl Rule for UseShorthandArrayType { mutation.replace_node(AnyTsType::TsReferenceType(node.clone()), state.clone()); - Some(JsRuleAction { - category: ActionCategory::QuickFix, - applicability: Applicability::MaybeIncorrect, - message: markup! { "Use ""shorthand T[] syntax"" to replace" } - .to_owned(), - mutation, - }) + if let Some(kind) = get_array_kind_by_reference(node) { + let message = match kind { + TsArrayKind::Simple => { + markup! { "Use ""shorthand T[] syntax"" to replace" } + .to_owned() + } + TsArrayKind::Readonly => { + markup! { "Use ""shorthand readonly T[] syntax"" to replace" } + .to_owned() + } + }; + return Some(JsRuleAction { + category: ActionCategory::QuickFix, + applicability: Applicability::MaybeIncorrect, + message, + mutation, + }); + }; + None } } -fn is_array_reference(ty: &TsReferenceType) -> Option { +fn get_array_kind_by_reference(ty: &TsReferenceType) -> Option { let name = ty.name().ok()?; name.as_js_reference_identifier().and_then(|identifier| { let name = identifier.value_token().ok()?; - Some(name.text_trimmed() == "Array") + match name.text_trimmed() { + "Array" => Some(TsArrayKind::Simple), + "ReadonlyArray" => Some(TsArrayKind::Readonly), + _ => None, + } }) } -fn convert_to_array_type(type_arguments: TsTypeArguments) -> Option { +fn convert_to_array_type( + type_arguments: TsTypeArguments, + array_kind: TsArrayKind, +) -> Option { if type_arguments.ts_type_argument_list().len() > 0 { let types_array = type_arguments .ts_type_argument_list() @@ -125,24 +157,43 @@ fn convert_to_array_type(type_arguments: TsTypeArguments) -> Option { | AnyTsType::TsInferType(_) | AnyTsType::TsMappedType(_) => None, - AnyTsType::TsReferenceType(ty) if is_array_reference(ty).unwrap_or(false) => { - if let Some(type_arguments) = ty.type_arguments() { - convert_to_array_type(type_arguments) - } else { - Some(param) + AnyTsType::TsReferenceType(ty) => match get_array_kind_by_reference(ty) { + Some(array_kind) => { + if let Some(type_arguments) = ty.type_arguments() { + convert_to_array_type(type_arguments, array_kind) + } else { + Some(param) + } } - } + None => Some(param), + }, _ => Some(param), }; element_type.map(|element_type| { - AnyTsType::TsArrayType(make::ts_array_type( + let array_type = make::ts_array_type( element_type, make::token(T!['[']), make::token(T![']']), - )) + ); + let readonly_token = JsSyntaxToken::new_detached( + JsSyntaxKind::TS_READONLY_MODIFIER, + "readonly ", + [], + [TriviaPiece::new(TriviaPieceKind::Whitespace, 1)], + ); + match array_kind { + TsArrayKind::Simple => AnyTsType::TsArrayType(array_type), + TsArrayKind::Readonly => { + AnyTsType::TsTypeOperatorType(make::ts_type_operator_type( + readonly_token, + AnyTsType::TsArrayType(array_type), + )) + } + } }) }) .collect::>(); + match types_array.len() { 0 => {} 1 => { diff --git a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts index b0b7eb6ddf4..cddbc664136 100644 --- a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts +++ b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts @@ -8,19 +8,35 @@ let invalid1: Array>; let invalid2: Promise>; let invalid3: Array>; let invalid4: Array<[number, number]>; -let invalid5: ReadonlyArray; // valid let valid5: Array; let valid6: Array<() => string>; -type valid7 = Array; -type valid8 = Array string>; +type valid7 = Array +type valid8 = Array string> // valid end //parenthesized type -let valid8: Array; +let valid8: Array<(string & number)>; // infer type type valid9 = T extends Array ? R : any; // mapped type type valid10 = { [K in keyof T]: T[K] }; -let valid11: readonly string[]; + +// valid +let readonlyValid1: ReadonlyArray; +let readonlyValid2: ReadonlyArray; +let readonlyValid3: ReadonlyArray; +let readonlyValid5: ReadonlyArray; +let readonlyValid6: ReadonlyArray<() => string>; +type readonlyValid7 = ReadonlyArray +type readonlyValid8 = ReadonlyArray string> +let readonlyValid8: ReadonlyArray<(string & number)>; +type readonlyValid9 = T extends ReadonlyArray ? R : any; +type readonlyValid10 = { [K in keyof T]: T[K] }; + +// invalid +let readonlyInvalid1: ReadonlyArray; +let readonlyInvalid2: Promise>; +let readonlyInvalid3: ReadonlyArray>; +let readonlyInvalid4: ReadonlyArray<[number, number]>; diff --git a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap index 2fe27787f4d..7275318ffe5 100644 --- a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap +++ b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap @@ -29,6 +29,24 @@ type valid9 = T extends Array ? R : any; // mapped type type valid10 = { [K in keyof T]: T[K] }; +// valid +let readonlyValid1: ReadonlyArray; +let readonlyValid2: ReadonlyArray; +let readonlyValid3: ReadonlyArray; +let readonlyValid5: ReadonlyArray; +let readonlyValid6: ReadonlyArray<() => string>; +type readonlyValid7 = ReadonlyArray +type readonlyValid8 = ReadonlyArray string> +let readonlyValid8: ReadonlyArray<(string & number)>; +type readonlyValid9 = T extends ReadonlyArray ? R : any; +type readonlyValid10 = { [K in keyof T]: T[K] }; + +// invalid +let readonlyInvalid1: ReadonlyArray; +let readonlyInvalid2: Promise>; +let readonlyInvalid3: ReadonlyArray>; +let readonlyInvalid4: ReadonlyArray<[number, number]>; + ``` # Diagnostics @@ -199,4 +217,121 @@ useShorthandArrayType.ts:20:13 lint/style/useShorthandArrayType FIXABLE ━━ ``` +``` +useShorthandArrayType.ts:34:21 lint/style/useShorthandArrayType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. + + 32 │ type readonlyValid7 = ReadonlyArray + 33 │ type readonlyValid8 = ReadonlyArray string> + > 34 │ let readonlyValid8: ReadonlyArray<(string & number)>; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 35 │ type readonlyValid9 = T extends ReadonlyArray ? R : any; + 36 │ type readonlyValid10 = { [K in keyof T]: T[K] }; + + i Suggested fix: Use shorthand readonly T[] syntax to replace + + 32 32 │ type readonlyValid7 = ReadonlyArray + 33 33 │ type readonlyValid8 = ReadonlyArray string> + 34 │ - let·readonlyValid8:·ReadonlyArray<(string·&·number)>; + 34 │ + let·readonlyValid8:·readonly·(string·&·number)[]; + 35 35 │ type readonlyValid9 = T extends ReadonlyArray ? R : any; + 36 36 │ type readonlyValid10 = { [K in keyof T]: T[K] }; + + +``` + +``` +useShorthandArrayType.ts:39:23 lint/style/useShorthandArrayType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. + + 38 │ // invalid + > 39 │ let readonlyInvalid1: ReadonlyArray; + │ ^^^^^^^^^^^^^^^^^^ + 40 │ let readonlyInvalid2: Promise>; + 41 │ let readonlyInvalid3: ReadonlyArray>; + + i Suggested fix: Use shorthand readonly T[] syntax to replace + + 37 37 │ + 38 38 │ // invalid + 39 │ - let·readonlyInvalid1:·ReadonlyArray; + 39 │ + let·readonlyInvalid1:·readonly·foo[]; + 40 40 │ let readonlyInvalid2: Promise>; + 41 41 │ let readonlyInvalid3: ReadonlyArray>; + + +``` + +``` +useShorthandArrayType.ts:40:31 lint/style/useShorthandArrayType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. + + 38 │ // invalid + 39 │ let readonlyInvalid1: ReadonlyArray; + > 40 │ let readonlyInvalid2: Promise>; + │ ^^^^^^^^^^^^^^^^^^^^^ + 41 │ let readonlyInvalid3: ReadonlyArray>; + 42 │ let readonlyInvalid4: ReadonlyArray<[number, number]>; + + i Suggested fix: Use shorthand readonly T[] syntax to replace + + 38 38 │ // invalid + 39 39 │ let readonlyInvalid1: ReadonlyArray; + 40 │ - let·readonlyInvalid2:·Promise>; + 40 │ + let·readonlyInvalid2:·Promise; + 41 41 │ let readonlyInvalid3: ReadonlyArray>; + 42 42 │ let readonlyInvalid4: ReadonlyArray<[number, number]>; + + +``` + +``` +useShorthandArrayType.ts:41:23 lint/style/useShorthandArrayType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. + + 39 │ let readonlyInvalid1: ReadonlyArray; + 40 │ let readonlyInvalid2: Promise>; + > 41 │ let readonlyInvalid3: ReadonlyArray>; + │ ^^^^^^^^^^^^^^^^^^^^^^^ + 42 │ let readonlyInvalid4: ReadonlyArray<[number, number]>; + 43 │ + + i Suggested fix: Use shorthand readonly T[] syntax to replace + + 39 39 │ let readonlyInvalid1: ReadonlyArray; + 40 40 │ let readonlyInvalid2: Promise>; + 41 │ - let·readonlyInvalid3:·ReadonlyArray>; + 41 │ + let·readonlyInvalid3:·readonly·Foo[]; + 42 42 │ let readonlyInvalid4: ReadonlyArray<[number, number]>; + 43 43 │ + + +``` + +``` +useShorthandArrayType.ts:42:23 lint/style/useShorthandArrayType FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. + + 40 │ let readonlyInvalid2: Promise>; + 41 │ let readonlyInvalid3: ReadonlyArray>; + > 42 │ let readonlyInvalid4: ReadonlyArray<[number, number]>; + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 43 │ + + i Suggested fix: Use shorthand readonly T[] syntax to replace + + 40 40 │ let readonlyInvalid2: Promise>; + 41 41 │ let readonlyInvalid3: ReadonlyArray>; + 42 │ - let·readonlyInvalid4:·ReadonlyArray<[number,·number]>; + 42 │ + let·readonlyInvalid4:·readonly·[number,·number][]; + 43 43 │ + + +``` + diff --git a/crates/rome_js_factory/src/generated/node_factory.rs b/crates/rome_js_factory/src/generated/node_factory.rs index f1e0ed5ebed..e3ebbe5db45 100644 --- a/crates/rome_js_factory/src/generated/node_factory.rs +++ b/crates/rome_js_factory/src/generated/node_factory.rs @@ -3865,36 +3865,15 @@ pub fn ts_array_type( element_type: AnyTsType, l_brack_token: SyntaxToken, r_brack_token: SyntaxToken, -) -> TsArrayTypeBuilder { - TsArrayTypeBuilder { - element_type, - l_brack_token, - r_brack_token, - readonly_token: None, - } -} -pub struct TsArrayTypeBuilder { - element_type: AnyTsType, - l_brack_token: SyntaxToken, - r_brack_token: SyntaxToken, - readonly_token: Option, -} -impl TsArrayTypeBuilder { - pub fn with_readonly_token(mut self, readonly_token: SyntaxToken) -> Self { - self.readonly_token = Some(readonly_token); - self - } - pub fn build(self) -> TsArrayType { - TsArrayType::unwrap_cast(SyntaxNode::new_detached( - JsSyntaxKind::TS_ARRAY_TYPE, - [ - self.readonly_token.map(|token| SyntaxElement::Token(token)), - Some(SyntaxElement::Node(self.element_type.into_syntax())), - Some(SyntaxElement::Token(self.l_brack_token)), - Some(SyntaxElement::Token(self.r_brack_token)), - ], - )) - } +) -> TsArrayType { + TsArrayType::unwrap_cast(SyntaxNode::new_detached( + JsSyntaxKind::TS_ARRAY_TYPE, + [ + Some(SyntaxElement::Node(element_type.into_syntax())), + Some(SyntaxElement::Token(l_brack_token)), + Some(SyntaxElement::Token(r_brack_token)), + ], + )) } pub fn ts_as_assignment( assignment: AnyJsAssignment, diff --git a/crates/rome_js_factory/src/generated/syntax_factory.rs b/crates/rome_js_factory/src/generated/syntax_factory.rs index 3e7f11351fe..a1d54778e5f 100644 --- a/crates/rome_js_factory/src/generated/syntax_factory.rs +++ b/crates/rome_js_factory/src/generated/syntax_factory.rs @@ -6012,15 +6012,8 @@ impl SyntaxFactory for JsSyntaxFactory { } TS_ARRAY_TYPE => { let mut elements = (&children).into_iter(); - let mut slots: RawNodeSlots<4usize> = RawNodeSlots::default(); + let mut slots: RawNodeSlots<3usize> = RawNodeSlots::default(); let mut current_element = elements.next(); - if let Some(element) = ¤t_element { - if element.kind() == T![readonly] { - slots.mark_present(); - current_element = elements.next(); - } - } - slots.next_slot(); if let Some(element) = ¤t_element { if AnyTsType::can_cast(element.kind()) { slots.mark_present(); diff --git a/crates/rome_js_syntax/src/generated/nodes.rs b/crates/rome_js_syntax/src/generated/nodes.rs index a6d01aa88fe..94b8ff1e1d7 100644 --- a/crates/rome_js_syntax/src/generated/nodes.rs +++ b/crates/rome_js_syntax/src/generated/nodes.rs @@ -7509,21 +7509,19 @@ impl TsArrayType { pub const unsafe fn new_unchecked(syntax: SyntaxNode) -> Self { Self { syntax } } pub fn as_fields(&self) -> TsArrayTypeFields { TsArrayTypeFields { - readonly_token: self.readonly_token(), element_type: self.element_type(), l_brack_token: self.l_brack_token(), r_brack_token: self.r_brack_token(), } } - pub fn readonly_token(&self) -> Option { support::token(&self.syntax, 0usize) } pub fn element_type(&self) -> SyntaxResult { - support::required_node(&self.syntax, 1usize) + support::required_node(&self.syntax, 0usize) } pub fn l_brack_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 2usize) + support::required_token(&self.syntax, 1usize) } pub fn r_brack_token(&self) -> SyntaxResult { - support::required_token(&self.syntax, 3usize) + support::required_token(&self.syntax, 2usize) } } #[cfg(feature = "serde")] @@ -7537,7 +7535,6 @@ impl Serialize for TsArrayType { } #[cfg_attr(feature = "serde", derive(Serialize))] pub struct TsArrayTypeFields { - pub readonly_token: Option, pub element_type: SyntaxResult, pub l_brack_token: SyntaxResult, pub r_brack_token: SyntaxResult, @@ -21009,10 +21006,6 @@ impl AstNode for TsArrayType { impl std::fmt::Debug for TsArrayType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("TsArrayType") - .field( - "readonly_token", - &support::DebugOptionalElement(self.readonly_token()), - ) .field( "element_type", &support::DebugSyntaxResult(self.element_type()), diff --git a/crates/rome_js_syntax/src/generated/nodes_mut.rs b/crates/rome_js_syntax/src/generated/nodes_mut.rs index e8ef2862492..3d29fcbbedf 100644 --- a/crates/rome_js_syntax/src/generated/nodes_mut.rs +++ b/crates/rome_js_syntax/src/generated/nodes_mut.rs @@ -3687,28 +3687,22 @@ impl TsAnyType { } } impl TsArrayType { - pub fn with_readonly_token(self, element: Option) -> Self { - Self::unwrap_cast( - self.syntax - .splice_slots(0usize..=0usize, once(element.map(|element| element.into()))), - ) - } pub fn with_element_type(self, element: AnyTsType) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(1usize..=1usize, once(Some(element.into_syntax().into()))), + .splice_slots(0usize..=0usize, once(Some(element.into_syntax().into()))), ) } pub fn with_l_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(2usize..=2usize, once(Some(element.into()))), + .splice_slots(1usize..=1usize, once(Some(element.into()))), ) } pub fn with_r_brack_token(self, element: SyntaxToken) -> Self { Self::unwrap_cast( self.syntax - .splice_slots(3usize..=3usize, once(Some(element.into()))), + .splice_slots(2usize..=2usize, once(Some(element.into()))), ) } } diff --git a/crates/rome_js_unicode_table/src/tables.rs b/crates/rome_js_unicode_table/src/tables.rs index eb783866c93..7f67057597c 100644 --- a/crates/rome_js_unicode_table/src/tables.rs +++ b/crates/rome_js_unicode_table/src/tables.rs @@ -787,7 +787,9 @@ pub mod derived_property { ('\u{31350}', '\u{323af}'), ('\u{e0100}', '\u{e01ef}'), ]; - pub fn ID_Continue(c: char) -> bool { super::bsearch_range_table(c, ID_Continue_table) } + pub fn ID_Continue(c: char) -> bool { + super::bsearch_range_table(c, ID_Continue_table) + } pub const ID_Start_table: &[(char, char)] = &[ ('A', 'Z'), ('a', 'z'), @@ -1449,5 +1451,7 @@ pub mod derived_property { ('𰀀', '𱍊'), ('\u{31350}', '\u{323af}'), ]; - pub fn ID_Start(c: char) -> bool { super::bsearch_range_table(c, ID_Start_table) } + pub fn ID_Start(c: char) -> bool { + super::bsearch_range_table(c, ID_Start_table) + } } diff --git a/website/src/pages/lint/rules/useShorthandArrayType.md b/website/src/pages/lint/rules/useShorthandArrayType.md index 85a3652678d..a84dd6a64b9 100644 --- a/website/src/pages/lint/rules/useShorthandArrayType.md +++ b/website/src/pages/lint/rules/useShorthandArrayType.md @@ -12,101 +12,121 @@ When expressing array types, this rule promotes the usage of `T[]` shorthand ins ### Invalid ```ts -let valid: Array; +let incorrect: Array; ``` -
style/useShorthandArrayType.js:1:12 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let valid: Array<foo>;
-              ^^^^^^^^^^
+  > 1 │ let incorrect: Array<foo>;
+                  ^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·valid:·Array<foo>;
-      1+ let·valid:·foo[];
+    1  - let·incorrect:·Array<foo>;
+      1+ let·incorrect:·foo[];
     2 2  
   
 
```ts -let invalid2: Promise>; +let incorrect: Promise>; ``` -
style/useShorthandArrayType.js:1:23 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:24 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let invalid2: Promise<Array<string>>;
-                         ^^^^^^^^^^^^^
+  > 1 │ let incorrect: Promise<Array<string>>;
+                          ^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·invalid2:·Promise<Array<string>>;
-      1+ let·invalid2:·Promise<string[]>;
+    1  - let·incorrect:·Promise<Array<string>>;
+      1+ let·incorrect:·Promise<string[]>;
     2 2  
   
 
```ts -let invalid3: Array>; +let incorrect: Array>; ``` -
style/useShorthandArrayType.js:1:15 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let invalid3: Array<Foo<Bar>>;
-                 ^^^^^^^^^^^^^^^
+  > 1 │ let incorrect: Array<Foo<Bar>>;
+                  ^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·invalid3:·Array<Foo<Bar>>;
-      1+ let·invalid3:·Foo<Bar>[];
+    1  - let·incorrect:·Array<Foo<Bar>>;
+      1+ let·incorrect:·Foo<Bar>[];
     2 2  
   
 
```ts -let invalid: Array<[number, number]>; +let incorrect: Array<[number, number]>; ``` -
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let invalid: Array<[number, number]>;
-                ^^^^^^^^^^^^^^^^^^^^^^^
+  > 1 │ let incorrect: Array<[number, number]>;
+                  ^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·invalid:·Array<[number,·number]>;
-      1+ let·invalid:·[number,·number][];
+    1  - let·incorrect:·Array<[number,·number]>;
+      1+ let·incorrect:·[number,·number][];
     2 2  
   
 
```ts -let invalid: Array<[number, number]>; +let incorrect: Array<[number, number]>; ``` -
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let invalid: Array<[number, number]>;
-                ^^^^^^^^^^^^^^^^^^^^^^^
+  > 1 │ let incorrect: Array<[number, number]>;
+                  ^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·invalid:·Array<[number,·number]>;
-      1+ let·invalid:·[number,·number][];
+    1  - let·incorrect:·Array<[number,·number]>;
+      1+ let·incorrect:·[number,·number][];
+    2 2  
+  
+
+ +```ts +let incorrect: ReadonlyArray; +``` + +
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
+   Use shorthand readonly T[] syntax instead of ReadonlyArray<T> syntax.
+  
+  > 1 │ let incorrect: ReadonlyArray<string>;
+                  ^^^^^^^^^^^^^^^^^^^^^
+    2 │ 
+  
+   Suggested fix: Use shorthand readonly T[] syntax to replace
+  
+    1  - let·incorrect:·ReadonlyArray<string>;
+      1+ let·incorrect:·readonly·string[];
     2 2  
   
 
@@ -114,8 +134,8 @@ let invalid: Array<[number, number]>; ### Valid ```ts -let valid: Array; -let valid: Array; -let valid: Array; +let correct: Array; +let correct: Array; +let correct: Array; ``` diff --git a/xtask/codegen/js.ungram b/xtask/codegen/js.ungram index b2e5c51ff06..78e7cbb8219 100644 --- a/xtask/codegen/js.ungram +++ b/xtask/codegen/js.ungram @@ -2069,7 +2069,6 @@ TsImportTypeQualifier = TsArrayType = - 'readonly'? element_type: AnyTsType '[' ']' From 25152d2b593229ab0fb1b0c432c48a59207f339b Mon Sep 17 00:00:00 2001 From: unvalley Date: Wed, 14 Dec 2022 02:33:23 +0900 Subject: [PATCH 4/7] test: update snapshot --- .../tests/specs/style/useShorthandArrayType.ts | 8 ++++---- .../specs/style/useShorthandArrayType.ts.snap | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts index cddbc664136..8533e36c125 100644 --- a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts +++ b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts @@ -27,10 +27,10 @@ type valid10 = { [K in keyof T]: T[K] }; let readonlyValid1: ReadonlyArray; let readonlyValid2: ReadonlyArray; let readonlyValid3: ReadonlyArray; -let readonlyValid5: ReadonlyArray; -let readonlyValid6: ReadonlyArray<() => string>; -type readonlyValid7 = ReadonlyArray -type readonlyValid8 = ReadonlyArray string> +let readonlyValid4: ReadonlyArray; +let readonlyValid5: ReadonlyArray<() => string>; +type readonlyValid6 = ReadonlyArray +type readonlyValid7 = ReadonlyArray string> let readonlyValid8: ReadonlyArray<(string & number)>; type readonlyValid9 = T extends ReadonlyArray ? R : any; type readonlyValid10 = { [K in keyof T]: T[K] }; diff --git a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap index 7275318ffe5..d5dcbf65269 100644 --- a/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap +++ b/crates/rome_js_analyze/tests/specs/style/useShorthandArrayType.ts.snap @@ -33,10 +33,10 @@ type valid10 = { [K in keyof T]: T[K] }; let readonlyValid1: ReadonlyArray; let readonlyValid2: ReadonlyArray; let readonlyValid3: ReadonlyArray; -let readonlyValid5: ReadonlyArray; -let readonlyValid6: ReadonlyArray<() => string>; -type readonlyValid7 = ReadonlyArray -type readonlyValid8 = ReadonlyArray string> +let readonlyValid4: ReadonlyArray; +let readonlyValid5: ReadonlyArray<() => string>; +type readonlyValid6 = ReadonlyArray +type readonlyValid7 = ReadonlyArray string> let readonlyValid8: ReadonlyArray<(string & number)>; type readonlyValid9 = T extends ReadonlyArray ? R : any; type readonlyValid10 = { [K in keyof T]: T[K] }; @@ -222,8 +222,8 @@ useShorthandArrayType.ts:34:21 lint/style/useShorthandArrayType FIXABLE ━━ ! Use shorthand readonly T[] syntax instead of ReadonlyArray syntax. - 32 │ type readonlyValid7 = ReadonlyArray - 33 │ type readonlyValid8 = ReadonlyArray string> + 32 │ type readonlyValid6 = ReadonlyArray + 33 │ type readonlyValid7 = ReadonlyArray string> > 34 │ let readonlyValid8: ReadonlyArray<(string & number)>; │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 35 │ type readonlyValid9 = T extends ReadonlyArray ? R : any; @@ -231,8 +231,8 @@ useShorthandArrayType.ts:34:21 lint/style/useShorthandArrayType FIXABLE ━━ i Suggested fix: Use shorthand readonly T[] syntax to replace - 32 32 │ type readonlyValid7 = ReadonlyArray - 33 33 │ type readonlyValid8 = ReadonlyArray string> + 32 32 │ type readonlyValid6 = ReadonlyArray + 33 33 │ type readonlyValid7 = ReadonlyArray string> 34 │ - let·readonlyValid8:·ReadonlyArray<(string·&·number)>; 34 │ + let·readonlyValid8:·readonly·(string·&·number)[]; 35 35 │ type readonlyValid9 = T extends ReadonlyArray ? R : any; From 810491d4213fe2ad2567423fa751d6144fba5a50 Mon Sep 17 00:00:00 2001 From: unvalley Date: Thu, 15 Dec 2022 00:53:59 +0900 Subject: [PATCH 5/7] chore: restore change of comment --- .../style/use_shorthand_array_type.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs index 4c70655ac13..6fab7772cde 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs @@ -16,35 +16,35 @@ declare_rule! { /// /// ### Invalid /// ```ts,expect_diagnostic - /// let incorrect: Array; + /// let invalid: Array; /// ``` /// /// ```ts,expect_diagnostic - /// let incorrect: Promise>; + /// let invalid: Promise>; /// ``` /// /// ```ts,expect_diagnostic - /// let incorrect: Array>; + /// let invalid: Array>; /// ``` /// /// ```ts,expect_diagnostic - /// let incorrect: Array<[number, number]>; + /// let invalid: Array<[number, number]>; /// ``` /// /// ```ts,expect_diagnostic - /// let incorrect: Array<[number, number]>; + /// let invalid: Array<[number, number]>; /// ``` /// /// ```ts,expect_diagnostic - /// let incorrect: ReadonlyArray; + /// let invalid: ReadonlyArray; /// ``` /// /// ### Valid /// /// ```ts - /// let correct: Array; - /// let correct: Array; - /// let correct: Array; + /// let valid: Array; + /// let valid: Array; + /// let valid: Array; /// ``` pub(crate) UseShorthandArrayType { version: "0.7.0", From c310baaab32e0acedf49620db4dc91c2ac421171 Mon Sep 17 00:00:00 2001 From: unvalley Date: Fri, 16 Dec 2022 10:07:04 +0900 Subject: [PATCH 6/7] refactor: move creation of readonly_token --- .../src/analyzers/style/use_shorthand_array_type.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs index 6fab7772cde..ebc7c198424 100644 --- a/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs +++ b/crates/rome_js_analyze/src/analyzers/style/use_shorthand_array_type.rs @@ -175,15 +175,15 @@ fn convert_to_array_type( make::token(T!['[']), make::token(T![']']), ); - let readonly_token = JsSyntaxToken::new_detached( - JsSyntaxKind::TS_READONLY_MODIFIER, - "readonly ", - [], - [TriviaPiece::new(TriviaPieceKind::Whitespace, 1)], - ); match array_kind { TsArrayKind::Simple => AnyTsType::TsArrayType(array_type), TsArrayKind::Readonly => { + let readonly_token = JsSyntaxToken::new_detached( + JsSyntaxKind::TS_READONLY_MODIFIER, + "readonly ", + [], + [TriviaPiece::new(TriviaPieceKind::Whitespace, 1)], + ); AnyTsType::TsTypeOperatorType(make::ts_type_operator_type( readonly_token, AnyTsType::TsArrayType(array_type), From 95822485da44eaac367cbe396d792921c8ef8859 Mon Sep 17 00:00:00 2001 From: unvalley Date: Fri, 16 Dec 2022 10:29:55 +0900 Subject: [PATCH 7/7] doc: update website doc --- .../pages/lint/rules/useShorthandArrayType.md | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/website/src/pages/lint/rules/useShorthandArrayType.md b/website/src/pages/lint/rules/useShorthandArrayType.md index a84dd6a64b9..4fcdbec3d15 100644 --- a/website/src/pages/lint/rules/useShorthandArrayType.md +++ b/website/src/pages/lint/rules/useShorthandArrayType.md @@ -12,121 +12,121 @@ When expressing array types, this rule promotes the usage of `T[]` shorthand ins ### Invalid ```ts -let incorrect: Array; +let invalid: Array; ``` -
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let incorrect: Array<foo>;
-                  ^^^^^^^^^^
+  > 1 │ let invalid: Array<foo>;
+                ^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·incorrect:·Array<foo>;
-      1+ let·incorrect:·foo[];
+    1  - let·invalid:·Array<foo>;
+      1+ let·invalid:·foo[];
     2 2  
   
 
```ts -let incorrect: Promise>; +let invalid: Promise>; ``` -
style/useShorthandArrayType.js:1:24 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:22 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let incorrect: Promise<Array<string>>;
-                          ^^^^^^^^^^^^^
+  > 1 │ let invalid: Promise<Array<string>>;
+                        ^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·incorrect:·Promise<Array<string>>;
-      1+ let·incorrect:·Promise<string[]>;
+    1  - let·invalid:·Promise<Array<string>>;
+      1+ let·invalid:·Promise<string[]>;
     2 2  
   
 
```ts -let incorrect: Array>; +let invalid: Array>; ``` -
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let incorrect: Array<Foo<Bar>>;
-                  ^^^^^^^^^^^^^^^
+  > 1 │ let invalid: Array<Foo<Bar>>;
+                ^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·incorrect:·Array<Foo<Bar>>;
-      1+ let·incorrect:·Foo<Bar>[];
+    1  - let·invalid:·Array<Foo<Bar>>;
+      1+ let·invalid:·Foo<Bar>[];
     2 2  
   
 
```ts -let incorrect: Array<[number, number]>; +let invalid: Array<[number, number]>; ``` -
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let incorrect: Array<[number, number]>;
-                  ^^^^^^^^^^^^^^^^^^^^^^^
+  > 1 │ let invalid: Array<[number, number]>;
+                ^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·incorrect:·Array<[number,·number]>;
-      1+ let·incorrect:·[number,·number][];
+    1  - let·invalid:·Array<[number,·number]>;
+      1+ let·invalid:·[number,·number][];
     2 2  
   
 
```ts -let incorrect: Array<[number, number]>; +let invalid: Array<[number, number]>; ``` -
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand T[] syntax instead of Array<T> syntax.
   
-  > 1 │ let incorrect: Array<[number, number]>;
-                  ^^^^^^^^^^^^^^^^^^^^^^^
+  > 1 │ let invalid: Array<[number, number]>;
+                ^^^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand T[] syntax to replace
   
-    1  - let·incorrect:·Array<[number,·number]>;
-      1+ let·incorrect:·[number,·number][];
+    1  - let·invalid:·Array<[number,·number]>;
+      1+ let·invalid:·[number,·number][];
     2 2  
   
 
```ts -let incorrect: ReadonlyArray; +let invalid: ReadonlyArray; ``` -
style/useShorthandArrayType.js:1:16 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
+
style/useShorthandArrayType.js:1:14 lint/style/useShorthandArrayType  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━
 
    Use shorthand readonly T[] syntax instead of ReadonlyArray<T> syntax.
   
-  > 1 │ let incorrect: ReadonlyArray<string>;
-                  ^^^^^^^^^^^^^^^^^^^^^
+  > 1 │ let invalid: ReadonlyArray<string>;
+                ^^^^^^^^^^^^^^^^^^^^^
     2 │ 
   
    Suggested fix: Use shorthand readonly T[] syntax to replace
   
-    1  - let·incorrect:·ReadonlyArray<string>;
-      1+ let·incorrect:·readonly·string[];
+    1  - let·invalid:·ReadonlyArray<string>;
+      1+ let·invalid:·readonly·string[];
     2 2  
   
 
@@ -134,8 +134,8 @@ let incorrect: ReadonlyArray; ### Valid ```ts -let correct: Array; -let correct: Array; -let correct: Array; +let valid: Array; +let valid: Array; +let valid: Array; ```