Skip to content

Commit 48d8eba

Browse files
fix!: replace ignorePattern option with ignoreIdentifierPattern and ignoreCodePattern
fix #467
1 parent f448813 commit 48d8eba

26 files changed

+211
-131
lines changed

docs/rules/functional-parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Options = {
6565
ignoreIIFE: boolean;
6666
ignoreGettersAndSetters: boolean;
6767
};
68-
ignorePattern?: string[] | string;
68+
ignoreIdentifierPattern?: string[] | string;
6969
ignorePrefixSelector?: string[] | string;
7070
};
7171
```
@@ -192,7 +192,7 @@ The following inline callback won't be flagged:
192192
const sum = [1, 2, 3].reduce((carry, current) => current, 0);
193193
```
194194

195-
### `ignorePattern`
195+
### `ignoreIdentifierPattern`
196196

197197
This option takes a RegExp string or an array of RegExp strings.
198198
It allows for the ability to ignore violations based on a function's name.

docs/rules/immutable-data.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This rule accepts an options object of the following type:
6161
type Options = {
6262
ignoreClasses: boolean | "fieldsOnly";
6363
ignoreImmediateMutation: boolean;
64-
ignorePattern?: string[] | string;
64+
ignoreIdentifierPattern?: string[] | string;
6565
ignoreAccessorPattern?: string[] | string;
6666
};
6767
```
@@ -103,7 +103,7 @@ Ignore mutations inside classes.
103103

104104
Classes already aren't functional so ignore mutations going on inside them.
105105

106-
### `ignorePattern`
106+
### `ignoreIdentifierPattern`
107107

108108
This option takes a RegExp string or an array of RegExp strings.
109109
It allows for the ability to ignore violations based on a variable's name.

docs/rules/no-expression-statements.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ This rule accepts an options object of the following type:
5858

5959
```ts
6060
type Options = {
61-
ignorePattern?: string[] | string;
61+
ignoreCodePattern?: string[] | string;
6262
ignoreVoid?: boolean;
6363
ignoreSelfReturning?: boolean;
6464
};
@@ -83,7 +83,7 @@ Like `ignoreVoid` but instead does not flag function calls that always only retu
8383

8484
Limitation: The function declaration must explicitly use `return this`; equivalents (such as assign this to a variable first, that is then returned) won't be considered valid.
8585

86-
### `ignorePattern`
86+
### `ignoreCodePattern`
8787

8888
This option takes a RegExp string or an array of RegExp strings.
89-
It allows for the ability to ignore violations based on the line(s) of code.
89+
It allows for the ability to ignore violations based on the code itself.

docs/rules/no-let.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This rule accepts an options object of the following type:
5757
```ts
5858
type Options = {
5959
allowInFunctions: boolean;
60-
ignorePattern?: string[] | string;
60+
ignoreIdentifierPattern?: string[] | string;
6161
};
6262
```
6363

