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 Aug 3, 2024
1 parent ca28a4a commit 9544b7f
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 193 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 @@ -255,6 +255,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 @@ -488,3 +519,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.
1 change: 0 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default rsEslint(
"ts/no-unnecessary-condition": "off",

// Temp
"functional/prefer-immutable-types": "off",
"functional/no-throw-statements": "off",
},
},
Expand Down
Loading

0 comments on commit 9544b7f

Please sign in to comment.