-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [prefer-nullish-coalescing] add ignoreTernaryTests option #4965
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
Changes from all commits
a07ac2d
0487bb7
33a6053
b7b0758
42e9737
61b9680
40609b1
e9626e9
81f1a1d
060002a
a20e741
ee6bbf6
0726c9d
c4146c0
65415e6
dda02a3
cafa047
8ee505c
119f14d
31966ff
3d0eab1
73034b0
4ef1ef7
3b36d89
67e7ab5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; | ||||||
|
||||||
export function isNodeEqual(a: TSESTree.Node, b: TSESTree.Node): boolean { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this name is a little non-specific. Maybe...
Suggested change
There's almost certainly a better name out there than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will think about this one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have thought about this, I don't like I however also have no idea for a better name 🤷♂️ |
||||||
if (a.type !== b.type) { | ||||||
return false; | ||||||
} | ||||||
if ( | ||||||
a.type === AST_NODE_TYPES.ThisExpression && | ||||||
b.type === AST_NODE_TYPES.ThisExpression | ||||||
) { | ||||||
return true; | ||||||
} | ||||||
if (a.type === AST_NODE_TYPES.Literal && b.type === AST_NODE_TYPES.Literal) { | ||||||
return a.value === b.value; | ||||||
} | ||||||
if ( | ||||||
a.type === AST_NODE_TYPES.Identifier && | ||||||
b.type === AST_NODE_TYPES.Identifier | ||||||
) { | ||||||
return a.name === b.name; | ||||||
} | ||||||
if ( | ||||||
a.type === AST_NODE_TYPES.MemberExpression && | ||||||
b.type === AST_NODE_TYPES.MemberExpression | ||||||
) { | ||||||
return ( | ||||||
isNodeEqual(a.property, b.property) && isNodeEqual(a.object, b.object) | ||||||
); | ||||||
} | ||||||
return false; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; | ||
|
||
export function isNullLiteral(i: TSESTree.Node): boolean { | ||
return i.type === AST_NODE_TYPES.Literal && i.value === null; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; | ||
|
||
export function isUndefinedIdentifier(i: TSESTree.Node): boolean { | ||
return i.type === AST_NODE_TYPES.Identifier && i.name === 'undefined'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other way to solve this is to put a bunch of
else { return; }
here instead of the oneif (!operator) { return; }
at the endThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I tried refactoring a bit and couldn't find anything significantly cleaner. 🤷