Skip to content

Commit f6ff69b

Browse files
committedJul 11, 2024··
fix(immutable-data): ignoreAccessorPattern can now handle NonNullExpressions and ChainExpressions (#849)
fix #840
1 parent 13e04cc commit f6ff69b

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
 

‎src/utils/misc.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import {
77
hasID,
88
hasKey,
99
isAssignmentExpression,
10+
isChainExpression,
1011
isDefined,
1112
isIdentifier,
1213
isMemberExpression,
1314
isPrivateIdentifier,
14-
isThisExpression,
1515
isTSAsExpression,
16+
isTSNonNullExpression,
1617
isTSTypeAnnotation,
18+
isThisExpression,
1719
isUnaryExpression,
1820
isVariableDeclaration,
1921
} from "#/utils/type-guards";
@@ -73,7 +75,9 @@ function getNodeIdentifierText(
7375
? context.sourceCode
7476
.getText(node.typeAnnotation as TSESTree.Node)
7577
.replaceAll(/\s+/gmu, "")
76-
: isTSAsExpression(node)
78+
: isTSAsExpression(node) ||
79+
isTSNonNullExpression(node) ||
80+
isChainExpression(node)
7781
? getNodeIdentifierText(node.expression, context)
7882
: null;
7983

‎src/utils/type-guards.ts

+12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export function isCallExpression(
7575
return node.type === AST_NODE_TYPES.CallExpression;
7676
}
7777

78+
export function isChainExpression(
79+
node: TSESTree.Node,
80+
): node is TSESTree.ChainExpression {
81+
return node.type === AST_NODE_TYPES.ChainExpression;
82+
}
83+
7884
export function isPropertyDefinition(
7985
node: TSESTree.Node,
8086
): node is TSESTree.PropertyDefinition {
@@ -303,6 +309,12 @@ export function isTSInterfaceHeritage(
303309
return node.type === AST_NODE_TYPES.TSInterfaceHeritage;
304310
}
305311

312+
export function isTSNonNullExpression(
313+
node: TSESTree.Node,
314+
): node is TSESTree.TSNonNullExpression {
315+
return node.type === AST_NODE_TYPES.TSNonNullExpression;
316+
}
317+
306318
export function isTSNullKeyword(
307319
node: TSESTree.Node,
308320
): node is TSESTree.TSNullKeyword {

‎tests/rules/immutable-data/ts/object/valid.ts

+6
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ const tests: Array<ValidTestCaseSet<OptionsOf<typeof rule>>> = [
282282
`,
283283
optionsSet: [[{ ignoreAccessorPattern: "mutable*.*" }]],
284284
},
285+
{
286+
code: dedent`
287+
mutable_foo!.baz = "hello world";
288+
`,
289+
optionsSet: [[{ ignoreAccessorPattern: "mutable*.*" }]],
290+
},
285291
];
286292

287293
export default tests;

0 commit comments

Comments
 (0)
Please sign in to comment.