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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing import recognise tsx extension #97

Merged
merged 1 commit into from
May 10, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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