Skip to content

Commit 6ee88e8

Browse files
authored
feat: start TypeScript migration (#42)
1 parent 14ab57c commit 6ee88e8

File tree

108 files changed

+998
-927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+998
-927
lines changed

.changeset/wicked-schools-stare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": minor
3+
---
4+
5+
feat!: start TypeScript migration

.eslintrc.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @type {import('eslint').Linter.Config}
3+
*/
14
module.exports = {
25
root: true,
36
plugins: ['eslint-plugin', 'import-x'],
@@ -18,6 +21,7 @@ module.exports = {
1821
ecmaVersion: 2020,
1922
},
2023
rules: {
24+
'@typescript-eslint/no-non-null-assertion': 'off',
2125
'@typescript-eslint/no-var-requires': 'off',
2226

2327
'eslint-plugin/consistent-output': ['error', 'always'],
@@ -55,6 +59,15 @@ module.exports = {
5559
},
5660

5761
overrides: [
62+
{
63+
files: ['*.js', '*.ts'],
64+
excludedFiles: ['test/fixtures'],
65+
settings: {
66+
'import-x/resolver': {
67+
typescript: true,
68+
},
69+
},
70+
},
5871
{
5972
files: 'test/**',
6073
env: {

.github/workflows/pkg-size.yml

-32
This file was deleted.

babel.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* @type {import('@babel/core').TransformOptions}
3+
*/
14
module.exports = {
25
presets: [
36
[
@@ -22,4 +25,10 @@ module.exports = {
2225
],
2326
sourceMaps: 'inline',
2427
retainLines: true,
28+
overrides: [
29+
{
30+
include: '**/*.ts',
31+
presets: ['@babel/typescript'],
32+
},
33+
],
2534
}

jest.config.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
const testCompiled = process.env.TEST_COMPILED === '1'
2+
3+
const srcDir = testCompiled ? 'lib' : 'src'
4+
15
/**
26
* @type {import('@jest/types').Config.InitialOptions}
37
*/
48
module.exports = {
5-
collectCoverage: true,
9+
collectCoverage: !testCompiled,
610
modulePathIgnorePatterns: ['<rootDir>/test/fixtures/with-syntax-error'],
711
moduleNameMapper: {
8-
'^core/(.+)$': '<rootDir>/src/core/$1',
9-
'^eslint-plugin-import-x$': '<rootDir>/src/index.js',
10-
'^eslint-plugin-import-x/config/(.+)$': '<rootDir>/config/$1',
12+
'^core/(.+)$': `<rootDir>/${srcDir}/core/$1`,
13+
'^eslint-plugin-import-x$': `<rootDir>/${srcDir}`,
1114
'^eslint-plugin-import-x/package.json$': '<rootDir>/package.json',
12-
'^eslint-plugin-import-x/(.+)$': '<rootDir>/src/$1',
13-
'^rules/(.+)$': '<rootDir>/src/rules/$1',
15+
'^eslint-plugin-import-x/(.+)$': `<rootDir>/${srcDir}/$1`,
16+
'^rules/(.+)$': `<rootDir>/${srcDir}/rules/$1`,
1417
},
1518
testMatch: [
1619
'<rootDir>/test/**/*.spec.js',
20+
'<rootDir>/test/**/*.spec.ts',
1721
'!<rootDir>/test/fixtures/**/*.js',
1822
],
1923
}

package.json

+17-8
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
"main": "lib/index.js",
1313
"exports": {
1414
".": "./lib/index.js",
15-
"./config/*": "./config/*",
1615
"./package.json": "./package.json",
1716
"./*": "./lib/*"
1817
},
1918
"files": [
20-
"config",
21-
"lib"
19+
"lib",
20+
"!lib/*.tsbuildinfo"
2221
],
2322
"keywords": [
2423
"eslint",
@@ -31,19 +30,21 @@
3130
"export"
3231
],
3332
"scripts": {
34-
"build": "babel --quiet --out-dir lib src",
33+
"build": "rimraf lib && tsc -p src",
3534
"lint": "yarn lint:es && yarn update:eslint-docs --check",
3635
"lint:es": "eslint . --cache",
37-
"prebuild": "rimraf lib",
36+
"prepare": "patch-package",
3837
"release": "changeset publish",
3938
"test": "jest",
39+
"test-compiled": "yarn build && cross-env TEST_COMPILED=1 jest",
4040
"update:eslint-docs": "yarn build && eslint-doc-generator --rule-doc-title-format prefix-name --rule-doc-section-options false --rule-list-split meta.docs.category --ignore-config stage-0 --config-emoji recommended,☑️",
4141
"watch": "yarn test --watch"
4242
},
4343
"peerDependencies": {
4444
"eslint": "^7.2.0 || ^8"
4545
},
4646
"dependencies": {
47+
"@typescript-eslint/utils": "^5.62.0",
4748
"debug": "^4.3.4",
4849
"doctrine": "^3.0.0",
4950
"eslint-import-resolver-node": "^0.3.9",
@@ -54,23 +55,30 @@
5455
},
5556
"devDependencies": {
5657
"@1stg/prettier-config": "^4.0.1",
58+
"@1stg/tsconfig": "^2.3.3",
5759
"@angular-eslint/template-parser": "^17.2.1",
58-
"@babel/cli": "^7.23.9",
5960
"@babel/core": "^7.24.0",
6061
"@babel/eslint-parser": "^7.23.10",
6162
"@babel/plugin-proposal-decorators": "^7.24.0",
6263
"@babel/plugin-proposal-export-default-from": "^7.23.3",
6364
"@babel/preset-env": "^7.24.0",
6465
"@babel/preset-flow": "^7.24.0",
6566
"@babel/preset-react": "^7.23.3",
67+
"@babel/preset-typescript": "^7.23.3",
6668
"@babel/register": "^7.23.7",
6769
"@changesets/changelog-github": "^0.5.0",
6870
"@changesets/cli": "^2.27.1",
6971
"@eslint/import-test-order-redirect-scoped": "link:./test/fixtures/order-redirect-scoped",
7072
"@test-scope/some-module": "link:./test/fixtures/symlinked-module",
73+
"@types/eslint": "^8.56.5",
7174
"@types/jest": "^29.5.12",
72-
"@typescript-eslint/eslint-plugin": "^7.2.0",
75+
"@types/json-schema": "^7.0.15",
76+
"@typescript-eslint/eslint-plugin": "^5.62.0",
7377
"@typescript-eslint/parser": "^5.62.0",
78+
"@typescript-eslint/typescript-estree": "^5.62.0",
79+
"@unts/patch-package": "^8.0.0",
80+
"cross-env": "^7.0.3",
81+
"enhanced-resolve": "^5.16.0",
7482
"escope": "^4.0.0",
7583
"eslint": "^7.2.0 || ^8",
7684
"eslint-config-prettier": "^9.1.0",
@@ -88,6 +96,7 @@
8896
"redux": "^5.0.1",
8997
"rimraf": "^5.0.5",
9098
"svelte": "^4.2.12",
91-
"typescript": "^5.4.2"
99+
"type-fest": "^4.12.0",
100+
"typescript": "~5.1.0"
92101
}
93102
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
2+
index 9a3a1fd..46b3961 100644
3+
--- a/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
4+
+++ b/node_modules/@typescript-eslint/utils/dist/ts-eslint/Rule.d.ts
5+
@@ -6,6 +6,10 @@ import type { Scope } from './Scope';
6+
import type { SourceCode } from './SourceCode';
7+
export type RuleRecommendation = 'error' | 'strict' | 'warn' | false;
8+
interface RuleMetaDataDocs {
9+
+ /**
10+
+ * The category the rule falls under
11+
+ */
12+
+ category?: string;
13+
/**
14+
* Concise description of the rule
15+
*/

src/ExportMap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SourceCode } from 'eslint'
99

1010
import parse from './utils/parse'
1111
import visit from './utils/visit'
12-
import resolve from './utils/resolve'
12+
import { relative, resolve } from './utils/resolve'
1313
import isIgnored, { hasValidExtension } from './utils/ignore'
1414

1515
import { hashObject } from './utils/hash'
@@ -506,7 +506,7 @@ ExportMap.parse = function (path, content, context) {
506506
const namespaces = new Map()
507507

508508
function remotePath(value) {
509-
return resolve.relative(value, path, context.settings)
509+
return relative(value, path, context.settings)
510510
}
511511

512512
function resolveImport(value) {
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* Default settings for Electron applications.
35
*/
4-
module.exports = {
6+
export = {
57
settings: {
68
'import-x/core-modules': ['electron'],
79
},
8-
}
10+
} satisfies PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* unopinionated config. just the things that are necessarily runtime errors
35
* waiting to happen.
4-
* @type {Object}
56
*/
6-
module.exports = {
7+
export = {
78
plugins: ['import-x'],
89
rules: {
910
'import-x/no-unresolved': 2,
@@ -12,4 +13,4 @@ module.exports = {
1213
'import-x/default': 2,
1314
'import-x/export': 2,
1415
},
15-
}
16+
} satisfies PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
2-
* - adds platform extensions to Node resolver
4+
* adds platform extensions to Node resolver
35
*/
4-
module.exports = {
6+
export = {
57
settings: {
68
'import-x/resolver': {
79
node: {
@@ -10,4 +12,4 @@ module.exports = {
1012
},
1113
},
1214
},
13-
}
15+
} satisfies PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* Adds `.jsx` as an extension, and enables JSX parsing.
35
*
46
* Even if _you_ aren't using JSX (or .jsx) directly, if your dependencies
57
* define jsnext:main and have JSX internally, you may run into problems
68
* if you don't enable these settings at the top level.
79
*/
8-
module.exports = {
10+
export = {
911
settings: {
1012
'import-x/extensions': ['.js', '.jsx'],
1113
},
12-
1314
parserOptions: {
14-
ecmaFeatures: { jsx: true },
15+
ecmaFeatures: {
16+
jsx: true,
17+
},
1518
},
16-
}
19+
} satisfies PluginConfig

config/recommended.js renamed to src/config/recommended.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* The basics.
3-
* @type {Object}
45
*/
5-
module.exports = {
6+
export = {
67
plugins: ['import-x'],
78

89
rules: {
@@ -25,4 +26,4 @@ module.exports = {
2526
sourceType: 'module',
2627
ecmaVersion: 2018,
2728
},
28-
}
29+
} satisfies PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* Rules in progress.
35
*
46
* Do not expect these to adhere to semver across releases.
5-
* @type {Object}
67
*/
7-
module.exports = {
8+
export = {
89
plugins: ['import-x'],
910
rules: {
1011
'import-x/no-deprecated': 1,
1112
},
12-
}
13+
} as PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* This config:
35
* 1) adds `.jsx`, `.ts`, `.cts`, `.mts`, and `.tsx` as an extension
@@ -7,28 +9,27 @@
79
// Omit `.d.ts` because 1) TypeScript compilation already confirms that
810
// types are resolved, and 2) it would mask an unresolved
911
// `.ts`/`.tsx`/`.js`/`.jsx` implementation.
10-
const typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx']
12+
const typeScriptExtensions = ['.ts', '.tsx'] as const
1113

12-
const allExtensions = [...typeScriptExtensions, '.js', '.jsx']
14+
const allExtensions = [...typeScriptExtensions, '.js', '.jsx'] as const
1315

14-
module.exports = {
16+
export = {
1517
settings: {
1618
'import-x/extensions': allExtensions,
1719
'import-x/external-module-folders': ['node_modules', 'node_modules/@types'],
1820
'import-x/parsers': {
19-
'@typescript-eslint/parser': typeScriptExtensions,
21+
'@typescript-eslint/parser': [...typeScriptExtensions, '.cts', '.mts'],
2022
},
2123
'import-x/resolver': {
2224
node: {
2325
extensions: allExtensions,
2426
},
2527
},
2628
},
27-
2829
rules: {
2930
// analysis/correctness
3031

3132
// TypeScript compilation already ensures that named imports exist in the referenced module
3233
'import-x/named': 'off',
3334
},
34-
}
35+
} satisfies PluginConfig
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import type { PluginConfig } from '../types'
2+
13
/**
24
* more opinionated config.
3-
* @type {Object}
45
*/
5-
module.exports = {
6+
export = {
67
plugins: ['import-x'],
78
rules: {
89
'import-x/no-named-as-default': 1,
910
'import-x/no-named-as-default-member': 1,
1011
'import-x/no-duplicates': 1,
1112
},
12-
}
13+
} satisfies PluginConfig

0 commit comments

Comments
 (0)