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

Skip to content

Commit b2ca20d

Browse files
JayaKrishnaNamburubradzacher
authored andcommitted
feat(eslint-plugin): [no-var-requires] report on foo(require('')) (typescript-eslint#725)
Fixes typescript-eslint#665
1 parent 35dec52 commit b2ca20d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/eslint-plugin/src/rules/no-var-requires.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export default util.createRule<Options, MessageIds>({
2727
node.callee.type === AST_NODE_TYPES.Identifier &&
2828
node.callee.name === 'require' &&
2929
node.parent &&
30-
node.parent.type === AST_NODE_TYPES.VariableDeclarator
30+
(node.parent.type === AST_NODE_TYPES.VariableDeclarator ||
31+
node.parent.type === AST_NODE_TYPES.CallExpression)
3132
) {
3233
context.report({
3334
node,

packages/eslint-plugin/tests/rules/no-var-requires.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,15 @@ ruleTester.run('no-var-requires', rule, {
3838
},
3939
],
4040
},
41+
{
42+
code: "let foo = trick(require('foo'))",
43+
errors: [
44+
{
45+
messageId: 'noVarReqs',
46+
line: 1,
47+
column: 17,
48+
},
49+
],
50+
},
4151
],
4252
});

0 commit comments

Comments
 (0)