Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [no-var-requires] false negative for TSAsExpressi…
…on and MemberExpression (#2139)
  • Loading branch information
toshi-toma committed May 31, 2020
1 parent 0e83d15 commit df95338
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/eslint-plugin/src/rules/no-var-requires.ts
Expand Up @@ -34,7 +34,9 @@ export default util.createRule<Options, MessageIds>({
node.parent &&
(node.parent.type === AST_NODE_TYPES.VariableDeclarator ||
node.parent.type === AST_NODE_TYPES.CallExpression ||
node.parent.type === AST_NODE_TYPES.OptionalCallExpression)
node.parent.type === AST_NODE_TYPES.OptionalCallExpression ||
node.parent.type === AST_NODE_TYPES.TSAsExpression ||
node.parent.type === AST_NODE_TYPES.MemberExpression)
) {
context.report({
node,
Expand Down
20 changes: 20 additions & 0 deletions packages/eslint-plugin/tests/rules/no-var-requires.test.ts
Expand Up @@ -102,5 +102,25 @@ ruleTester.run('no-var-requires', rule, {
},
],
},
{
code: "const foo = require('./foo.json') as Foo;",
errors: [
{
messageId: 'noVarReqs',
line: 1,
column: 13,
},
],
},
{
code: "const foo: Foo = require('./foo.json').default;",
errors: [
{
messageId: 'noVarReqs',
line: 1,
column: 18,
},
],
},
],
});

0 comments on commit df95338

Please sign in to comment.