Skip to content

Commit

Permalink
Restore import/no-unresolved for ESM-only test packages (#16387)
Browse files Browse the repository at this point in the history
## Description

#15939 and related PRs disabled this linter rule for imports to `.js`
files, since the base eslint module resolver doesn't understand that
relative imports to .js should sometimes conceptually refer to .ts files
instead. This re-enables linting for that rule in affected packages by
using
[eslint-import-resolver-typescript](https://www.npmjs.com/package/eslint-import-resolver-typescript).
  • Loading branch information
Abe27342 authored and pradeepvairamani committed Aug 9, 2023
1 parent fc4efe8 commit 4b27096
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 38 deletions.
17 changes: 7 additions & 10 deletions examples/data-objects/table-document/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ module.exports = {
rules: {
"@typescript-eslint/strict-boolean-expressions": "off",
},
overrides: [
{
// Rules only for test files
files: ["*.spec.ts", "src/test/**"],
rules: {
// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
settings: {
"import/resolver": {
// Use eslint-import-resolver-typescript.
// This ensures ESNext with `.js` extensions resolve correctly to their corresponding `.ts` files.
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
},
},
],
},
};
2 changes: 2 additions & 0 deletions examples/data-objects/table-document/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"concurrently": "^7.6.0",
"cross-env": "^7.0.3",
"eslint": "~8.6.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "~2.25.4",
"mocha": "^10.2.0",
"mocha-json-output-reporter": "^2.0.1",
"mocha-multi-reporters": "^1.5.1",
Expand Down
15 changes: 9 additions & 6 deletions examples/data-objects/webflow/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ module.exports = {
"max-len": "off",
"no-bitwise": "off",
"no-case-declarations": "off",
// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
// AB#4614 tracks moving to eslint-import-resolver-typescript (which handles such imports
// out of the box) and removing this exception.
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
},
settings: {
"import/resolver": {
// Use eslint-import-resolver-typescript.
// This ensures ESNext with `.js` extensions resolve correctly to their corresponding `.ts` files.
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
},
},
},
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
Expand Down
2 changes: 2 additions & 0 deletions examples/data-objects/webflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"cross-env": "^7.0.3",
"css-loader": "^1.0.0",
"eslint": "~8.6.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "~2.25.4",
"esm-loader-css": "^1.0.4",
"file-loader": "^3.0.1",
"html-loader": "^3.1.0",
Expand Down
15 changes: 9 additions & 6 deletions packages/test/test-end-to-end-tests/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ module.exports = {
// This library is used in the browser, so we don't want dependencies on most node libraries.
"import/no-nodejs-modules": ["error", { allow: ["url"] }],
},
settings: {
"import/resolver": {
// Use eslint-import-resolver-typescript.
// This ensures ESNext with `.js` extensions resolve correctly to their corresponding `.ts` files.
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
},
},
},
overrides: [
{
// Rules only for test files
files: ["*.spec.ts", "src/test/**"],
rules: {
// Test files are run in node only so additional node libraries can be used.
"import/no-nodejs-modules": ["error", { allow: ["assert", "url"] }],
// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
// AB#4614 tracks moving to eslint-import-resolver-typescript (which handles such imports
// out of the box) and removing this exception.
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.js$"] }],
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions packages/test/test-end-to-end-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
"@types/uuid": "^8.3.0",
"concurrently": "^7.6.0",
"eslint": "~8.6.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "~2.25.4",
"mocha-json-output-reporter": "^2.0.1",
"mocha-multi-reporters": "^1.5.1",
"moment": "^2.21.0",
Expand Down
15 changes: 9 additions & 6 deletions packages/test/test-version-utils/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ module.exports = {
rules: {
"@typescript-eslint/strict-boolean-expressions": "off", // requires strictNullChecks=true in tsconfig
"import/no-nodejs-modules": "off",
// ESLint's resolver doesn't resolve relative imports of ESNext modules correctly, since
// it resolves the path relative to the .ts file (and assumes a file with a .js extension
// should exist there)
// AB#4614 tracks moving to eslint-import-resolver-typescript (which handles such imports
// out of the box) and removing this exception.
"import/no-unresolved": ["error", { ignore: ["^\\.(.*)\\.(m|c)?js$"] }],
},
settings: {
"import/resolver": {
// Use eslint-import-resolver-typescript.
// This ensures ESNext with `.js` extensions resolve correctly to their corresponding `.ts` files.
typescript: {
extensions: [".ts", ".tsx", ".d.ts", ".js", ".jsx"],
},
},
},
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
Expand Down
2 changes: 2 additions & 0 deletions packages/test/test-version-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
"concurrently": "^7.6.0",
"cross-env": "^7.0.3",
"eslint": "~8.6.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "~2.25.4",
"mocha": "^10.2.0",
"mocha-json-output-reporter": "^2.0.1",
"mocha-multi-reporters": "^1.5.1",
Expand Down
Loading

0 comments on commit 4b27096

Please sign in to comment.