Skip to content

fix(eslint-plugin): [prefer-optional-chain] ignore check option for most RHS of a chain #11272

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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aec9ef5
feat: add check void option
nayounsang Jun 5, 2025
e35a6f2
test: add test case for check void
nayounsang Jun 5, 2025
eacc622
feat: check void type
nayounsang Jun 5, 2025
88decc1
chore: add snapshot
nayounsang Jun 5, 2025
4171c5e
docs: add checkvoid section
nayounsang Jun 5, 2025
791461b
chore: update snapshot
nayounsang Jun 5, 2025
b3d2a4f
refactor: inject option based on flagsToExcludeFromCheck
nayounsang Jun 7, 2025
656ec50
test: add test for checkVoid = false
nayounsang Jun 7, 2025
3ea00d0
Merge branch 'main' into void-optional-chain
nayounsang Jun 11, 2025
5e7fec4
Merge branch 'void-optional-chain' of https://github.com/nayounsang/t…
nayounsang Jun 12, 2025
4b92ad4
test: add tc for all checks are excluded but invaild
nayounsang Jun 12, 2025
01f6313
Merge branch 'main' into void-optional-chain
nayounsang Jul 11, 2025
b3bf6b7
test: add test cases
nayounsang Jul 12, 2025
b0adaa8
fix: ignore isValidFalseBooleanCheckType if there is no more op
nayounsang Jul 12, 2025
2559e54
feat: remove checkVoid option
nayounsang Jul 12, 2025
9fa30d7
docs: remove checkVoid on docs
nayounsang Jul 12, 2025
1ef4c51
fix: reupdate snapshot
nayounsang Jul 12, 2025
d0b2c6b
Merge branch 'main' into void-optional-chain
nayounsang Jul 16, 2025
87107cd
chore: revert gatherLogicalOperands.ts
nayounsang Jul 16, 2025
cba0f37
chore: revert perfer-optional-chain.test.ts
nayounsang Jul 16, 2025
433e6d4
fix: ignore isValidFalseBooleanCheckType if there is no more op
nayounsang Jul 16, 2025
baf82db
test: add test case
nayounsang Jul 16, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ export function gatherLogicalOperands(
case AST_NODE_TYPES.UnaryExpression:
if (
operand.operator === '!' &&
isValidFalseBooleanCheckType(
operand.argument,
areMoreOperands && node.operator === '||',
parserServices,
options,
)
(!areMoreOperands ||
isValidFalseBooleanCheckType(
operand.argument,
node.operator === '||',
parserServices,
options,
))
) {
result.push({
comparedName: operand.argument,
Expand All @@ -274,9 +275,10 @@ export function gatherLogicalOperands(

default:
if (
!areMoreOperands ||
isValidFalseBooleanCheckType(
operand,
areMoreOperands && node.operator === '&&',
node.operator === '&&',
parserServices,
options,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1680,6 +1680,46 @@ describe('hand-crafted cases', () => {
],
output: 'a?.prop;',
},
{
code: `
declare const foo: {
bar: undefined | (() => void);
};

foo.bar && foo.bar();
`,
errors: [{ messageId: 'preferOptionalChain' }],
output: `
declare const foo: {
bar: undefined | (() => void);
};

foo.bar?.();
`,
},
{
code: `
declare const foo: { bar: string };

const baz = foo && foo.bar;
`,
errors: [
{
messageId: 'preferOptionalChain',
suggestions: [
{
messageId: 'optionalChainSuggest',
output: `
declare const foo: { bar: string };

const baz = foo?.bar;
`,
},
],
},
],
options: [{ checkString: false }],
},
],
valid: [
'!a || !b;',
Expand Down Expand Up @@ -1917,6 +1957,10 @@ describe('hand-crafted cases', () => {
!x || x.a;
`,
"typeof globalThis !== 'undefined' && globalThis.Array();",
`
declare const x: void;
x && x();
`,
],
});
});
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy