File tree 3 files changed +24
-2
lines changed
tests/rules/immutable-data/ts/object
3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,15 @@ import {
7
7
hasID ,
8
8
hasKey ,
9
9
isAssignmentExpression ,
10
+ isChainExpression ,
10
11
isDefined ,
11
12
isIdentifier ,
12
13
isMemberExpression ,
13
14
isPrivateIdentifier ,
14
- isThisExpression ,
15
15
isTSAsExpression ,
16
+ isTSNonNullExpression ,
16
17
isTSTypeAnnotation ,
18
+ isThisExpression ,
17
19
isUnaryExpression ,
18
20
isVariableDeclaration ,
19
21
} from "#/utils/type-guards" ;
@@ -73,7 +75,9 @@ function getNodeIdentifierText(
73
75
? context . sourceCode
74
76
. getText ( node . typeAnnotation as TSESTree . Node )
75
77
. replaceAll ( / \s + / gmu, "" )
76
- : isTSAsExpression ( node )
78
+ : isTSAsExpression ( node ) ||
79
+ isTSNonNullExpression ( node ) ||
80
+ isChainExpression ( node )
77
81
? getNodeIdentifierText ( node . expression , context )
78
82
: null ;
79
83
Original file line number Diff line number Diff line change @@ -75,6 +75,12 @@ export function isCallExpression(
75
75
return node . type === AST_NODE_TYPES . CallExpression ;
76
76
}
77
77
78
+ export function isChainExpression (
79
+ node : TSESTree . Node ,
80
+ ) : node is TSESTree . ChainExpression {
81
+ return node . type === AST_NODE_TYPES . ChainExpression ;
82
+ }
83
+
78
84
export function isPropertyDefinition (
79
85
node : TSESTree . Node ,
80
86
) : node is TSESTree . PropertyDefinition {
@@ -303,6 +309,12 @@ export function isTSInterfaceHeritage(
303
309
return node . type === AST_NODE_TYPES . TSInterfaceHeritage ;
304
310
}
305
311
312
+ export function isTSNonNullExpression (
313
+ node : TSESTree . Node ,
314
+ ) : node is TSESTree . TSNonNullExpression {
315
+ return node . type === AST_NODE_TYPES . TSNonNullExpression ;
316
+ }
317
+
306
318
export function isTSNullKeyword (
307
319
node : TSESTree . Node ,
308
320
) : node is TSESTree . TSNullKeyword {
Original file line number Diff line number Diff line change @@ -282,6 +282,12 @@ const tests: Array<ValidTestCaseSet<OptionsOf<typeof rule>>> = [
282
282
` ,
283
283
optionsSet : [ [ { ignoreAccessorPattern : "mutable*.*" } ] ] ,
284
284
} ,
285
+ {
286
+ code : dedent `
287
+ mutable_foo!.baz = "hello world";
288
+ ` ,
289
+ optionsSet : [ [ { ignoreAccessorPattern : "mutable*.*" } ] ] ,
290
+ } ,
285
291
] ;
286
292
287
293
export default tests ;
You can’t perform that action at this time.
0 commit comments