Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(eslint-plugin): [no-confusing-void-expression] check sequence expressions for void is in last position #6597

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

Merged
merged 1 commit into from
Mar 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export default util.createRule<Options, MessageId>({
suggest: [{ messageId: 'voidExprWrapVoid', fix: wrapVoidFix }],
});
}

context.report({
node,
messageId: 'invalidVoidExpr',
Expand All @@ -225,6 +226,11 @@ export default util.createRule<Options, MessageId>({
node.parent,
util.NullThrowsReasons.MissingParent,
);
if (parent.type === AST_NODE_TYPES.SequenceExpression) {
if (node !== parent.expressions[parent.expressions.length - 1]) {
return null;
}
}

if (parent.type === AST_NODE_TYPES.ExpressionStatement) {
// e.g. `{ console.log("foo"); }`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ ruleTester.run('no-confusing-void-expression', rule, {
return void console.log('foo');
`,
}),
`
function cool(input: string) {
return console.log(input), input;
}
`,
{
code: `
function cool(input: string) {
return input, console.log(input), input;
}
`,
},
],

invalid: [
Expand Down Expand Up @@ -87,6 +99,14 @@ ruleTester.run('no-confusing-void-expression', rule, {
],
}),

{
code: `
function notcool(input: string) {
return input, console.log(input);
}
`,
errors: [{ line: 3, column: 17, messageId: 'invalidVoidExpr' }],
},
{
code: "() => console.log('foo');",
errors: [{ line: 1, column: 7, messageId: 'invalidVoidExprArrow' }],
Expand Down