Skip to content

Commit

Permalink
fix(no-test-callback): check argument is an identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jun 20, 2020
1 parent e7e092a commit f70612d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rules/__tests__/no-test-callback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ ruleTester.run('no-test-callback', rule, {
'test("something", someArg)',
],
invalid: [
{
code: 'test("something", (...args) => {args[0]();})',
errors: [
{
messageId: 'illegalTestCallback',
line: 1,
column: 20,
},
],
},
{
code: 'test("something", done => {done();})',
errors: [{ messageId: 'illegalTestCallback', line: 1, column: 19 }],
Expand Down
9 changes: 9 additions & 0 deletions src/rules/no-test-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export default createRule({

const [argument] = callback.params;

if (argument.type !== AST_NODE_TYPES.Identifier) {
context.report({
node: argument,
messageId: 'illegalTestCallback',
});

return;
}

if (callback.async) {
context.report({
node: argument,
Expand Down

0 comments on commit f70612d

Please sign in to comment.