Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [prefer-optional-chain] suggests optional chaining during strict null equality check#8717

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
16 commits
Select commitHold shift + click to select a range
8baa3fa
fix [prefer-optional-chain] suggests optional chaining during strict …
up201304504Mar 18, 2024
68acba3
fix [prefer-optional-chain] suggests optional chaining during strict …
up201304504Mar 19, 2024
cb68747
Fix lint
jsfm01Mar 22, 2024
29246c4
Add prefer-optional-chain test
jsfm01Mar 22, 2024
5307759
Fix lint
jsfm01Mar 22, 2024
6fb2f03
rebase and fix prefer optional chain on strict null equality
up201304504Mar 31, 2024
3a8bdb7
fix prefer optional chain on strict null equality
up201304504Mar 31, 2024
ef31674
fix lint
up201304504Apr 1, 2024
80d78d9
Merge branch 'main' into fix/7654-prefer-optional-chain
up201304504Apr 10, 2024
f49c964
tests: code review suggestion
up201304504Apr 10, 2024
9904ae4
Merge branch 'main' into fix/7654-prefer-optional-chain
jsfm01Apr 19, 2024
8c0b87b
Merge branch 'main' into fix/7654-prefer-optional-chain
up201304504Apr 22, 2024
7094d28
Update packages/eslint-plugin/src/rules/prefer-optional-chain-utils/a…
JoshuaKGoldbergApr 23, 2024
5a0732b
Merge branch 'main'
JoshuaKGoldbergApr 23, 2024
888874b
Merge branch 'main' into fix/7654-prefer-optional-chain
up201304504Apr 23, 2024
27f7269
Merge branch 'main' into fix/7654-prefer-optional-chain
up201304504Apr 23, 2024
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -61,13 +61,24 @@ const analyzeAndChainOperand: OperandAnalyzer = (
chain,
) => {
switch (operand.comparisonType) {
case NullishComparisonType.Boolean:
case NullishComparisonType.Boolean: {
const nextOperand = chain.at(index + 1);
if (
nextOperand?.comparisonType ===
NullishComparisonType.NotStrictEqualNull &&
operand.comparedName.type === AST_NODE_TYPES.Identifier
) {
return null;
}
return [operand];
}

case NullishComparisonType.NotEqualNullOrUndefined:
return [operand];

case NullishComparisonType.NotStrictEqualNull: {
// handle `x !== null && x !== undefined`
const nextOperand = chain[index + 1] as ValidOperand | undefined;
const nextOperand = chain.at(index + 1);
if (
nextOperand?.comparisonType ===
NullishComparisonType.NotStrictEqualUndefined &&
Expand All@@ -94,7 +105,7 @@ const analyzeAndChainOperand: OperandAnalyzer = (

case NullishComparisonType.NotStrictEqualUndefined: {
// handle `x !== undefined && x !== null`
const nextOperand = chain[index + 1] as ValidOperand | undefined;
const nextOperand = chain.at(index + 1);
if (
nextOperand?.comparisonType ===
NullishComparisonType.NotStrictEqualNull &&
Expand DownExpand Up@@ -132,7 +143,7 @@ const analyzeOrChainOperand: OperandAnalyzer = (

case NullishComparisonType.StrictEqualNull: {
// handle `x === null || x === undefined`
const nextOperand = chain[index + 1] as ValidOperand | undefined;
const nextOperand = chain.at(index + 1);
if (
nextOperand?.comparisonType ===
NullishComparisonType.StrictEqualUndefined &&
Expand All@@ -159,7 +170,7 @@ const analyzeOrChainOperand: OperandAnalyzer = (

case NullishComparisonType.StrictEqualUndefined: {
// handle `x === undefined || x === null`
const nextOperand = chain[index + 1] as ValidOperand | undefined;
const nextOperand = chain.at(index + 1);
if (
nextOperand?.comparisonType === NullishComparisonType.StrictEqualNull &&
compareNodes(operand.comparedName, nextOperand.comparedName) ===
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -793,6 +793,8 @@ describe('hand-crafted cases', () => {
'(function () {}) && function () {}.name;',
'(class Foo {}) && class Foo {}.constructor;',
"new Map().get('a') && new Map().get('a').what;",
// https://github.com/typescript-eslint/typescript-eslint/issues/7654
'data && data.value !== null;',
{
code: '<div /> && (<div />).wtf;',
parserOptions: { ecmaFeatures: { jsx: true } },
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp