Skip to content

Commit

Permalink
feat(eslint-plugin): [no-var-requires] report on foo(require('')) (#725)
Browse files Browse the repository at this point in the history
Fixes #665
  • Loading branch information
JayaKrishnaNamburu authored and bradzacher committed Jul 24, 2019
1 parent 35dec52 commit b2ca20d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/no-var-requires.ts
Expand Up @@ -27,7 +27,8 @@ export default util.createRule<Options, MessageIds>({
node.callee.type === AST_NODE_TYPES.Identifier &&
node.callee.name === 'require' &&
node.parent &&
node.parent.type === AST_NODE_TYPES.VariableDeclarator
(node.parent.type === AST_NODE_TYPES.VariableDeclarator ||
node.parent.type === AST_NODE_TYPES.CallExpression)
) {
context.report({
node,
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/tests/rules/no-var-requires.test.ts
Expand Up @@ -38,5 +38,15 @@ ruleTester.run('no-var-requires', rule, {
},
],
},
{
code: "let foo = trick(require('foo'))",
errors: [
{
messageId: 'noVarReqs',
line: 1,
column: 17,
},
],
},
],
});

0 comments on commit b2ca20d

Please sign in to comment.