Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-webpack-loader-syntax/TypeScript: avoid crash on missing name #1947

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: [],
})
})
})