Skip to content

Commit dd4e416

Browse files
leonardodinoljharb
authored andcommitted
[Fix] no-webpack-loader-syntax/TypeScript: avoid crash on missing name
1 parent 957092a commit dd4e416

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
99
### Fixed
1010
- [`export`]/TypeScript: properly detect export specifiers as children of a TS module block ([#1889], thanks [@andreubotella])
1111
- [`order`]: ignore non-module-level requires ([#1940], thanks [@golopot])
12+
- [`no-webpack-loader-syntax`]/TypeScript: avoid crash on missing name ([#1947], thanks @leonardodino)
1213

1314
## [2.22.1] - 2020-09-27
1415
### Fixed
@@ -736,6 +737,7 @@ for info on changes for earlier releases.
736737

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

740+
[#1947]: https://github.com/benmosher/eslint-plugin-import/pull/1947
739741
[#1940]: https://github.com/benmosher/eslint-plugin-import/pull/1940
740742
[#1889]: https://github.com/benmosher/eslint-plugin-import/pull/1889
741743
[#1878]: https://github.com/benmosher/eslint-plugin-import/pull/1878

src/rules/no-webpack-loader-syntax.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import isStaticRequire from '../core/staticRequire'
22
import docsUrl from '../docsUrl'
33

44
function reportIfNonStandard(context, node, name) {
5-
if (name.indexOf('!') !== -1) {
5+
if (name && name.indexOf('!') !== -1) {
66
context.report(node, `Unexpected '!' in '${name}'. ` +
77
'Do not use import syntax to configure webpack loaders.'
88
)

tests/src/rules/no-webpack-loader-syntax.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from '../utils'
1+
import { test, getTSParsers } from '../utils'
22

33
import { RuleTester } from 'eslint'
44

@@ -72,3 +72,26 @@ ruleTester.run('no-webpack-loader-syntax', rule, {
7272
}),
7373
],
7474
})
75+
76+
context('TypeScript', function () {
77+
getTSParsers().forEach((parser) => {
78+
const parserConfig = {
79+
parser: parser,
80+
settings: {
81+
'import/parsers': { [parser]: ['.ts'] },
82+
'import/resolver': { 'eslint-import-resolver-typescript': true },
83+
},
84+
}
85+
ruleTester.run('no-webpack-loader-syntax', rule, {
86+
valid: [
87+
test(Object.assign({
88+
code: 'import { foo } from\nalert()',
89+
}, parserConfig)),
90+
test(Object.assign({
91+
code: 'import foo from\nalert()',
92+
}, parserConfig)),
93+
],
94+
invalid: [],
95+
})
96+
})
97+
})

0 commit comments

Comments
 (0)