Skip to content

Commit

Permalink
[Fix] no-webpack-loader-syntax/TypeScript: avoid crash on missing name
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodino committed Nov 16, 2020
1 parent 957092a commit 6797bff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-webpack-loader-syntax.js
Expand Up @@ -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.'
)
Expand Down
25 changes: 24 additions & 1 deletion 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'

Expand Down Expand Up @@ -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: [],
})
})
})

0 comments on commit 6797bff

Please sign in to comment.