Skip to content

Commit

Permalink
fix(eslint-plugin): [no-var-requires] report when used in type assert…
Browse files Browse the repository at this point in the history
…ion (#3074)
  • Loading branch information
armano2 committed Feb 19, 2021
1 parent 1bd8f4e commit 763a252
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/no-var-requires.ts
Expand Up @@ -37,6 +37,7 @@ export default util.createRule<Options, MessageIds>({
(parent.type === AST_NODE_TYPES.VariableDeclarator ||
parent.type === AST_NODE_TYPES.CallExpression ||
parent.type === AST_NODE_TYPES.TSAsExpression ||
parent.type === AST_NODE_TYPES.TSTypeAssertion ||
parent.type === AST_NODE_TYPES.MemberExpression)
) {
context.report({
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/tests/rules/no-var-requires.test.ts
Expand Up @@ -112,6 +112,16 @@ ruleTester.run('no-var-requires', rule, {
},
],
},
{
code: "const foo = <Foo>require('./foo.json');",
errors: [
{
messageId: 'noVarReqs',
line: 1,
column: 18,
},
],
},
{
code: "const foo: Foo = require('./foo.json').default;",
errors: [
Expand Down

0 comments on commit 763a252

Please sign in to comment.