Skip to content

Commit dfb4dc0

Browse files
committedMay 4, 2019
🐛 fix file-extension-in-import for scoped packages (fixes #160)
1 parent 11d2d41 commit dfb4dc0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
 

‎lib/rules/file-extension-in-import.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const path = require("path")
88
const fs = require("fs")
99
const getImportExportTargets = require("../util/get-import-export-targets")
1010
const getTryExtensions = require("../util/get-try-extensions")
11+
const packageNamePattern = /^(?:@[^/\\]+[/\\])?[^/\\]+$/u
12+
const corePackageOverridePattern = /^(?:assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|trace_events|tty|url|util|v8|vm|worker_threads|zlib)[/\\]$/u
1113

1214
/**
1315
* Get all file extensions of the files which have the same basename.
@@ -69,7 +71,11 @@ module.exports = {
6971

7072
function verify({ filePath, name, node }) {
7173
// Ignore if it's not resolved to a file or it's a bare module.
72-
if (!filePath || !/[/\\]/u.test(name)) {
74+
if (
75+
!filePath ||
76+
packageNamePattern.test(name) ||
77+
corePackageOverridePattern.test(name)
78+
) {
7379
return
7480
}
7581

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"mocha": "^6.1.4",
3030
"nyc": "^14.0.0",
3131
"opener": "^1.5.1",
32+
"punycode": "^2.1.1",
3233
"rimraf": "^2.6.3"
3334
},
3435
"scripts": {

‎tests/lib/rules/file-extension-in-import.js

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ new RuleTester({
3232
filename: fixture("test.js"),
3333
code: "import 'eslint'",
3434
},
35+
{
36+
filename: fixture("test.js"),
37+
code: "import '@typescript-eslint/parser'",
38+
},
39+
{
40+
filename: fixture("test.js"),
41+
code: "import '@typescript-eslint\\parser'",
42+
},
43+
{
44+
filename: fixture("test.js"),
45+
code: "import 'punycode/'",
46+
},
3547
{
3648
filename: fixture("test.js"),
3749
code: "import 'xxx'",

0 commit comments

Comments
 (0)
Please sign in to comment.