Skip to content

Commit

Permalink
fix: missing import recognise tsx extension (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
neviaumi committed May 10, 2023
1 parent d74040c commit 5fae8a5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@
/node_modules
/test.js
.eslintcache
.vscode
.vscode
.idea/
2 changes: 1 addition & 1 deletion lib/util/is-typescript.js
Expand Up @@ -2,7 +2,7 @@

const path = require("path")

const typescriptExtensions = [".ts", ".cts", ".mts"]
const typescriptExtensions = [".ts", ".tsx", ".cts", ".mts"]

/**
* Determine if the context source file is typescript.
Expand Down
2 changes: 2 additions & 0 deletions lib/util/map-typescript-extension.js
Expand Up @@ -8,12 +8,14 @@ const mapping = {
".ts": ".js",
".cts": ".cjs",
".mts": ".mjs",
".tsx": ".jsx",
}

const reverseMapping = {
".js": ".ts",
".cjs": ".cts",
".mjs": ".mts",
".jsx": ".tsx",
}

/**
Expand Down
Empty file.
Empty file added tests/fixtures/no-missing/e.tsx
Empty file.
5 changes: 5 additions & 0 deletions tests/lib/rules/file-extension-in-import.js
Expand Up @@ -96,6 +96,11 @@ new RuleTester({
code: "import './c.mjs'",
options: ["always"],
},
{
filename: fixture("test.tsx"),
code: "import './d.jsx'",
options: ["always"],
},
{
filename: fixture("test.js"),
code: "import './a'",
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-missing-import.js
Expand Up @@ -98,6 +98,10 @@ ruleTester.run("no-missing-import", rule, {
filename: fixture("test.js"),
code: "import mocha from 'mocha!foo?a=b&c=d';",
},
{
filename: fixture("test.tsx"),
code: "import a from './e.jsx';",
},

// Ignores it if the filename is unknown.
"import abc from 'no-exist-package-0';",
Expand Down

0 comments on commit 5fae8a5

Please sign in to comment.