diff --git a/src/rules/no-webpack-loader-syntax.js b/src/rules/no-webpack-loader-syntax.js index 8075a6f9eb..a80bc112d5 100644 --- a/src/rules/no-webpack-loader-syntax.js +++ b/src/rules/no-webpack-loader-syntax.js @@ -2,7 +2,7 @@ import isStaticRequire from '../core/staticRequire' import docsUrl from '../docsUrl' function reportIfNonStandard(context, node, name) { - if (name.indexOf('!') !== -1) { + if (name && name.indexOf('!') !== -1) { context.report(node, `Unexpected '!' in '${name}'. ` + 'Do not use import syntax to configure webpack loaders.' ) diff --git a/tests/src/rules/no-webpack-loader-syntax.js b/tests/src/rules/no-webpack-loader-syntax.js index 23a1190fb5..a56e142e71 100644 --- a/tests/src/rules/no-webpack-loader-syntax.js +++ b/tests/src/rules/no-webpack-loader-syntax.js @@ -1,4 +1,4 @@ -import { test } from '../utils' +import { test, getTSParsers } from '../utils' import { RuleTester } from 'eslint' @@ -72,3 +72,26 @@ ruleTester.run('no-webpack-loader-syntax', rule, { }), ], }) + +context('TypeScript', function () { + getTSParsers().forEach((parser) => { + const parserConfig = { + parser: parser, + settings: { + 'import/parsers': { [parser]: ['.ts'] }, + 'import/resolver': { 'eslint-import-resolver-typescript': true }, + }, + } + ruleTester.run('no-webpack-loader-syntax', rule, { + valid: [ + test(Object.assign({ + code: 'import { foo } from\nalert()', + }, parserConfig)), + test(Object.assign({ + code: 'import foo from\nalert()', + }, parserConfig)), + ], + invalid: [], + }) + }) +})