Skip to content

Commit

Permalink
feat(prefer-immutable-types): allows for applying overrides to the op…
Browse files Browse the repository at this point in the history
…tions based on the type

fix #800
  • Loading branch information
RebeccaStevens committed Jul 5, 2024
1 parent ad39239 commit 0f0ff14
Show file tree
Hide file tree
Showing 5 changed files with 398 additions and 194 deletions.
57 changes: 57 additions & 0 deletions docs/rules/prefer-immutable-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,37 @@ type Options = {
Array<{ pattern: string; replace: string; message?: string }>
>;
};

overrides?: Array<{
match: Array<
| {
from: "file";
path?: string;
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
| {
from: "lib";
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
| {
from: "package";
package?: string;
name?: string | string[];
pattern?: RegExp | RegExp[];
ignoreName?: string | string[];
ignorePattern?: RegExp | RegExp[];
}
>;
options: Omit<Options, "overrides">;
inherit?: boolean;
disable: boolean;
}>;
};
```

Expand Down Expand Up @@ -493,3 +524,29 @@ It allows for the ability to ignore violations based on the identifier (name) of

This option takes a `RegExp` string or an array of `RegExp` strings.
It allows for the ability to ignore violations based on the type (as written, with whitespace removed) of the node in question.

### `overrides`

Allows for applying overrides to the options based on the type's declaration.
This can be used to override the settings for types coming from 3rd party libraries.

Note: Only the first matching override will be used.

#### `overrides[n].specifiers`

A specifier, or an array of specifiers to match the function type against.

In the case of reference types, both the type and its generics will be recursively checked.
If any of them match, the specifier will be considered a match.

#### `overrides[n].options`

The options to use when a specifiers matches.

#### `overrides[n].inherit`

Inherit the root options? Default is `true`.

#### `overrides[n].disable`

If true, when a specifier matches, this rule will not be applied to the matching node.
3 changes: 0 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export default rsEslint(
rules: {
// Some types say they have nonnullable properties, but they don't always.
"ts/no-unnecessary-condition": "off",

// Temp
"functional/prefer-immutable-types": "off",
},
},
{
Expand Down
Loading

0 comments on commit 0f0ff14

Please sign in to comment.