Skip to content
Permalink
Browse files
πŸ› fix file-extension-in-import for scoped packages (fixes #160)
  • Loading branch information
mysticatea committed May 4, 2019
1 parent 11d2d41 commit dfb4dc0202a9f9eb106b4dddb6c0f0205fabaff6
Showing with 20 additions and 1 deletion.
  1. +7 βˆ’1 lib/rules/file-extension-in-import.js
  2. +1 βˆ’0 package.json
  3. +12 βˆ’0 tests/lib/rules/file-extension-in-import.js
@@ -8,6 +8,8 @@ const path = require("path")
const fs = require("fs")
const getImportExportTargets = require("../util/get-import-export-targets")
const getTryExtensions = require("../util/get-try-extensions")
const packageNamePattern = /^(?:@[^/\\]+[/\\])?[^/\\]+$/u
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

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

function verify({ filePath, name, node }) {
// Ignore if it's not resolved to a file or it's a bare module.
if (!filePath || !/[/\\]/u.test(name)) {
if (
!filePath ||
packageNamePattern.test(name) ||
corePackageOverridePattern.test(name)
) {
return
}

@@ -29,6 +29,7 @@
"mocha": "^6.1.4",
"nyc": "^14.0.0",
"opener": "^1.5.1",
"punycode": "^2.1.1",
"rimraf": "^2.6.3"
},
"scripts": {
@@ -32,6 +32,18 @@ new RuleTester({
filename: fixture("test.js"),
code: "import 'eslint'",
},
{
filename: fixture("test.js"),
code: "import '@typescript-eslint/parser'",
},
{
filename: fixture("test.js"),
code: "import '@typescript-eslint\\parser'",
},
{
filename: fixture("test.js"),
code: "import 'punycode/'",
},
{
filename: fixture("test.js"),
code: "import 'xxx'",

0 comments on commit dfb4dc0

Please sign in to comment.