@@ -118,7 +118,7 @@ for (let [index, element] of array.entries()) {
118118

119119
If true, the rule will not flag any statements that are inside of function bodies.
120120

121-
### `ignorePattern`
121+
### `ignoreIdentifierPattern`
122122

123123
This option takes a RegExp string or an array of RegExp strings.
124124
It allows for the ability to ignore violations based on a variable's name.

docs/rules/type-declaration-immutability.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type Options = {
8686
| false;
8787
}>;
8888
ignoreInterfaces: boolean;
89-
ignorePattern: string[] | string;
89+
ignoreIdentifierPattern: string[] | string;
9090
};
9191
```
9292

@@ -189,7 +189,7 @@ If not set, or set to `false`, the fixer will be disabled.
189189
A boolean to specify whether interfaces should be exempt from these rules.
190190
`false` by default.
191191

192-
### `ignorePattern`
192+
### `ignoreIdentifierPattern`
193193

194194
This option takes a RegExp string or an array of RegExp strings.
195195
It allows for the ability to ignore violations based on a type's name.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"@cspell/dict-cryptocurrencies": "3.0.1",
8888
"@google/semantic-release-replace-plugin": "1.2.7",
8989
"@istanbuljs/nyc-config-typescript": "1.0.2",
90-
"@rebeccastevens/eslint-config": "2.0.1",
90+
"@rebeccastevens/eslint-config": "2.0.2",
9191
"@rollup/plugin-commonjs": "25.0.3",
9292
"@rollup/plugin-json": "6.0.0",
9393
"@rollup/plugin-typescript": "11.1.2",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options/ignore.ts

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { type JSONSchema4ObjectSchema } from "@typescript-eslint/utils/json-sche
33
import { type RuleContext } from "@typescript-eslint/utils/ts-eslint";
44
import escapeRegExp from "escape-string-regexp";
55

6-
import { getNodeIdentifierTexts } from "#eslint-plugin-functional/utils/misc";
6+
import {
7+
getNodeCode,
8+
getNodeIdentifierTexts,
9+
} from "#eslint-plugin-functional/utils/misc";
710
import { type BaseOptions } from "#eslint-plugin-functional/utils/rule";
811
import {
912
isInClass,
@@ -20,16 +23,36 @@ import {
2023
/**
2124
* The option to ignore patterns.
2225
*/
23-
export type IgnorePatternOption = Readonly<{
24-
ignorePattern?: ReadonlyArray<string> | string;
26+
export type IgnoreIdentifierPatternOption = Readonly<{
27+
ignoreIdentifierPattern?: ReadonlyArray<string> | string;
28+
}>;
29+
30+
/**
31+
* The schema for the option to ignore patterns.
32+
*/
33+
export const ignoreIdentifierPatternOptionSchema: JSONSchema4ObjectSchema["properties"] =
34+
{
35+
ignoreIdentifierPattern: {
36+
type: ["string", "array"],
37+
items: {
38+
type: "string",
39+
},
40+
},
41+
};
42+
43+
/**
44+
* The option to ignore patterns.
45+
*/
46+
export type IgnoreCodePatternOption = Readonly<{
47+
ignoreCodePattern?: ReadonlyArray<string> | string;
2548
}>;
2649

2750
/**
2851
* The schema for the option to ignore patterns.
2952
*/
30-
export const ignorePatternOptionSchema: JSONSchema4ObjectSchema["properties"] =
53+
export const ignoreCodePatternOptionSchema: JSONSchema4ObjectSchema["properties"] =
3154
{
32-
ignorePattern: {
55+
ignoreCodePattern: {
3356
type: ["string", "array"],
3457
items: {
3558
type: "string",
@@ -109,14 +132,12 @@ export const ignorePrefixSelectorOptionSchema: JSONSchema4ObjectSchema["properti
109132
*/
110133
function shouldIgnoreViaPattern(
111134
text: string,
112-
ignorePattern: ReadonlyArray<string> | string,
135+
pattern: ReadonlyArray<string> | string,
113136
): boolean {
114-
const patterns = Array.isArray(ignorePattern)
115-
? ignorePattern
116-
: [ignorePattern];
137+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
117138

118139
// One or more patterns match?
119-
return patterns.some((pattern) => new RegExp(pattern, "u").test(text));
140+
return patterns.some((p) => new RegExp(p, "u").test(text));
120141
}
121142

122143
/**
@@ -173,15 +194,13 @@ function accessorPatternMatch(
173194
*/
174195
function shouldIgnoreViaAccessorPattern(
175196
text: string,
176-
ignorePattern: ReadonlyArray<string> | string,
197+
pattern: ReadonlyArray<string> | string,
177198
): boolean {
178-
const patterns = Array.isArray(ignorePattern)
179-
? ignorePattern
180-
: [ignorePattern];
199+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
181200

182201
// One or more patterns match?
183-
return patterns.some((pattern) =>
184-
accessorPatternMatch(pattern.split("."), text.split(".")),
202+
return patterns.some((p) =>
203+
accessorPatternMatch(p.split("."), text.split(".")),
185204
);
186205
}
187206

@@ -223,30 +242,43 @@ export function shouldIgnoreClasses(
223242
* Should the given node be allowed base off the following rule options?
224243
*
225244
* - IgnoreAccessorPatternOption.
226-
* - IgnorePatternOption.
245+
* - IgnoreIdentifierPatternOption.
227246
*/
228247
export function shouldIgnorePattern(
229248
node: TSESTree.Node,
230249
context: Readonly<RuleContext<string, BaseOptions>>,
231-
ignorePattern: Readonly<Partial<IgnorePatternOption>["ignorePattern"]>,
250+
ignoreIdentifierPattern: Readonly<
251+
Partial<IgnoreIdentifierPatternOption>["ignoreIdentifierPattern"]
252+
>,
232253
ignoreAccessorPattern?: Readonly<
233254
Partial<IgnoreAccessorPatternOption>["ignoreAccessorPattern"]
234255
>,
256+
ignoreCodePattern?: Readonly<
257+
Partial<IgnoreCodePatternOption>["ignoreCodePattern"]
258+
>,
235259
): boolean {
236260
const texts = getNodeIdentifierTexts(node, context);
237261

238262
if (texts.length === 0) {
239-
return false;
263+
return (
264+
ignoreCodePattern !== undefined &&
265+
shouldIgnoreViaPattern(getNodeCode(node, context), ignoreCodePattern)
266+
);
240267
}
241268

242269
return (
243-
// Ignore if ignorePattern is set and a pattern matches.
244-
(ignorePattern !== undefined &&
245-
texts.every((text) => shouldIgnoreViaPattern(text, ignorePattern))) ||
270+
// Ignore if ignoreIdentifierPattern is set and a pattern matches.
271+
(ignoreIdentifierPattern !== undefined &&
272+
texts.every((text) =>
273+
shouldIgnoreViaPattern(text, ignoreIdentifierPattern),
274+
)) ||
246275
// Ignore if ignoreAccessorPattern is set and an accessor pattern matches.
247276
(ignoreAccessorPattern !== undefined &&
248277
texts.every((text) =>
249278
shouldIgnoreViaAccessorPattern(text, ignoreAccessorPattern),
250-
))
279+
)) ||
280+
// Ignore if ignoreCodePattern is set and a code pattern matches.
281+
(ignoreCodePattern !== undefined &&
282+
shouldIgnoreViaPattern(getNodeCode(node, context), ignoreCodePattern))
251283
);
252284
}

src/rules/functional-parameters.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { type RuleContext } from "@typescript-eslint/utils/ts-eslint";
77
import { deepmerge } from "deepmerge-ts";
88

99
import {
10-
type IgnorePatternOption,
10+
type IgnoreIdentifierPatternOption,
1111
type IgnorePrefixSelectorOption,
1212
} from "#eslint-plugin-functional/options";
1313
import {
1414
shouldIgnorePattern,
15-
ignorePatternOptionSchema,
15+
ignoreIdentifierPatternOptionSchema,
1616
ignorePrefixSelectorOptionSchema,
1717
} from "#eslint-plugin-functional/options";
1818
import { type ESFunction } from "#eslint-plugin-functional/utils/node-types";
@@ -45,7 +45,7 @@ type ParameterCountOptions = "atLeastOne" | "exactlyOne";
4545
* The options this rule can take.
4646
*/
4747
type Options = [
48-
IgnorePatternOption &
48+
IgnoreIdentifierPatternOption &
4949
IgnorePrefixSelectorOption & {
5050
allowRestParameter: boolean;
5151
allowArgumentsKeyword: boolean;
@@ -68,7 +68,7 @@ const schema: JSONSchema4[] = [
6868
{
6969
type: "object",
7070
properties: deepmerge(
71-
ignorePatternOptionSchema,
71+
ignoreIdentifierPatternOptionSchema,
7272
ignorePrefixSelectorOptionSchema,
7373
{
7474
allowRestParameter: {
@@ -230,9 +230,9 @@ function checkFunction(
230230
options: Readonly<Options>,
231231
): RuleResult<keyof typeof errorMessages, Options> {
232232
const [optionsObject] = options;
233-
const { ignorePattern } = optionsObject;
233+
const { ignoreIdentifierPattern } = optionsObject;
234234

235-
if (shouldIgnorePattern(node, context, ignorePattern)) {
235+
if (shouldIgnorePattern(node, context, ignoreIdentifierPattern)) {
236236
return {
237237
context,
238238
descriptors: [],
@@ -257,9 +257,9 @@ function checkIdentifier(
257257
options: Readonly<Options>,
258258
): RuleResult<keyof typeof errorMessages, Options> {
259259
const [optionsObject] = options;
260-
const { ignorePattern } = optionsObject;
260+
const { ignoreIdentifierPattern } = optionsObject;
261261

262-
if (shouldIgnorePattern(node, context, ignorePattern)) {
262+
if (shouldIgnorePattern(node, context, ignoreIdentifierPattern)) {
263263
return {
264264
context,
265265
descriptors: [],

0 commit comments

Comments
 (0)