Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(immutable-data): ignoreAccessorPattern can now handle NonNullExpressions and ChainExpressions #849

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
hasID,
hasKey,
isAssignmentExpression,
isChainExpression,
isDefined,
isIdentifier,
isMemberExpression,
isPrivateIdentifier,
isThisExpression,
isTSAsExpression,
isTSNonNullExpression,
isTSTypeAnnotation,
isThisExpression,
isUnaryExpression,
isVariableDeclaration,
} from "#/utils/type-guards";
Expand Down Expand Up @@ -73,7 +75,9 @@ function getNodeIdentifierText(
? context.sourceCode
.getText(node.typeAnnotation as TSESTree.Node)
.replaceAll(/\s+/gmu, "")
: isTSAsExpression(node)
: isTSAsExpression(node) ||
isTSNonNullExpression(node) ||
isChainExpression(node)
? getNodeIdentifierText(node.expression, context)
: null;

Expand Down
12 changes: 12 additions & 0 deletions src/utils/type-guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export function isCallExpression(
return node.type === AST_NODE_TYPES.CallExpression;
}

export function isChainExpression(
node: TSESTree.Node,
): node is TSESTree.ChainExpression {
return node.type === AST_NODE_TYPES.ChainExpression;
}

export function isPropertyDefinition(
node: TSESTree.Node,
): node is TSESTree.PropertyDefinition {
Expand Down Expand Up @@ -303,6 +309,12 @@ export function isTSInterfaceHeritage(
return node.type === AST_NODE_TYPES.TSInterfaceHeritage;
}

export function isTSNonNullExpression(
node: TSESTree.Node,
): node is TSESTree.TSNonNullExpression {
return node.type === AST_NODE_TYPES.TSNonNullExpression;
}

export function isTSNullKeyword(
node: TSESTree.Node,
): node is TSESTree.TSNullKeyword {
Expand Down
6 changes: 6 additions & 0 deletions tests/rules/immutable-data/ts/object/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ const tests: Array<ValidTestCaseSet<OptionsOf<typeof rule>>> = [
`,
optionsSet: [[{ ignoreAccessorPattern: "mutable*.*" }]],
},
{
code: dedent`
mutable_foo!.baz = "hello world";
`,
optionsSet: [[{ ignoreAccessorPattern: "mutable*.*" }]],
},
];

export default tests;
Loading