Skip to content

Commit

Permalink
Guard direct function calls in prefer-t-regex
Browse files Browse the repository at this point in the history
Fix #251
  • Loading branch information
GMartigny authored and novemberborn committed Jun 2, 2019
1 parent 32b45c0 commit c8ddcc3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/prefer-t-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const create = context => {

// First argument is a call expression
const isFunctionCall = firstArg.type === 'CallExpression';
if (!isFunctionCall) {
if (!isFunctionCall || !firstArg.callee.property) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions test/prefer-t-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ruleTester.run('prefer-t-regex', rule, {
header + 'test(t => t.true(foo.bar()));',
header + 'const a = /\\d+/;\ntest(t => t.truthy(a));',
header + 'const a = "not a regexp";\ntest(t => t.true(a.test("foo")));',
header + 'test("main", t => t.true(foo()));',
// Shouldn't be triggered since it's not a test file
'test(t => t.true(/\\d+/.test("foo")));'
],
Expand Down

0 comments on commit c8ddcc3

Please sign in to comment.