1
1
import type { TSESTree } from "@typescript-eslint/utils" ;
2
- import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema" ;
2
+ import type { JSONSchema4 , JSONSchema4ObjectSchema } from "@typescript-eslint/utils/json-schema" ;
3
3
import type { RuleContext } from "@typescript-eslint/utils/ts-eslint" ;
4
+ import { deepmerge } from "deepmerge-ts" ;
4
5
import type { Type } from "typescript" ;
5
6
6
7
import tsApiUtils from "#/conditional-imports/ts-api-utils" ;
8
+ import { type IgnoreCodePatternOption , ignoreCodePatternOptionSchema , shouldIgnorePattern } from "#/options" ;
7
9
import { ruleNameScope } from "#/utils/misc" ;
8
10
import { type NamedCreateRuleCustomMeta , type Rule , type RuleResult , createRule , getTypeOfNode } from "#/utils/rule" ;
9
11
import {
@@ -32,7 +34,7 @@ export const fullName: `${typeof ruleNameScope}/${typeof name}` = `${ruleNameSco
32
34
* The options this rule can take.
33
35
*/
34
36
type Options = [
35
- {
37
+ IgnoreCodePatternOption & {
36
38
allowReturningBranches : boolean | "ifExhaustive" ;
37
39
} ,
38
40
] ;
@@ -43,7 +45,7 @@ type Options = [
43
45
const schema : JSONSchema4 [ ] = [
44
46
{
45
47
type : "object" ,
46
- properties : {
48
+ properties : deepmerge ( ignoreCodePatternOptionSchema , {
47
49
allowReturningBranches : {
48
50
oneOf : [
49
51
{
@@ -55,7 +57,7 @@ const schema: JSONSchema4[] = [
55
57
} ,
56
58
] ,
57
59
} ,
58
- } ,
60
+ } satisfies JSONSchema4ObjectSchema [ "properties" ] ) ,
59
61
additionalProperties : false ,
60
62
} ,
61
63
] ;
@@ -273,7 +275,14 @@ function checkIfStatement(
273
275
context : Readonly < RuleContext < keyof typeof errorMessages , Options > > ,
274
276
options : Readonly < Options > ,
275
277
) : RuleResult < keyof typeof errorMessages , Options > {
276
- const [ { allowReturningBranches } ] = options ;
278
+ const [ { allowReturningBranches, ignoreCodePattern } ] = options ;
279
+
280
+ if ( shouldIgnorePattern ( node . test , context , undefined , undefined , ignoreCodePattern ) ) {
281
+ return {
282
+ context,
283
+ descriptors : [ ] ,
284
+ } ;
285
+ }
277
286
278
287
return {
279
288
context,
0 commit comments