Skip to content

Commit 8b6076e

Browse files
docs(linter): document options for the typescript/array-type rule (#11665)
Closes: #11661
1 parent eb55d83 commit 8b6076e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

crates/oxc_linter/src/rules/typescript/array_type.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ declare_oxc_lint!(
4141
/// const arr: number[] = new Array<number>();
4242
/// ```
4343
///
44+
/// ```typescript
45+
/// /*oxlint array-type: ["error", { "default": "array-simple" }] */
46+
/// const a: (string | number)[] = ['a', 'b'];
47+
/// const b: { prop: string }[] = [{ prop: 'a' }];
48+
/// const c: Array<MyType> = ['a', 'b'];
49+
/// const d: Array<string> = ['a', 'b'];
50+
/// ```
51+
///
4452
/// Examples of **correct** code for this rule:
4553
/// ```typescript
4654
/// /*oxlint array-type: ["error", { "default": "array" }] */
@@ -51,6 +59,31 @@ declare_oxc_lint!(
5159
/// /*oxlint array-type: ["error", { "default": "generic" }] */
5260
/// const arr: Array<number> = new Array<number>();
5361
/// ```
62+
///
63+
/// ```typescript
64+
/// /*oxlint array-type: ["error", { "default": "array-simple" }] */
65+
/// const a: Array<string | number> = ['a', 'b'];
66+
/// const b: Array<{ prop: string }> = [{ prop: 'a' }];
67+
/// const c: string[] = ['a', 'b'];
68+
/// const d: MyType[] = ['a', 'b'];
69+
/// ```
70+
///
71+
/// ### Options
72+
///
73+
/// ```json
74+
/// {
75+
/// "typescript/array-type": ["error", { "default": "array", "readonly": "array" }]
76+
/// }
77+
/// ```
78+
/// - `default`: The array type expected for mutable cases.
79+
/// - `readonly`: The array type expected for readonly cases. If omitted, the value for `default` will be used.
80+
///
81+
/// Both `default` and `readonly` can be one of:
82+
/// - `"array"`
83+
/// - `"generic"`
84+
/// - `"array-simple"`
85+
///
86+
/// The default config will enforce that all mutable and readonly arrays use the 'array' syntax.
5487
ArrayType,
5588
typescript,
5689
style,

0 commit comments

Comments
 (0)