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 authored and ljharb committed Nov 16, 2020
1 parent 957092a commit dd4e416
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block ([#1889], thanks [@andreubotella])
- [`order`]: ignore non-module-level requires ([#1940], thanks [@golopot])
- [`no-webpack-loader-syntax`]/TypeScript: avoid crash on missing name ([#1947], thanks @leonardodino)

## [2.22.1] - 2020-09-27
### Fixed
Expand Down Expand Up @@ -736,6 +737,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1947]: https://github.com/benmosher/eslint-plugin-import/pull/1947
[#1940]: https://github.com/benmosher/eslint-plugin-import/pull/1940
[#1889]: https://github.com/benmosher/eslint-plugin-import/pull/1889
[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878
Expand Down
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 dd4e416

Please sign in to comment.