Skip to content

Commit 525eb6a

Browse files
feat(prefer-immutable-types): allows for applying overrides to the options based on the type
fix #800
1 parent 4c7cafd commit 525eb6a

File tree

4 files changed

+399
-192
lines changed

4 files changed

+399
-192
lines changed

docs/rules/prefer-immutable-types.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,37 @@ type Options = {
248248
ReadonlyDeep?: Array<Array<{ pattern: string; replace: string }>>;
249249
Immutable?: Array<Array<{ pattern: string; replace: string }>>;
250250
};
251+
252+
overrides?: Array<{
253+
match: Array<
254+
| {
255+
from: "file";
256+
path?: string;
257+
name?: string | string[];
258+
pattern?: RegExp | RegExp[];
259+
ignoreName?: string | string[];
260+
ignorePattern?: RegExp | RegExp[];
261+
}
262+
| {
263+
from: "lib";
264+
name?: string | string[];
265+
pattern?: RegExp | RegExp[];
266+
ignoreName?: string | string[];
267+
ignorePattern?: RegExp | RegExp[];
268+
}
269+
| {
270+
from: "package";
271+
package?: string;
272+
name?: string | string[];
273+
pattern?: RegExp | RegExp[];
274+
ignoreName?: string | string[];
275+
ignorePattern?: RegExp | RegExp[];
276+
}
277+
>;
278+
options: Omit<Options, "overrides">;
279+
inherit?: boolean;
280+
disable: boolean;
281+
}>;
251282
};
252283
```
253284

@@ -482,3 +513,29 @@ It allows for the ability to ignore violations based on the identifier (name) of
482513

483514
This option takes a `RegExp` string or an array of `RegExp` strings.
484515
It allows for the ability to ignore violations based on the type (as written, with whitespace removed) of the node in question.
516+
517+
### `overrides`
518+
519+
Allows for applying overrides to the options based on the type's declaration.
520+
This can be used to override the settings for types coming from 3rd party libraries.
521+
522+
Note: Only the first matching override will be used.
523+
524+
#### `overrides[n].specifiers`
525+
526+
A specifier, or an array of specifiers to match the function type against.
527+
528+
In the case of reference types, both the type and its generics will be recursively checked.
529+
If any of them match, the specifier will be considered a match.
530+
531+
#### `overrides[n].options`
532+
533+
The options to use when a specifiers matches.
534+
535+
#### `overrides[n].inherit`
536+
537+
Inherit the root options? Default is `true`.
538+
539+
#### `overrides[n].disable`
540+
541+
If true, when a specifier matches, this rule will not be applied to the matching node.

0 commit comments

Comments
 (0)