Skip to content

Commit

Permalink
fix(eslint-plugin): [no-confusing-void-expression] check sequence exp…
Browse files Browse the repository at this point in the history
…ressions for void is in last position (#6597)

Sequence expression check and tests
  • Loading branch information
cparros committed Mar 13, 2023
1 parent f3c6373 commit d73d7d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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
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

0 comments on commit d73d7d3

Please sign in to comment.