Skip to content

Commit 3b43470

Browse files
committed
Migrate to TypeScript
1 parent 265b9cf commit 3b43470

Some content is hidden

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

45 files changed

+1454
-975
lines changed

.eslintrc.yml

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,62 @@ extends:
22
- plugin:@eslint-community/mysticatea/es2015
33
- plugin:@eslint-community/mysticatea/+eslint-plugin
44

5+
rules:
6+
"@eslint-community/mysticatea/node/file-extension-in-import":
7+
- error
8+
- always
9+
- ".ts": "always"
10+
"@eslint-community/mysticatea/ts/naming-convention":
11+
- off
12+
"@eslint-community/mysticatea/ts/prefer-readonly-parameter-types":
13+
- off
14+
"@eslint-community/mysticatea/ts/no-unsafe-member-access":
15+
- off
16+
"@eslint-community/mysticatea/ts/no-var-requires":
17+
- off
18+
"@eslint-community/mysticatea/ts/no-require-imports":
19+
- off
20+
"@eslint-community/mysticatea/ts/no-unsafe-assignment":
21+
- off
22+
"@eslint-community/mysticatea/ts/no-unsafe-call":
23+
- off
24+
"@eslint-community/mysticatea/ts/no-unsafe-argument":
25+
- off
26+
"@eslint-community/mysticatea/ts/no-unsafe-return":
27+
- off
28+
"@eslint-community/mysticatea/ts/ban-ts-comment":
29+
- off
30+
"@eslint-community/mysticatea/ts/no-non-null-asserted-optional-chain":
31+
- off
32+
"@eslint-community/mysticatea/ts/prefer-optional-chain":
33+
- off
34+
"@eslint-community/mysticatea/ts/prefer-nullish-coalescing":
35+
- off
36+
"@eslint-community/mysticatea/ts/no-floating-promises":
37+
- off
38+
"@eslint-community/mysticatea/ts/no-unnecessary-type-assertion":
39+
- off
40+
"no-shadow":
41+
- off
42+
"@eslint-community/mysticatea/node/no-missing-import": off
43+
"@eslint-community/mysticatea/node/no-unpublished-import": off
44+
545
overrides:
646
- files: "docs/.vuepress/components/*.vue"
747
parserOptions:
848
parser: "@babel/eslint-parser"
949

10-
- files: "lib/rules/*.js"
50+
- files: "lib/rules/*.ts"
1151
rules:
1252
"@eslint-community/mysticatea/eslint-plugin/require-meta-docs-url":
1353
- error
1454
- pattern: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/{{name}}.html"
1555

16-
- files: ["lib/configs.js", "lib/rules.js", "lib/utils.js"]
56+
- files: ["lib/configs.ts", "lib/rules.ts", "lib/utils.ts"]
1757
rules:
1858
"@eslint-community/mysticatea/node/global-require": off
1959

20-
- files: ["tests/**/*.js", "scripts/**/*.js"]
60+
- files: ["tests/**/*.ts", "scripts/**/*.ts"]
2161
rules:
2262
"@eslint-community/mysticatea/node/global-require": off
2363
"@eslint-community/mysticatea/node/no-sync": off

.github/workflows/ci.yml

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: ⎔ Setup Node
3535
uses: actions/setup-node@v4
3636
with:
37-
node-version: 18
37+
node-version: 22
3838

3939
- name: 📥 Install dependencies
4040
run: npm install
@@ -43,33 +43,32 @@ jobs:
4343
run: npm run lint
4444

4545
test:
46-
name:
47-
🧪 Test (Node@${{ matrix.node }} - ESLint@${{ matrix.eslint }} - ${{
46+
name: 🧪 Test (Node@${{ matrix.node }} - ESLint@${{ matrix.eslint }} - ${{
4847
matrix.os }})
4948
strategy:
5049
fail-fast: false
5150
matrix:
5251
eslint: [8]
53-
node: [12.22.0, 12, 14.17.0, 14, 16.0.0, 16, 18.0.0, 18, 20, 22, 24]
52+
node: [22, 24]
5453
os: [ubuntu-latest]
5554
include:
5655
# On other platforms
5756
- os: windows-latest
5857
eslint: 8
59-
node: 18
58+
node: 22
6059
- os: macos-latest
6160
eslint: 8
62-
node: 18
61+
node: 22
6362
# On ESLint 9
6463
- eslint: 9
65-
node: 18
64+
node: 22
6665
os: ubuntu-latest
6766
# On old ESLint versions
6867
- eslint: 7
69-
node: 18
68+
node: 22
7069
os: ubuntu-latest
7170
- eslint: 6
72-
node: 18
71+
node: 22
7372
os: ubuntu-latest
7473
# On the minimum supported ESLint/Node.js version
7574
- eslint: 6.0.0
@@ -84,25 +83,94 @@ jobs:
8483
uses: actions/setup-node@v4
8584
with:
8685
node-version: ${{ matrix.node }}
86+
check-latest: true
8787

8888
- name: 📥 Install dependencies
8989
run: npm install --legacy-peer-deps
9090

91+
- name: 📥 Build
92+
run: npm run build
93+
9194
- name: 📥 Install ESLint v${{ matrix.eslint }}
9295
run: npm install --save-dev eslint@${{ matrix.eslint }}
9396

9497
- name: ▶️ Run test script
98+
env:
99+
NODE_OPTIONS: --experimental-transform-types
95100
run: npm run test
96101

97102
- name: ⬆️ Upload coverage report
98103
uses: codecov/codecov-action@v4
99104

105+
are-the-types-wrong:
106+
name: 🤔 Are the types wrong?
107+
runs-on: ubuntu-latest
108+
steps:
109+
- name: ⬇️ Checkout repo
110+
uses: actions/checkout@v4
111+
112+
- name: ⎔ Setup Node
113+
uses: actions/setup-node@v4
114+
with:
115+
node-version: 22
116+
117+
- name: 📥 Install dependencies
118+
run: npm install --legacy-peer-deps
119+
120+
- name: ▶️ Run check-exports script
121+
run: npm run check-exports
122+
123+
- name: ▶️ Run typecheck script
124+
run: npm run typecheck
125+
126+
type-tests:
127+
name: 🧪 Type tests with ESLint ${{ matrix.eslint }} and TypeScript ${{ matrix.ts }}
128+
runs-on: ubuntu-latest
129+
130+
strategy:
131+
fail-fast: false
132+
133+
matrix:
134+
eslint: [8, 9]
135+
ts: ["5.7", "5.8", "5.9"]
136+
137+
steps:
138+
- name: ⬇️ Checkout repo
139+
uses: actions/checkout@v4
140+
141+
- name: ⎔ Setup Node
142+
uses: actions/setup-node@v4
143+
with:
144+
node-version: 22
145+
146+
- name: 📥 Install dependencies
147+
run: npm install
148+
149+
- name: Pack the package
150+
id: pack
151+
run: npm install "$(npm pack | tail -n1)"
152+
153+
- name: 📥 Uninstall @types/eslint
154+
if: matrix.eslint != 8
155+
run: npm uninstall @types/eslint
156+
157+
- name: 📥 Install ESLint version ${{ matrix.eslint }}
158+
run: npm install --save-dev eslint@${{ matrix.eslint }}
159+
160+
- name: 📥 Install TypeScript version ${{ matrix.ts }}
161+
run: npm install --save-dev typescript@${{ matrix.ts }} -f
162+
163+
- name: ▶️ Run typecheck script
164+
run: npm run typecheck
165+
166+
- name: 📝 List version of ESLint
167+
run: npm why eslint @types/eslint
168+
100169
release:
101170
name: 🚀 Release
102-
needs: [ lint, test ]
171+
needs: [lint, test]
103172
runs-on: ubuntu-latest
104-
if:
105-
github.repository == 'eslint-community/eslint-plugin-eslint-comments' &&
173+
if: github.repository == 'eslint-community/eslint-plugin-eslint-comments' &&
106174
contains('refs/heads/main,refs/heads/next,refs/heads/beta,refs/heads/alpha',
107175
github.ref) && github.event_name == 'push'
108176
steps:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
/node_modules
77
/npm-debug.log
88
/test.js
9+
dist/
10+
.rolldown/

configs.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
"use strict"
2-
3-
const { rules: rulesRecommended } = require("./lib/configs/recommended")
4-
const rules = require("./lib/rules")
5-
const { name, version } = require("./package.json")
1+
import type { ESLint, Linter } from "eslint"
2+
import { rulesRecommended } from "./lib/configs/recommended.ts"
3+
import { rules } from "./lib/rules.ts"
4+
import packageJson from "./package.json" with { type: "json" }
65

76
const plugin = {
8-
meta: { name, version },
7+
meta: {
8+
name: packageJson.name,
9+
version: packageJson.version,
10+
},
911
rules,
10-
}
12+
} as const satisfies ESLint.Plugin
1113

12-
module.exports = {
13-
recommended: {
14-
name: '@eslint-community/eslint-comments/recommended',
15-
plugins: {
16-
"@eslint-community/eslint-comments": plugin,
17-
},
18-
rules: rulesRecommended,
14+
export const recommended = {
15+
name: "@eslint-community/eslint-comments/recommended",
16+
plugins: {
17+
"@eslint-community/eslint-comments": plugin,
1918
},
20-
}
21-
22-
module.exports.default = module.exports
19+
rules: rulesRecommended,
20+
} as const satisfies Linter.FlatConfig

index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
/** DON'T EDIT THIS FILE WHICH WAS CREATED BY 'scripts/generate-index.js'. */
2-
"use strict"
3-
4-
module.exports = {
5-
configs: require("./lib/configs"),
6-
rules: require("./lib/rules"),
7-
utils: require("./lib/utils"),
8-
}
1+
export * as configs from "./lib/configs.ts"
2+
export { rules } from "./lib/rules.ts"
3+
export * as utils from "./lib/utils.ts"

lib/configs.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
/** DON'T EDIT THIS FILE; was created by scripts. */
2-
"use strict"
3-
4-
module.exports = {
5-
recommended: require("./configs/recommended"),
6-
}
1+
export * as recommended from "./configs/recommended.ts"

lib/configs/recommended.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/** DON'T EDIT THIS FILE; was created by scripts. */
2-
"use strict"
1+
import type { Linter } from "eslint"
32

4-
module.exports = {
5-
plugins: ["@eslint-community/eslint-comments"],
6-
rules: {
7-
"@eslint-community/eslint-comments/disable-enable-pair": "error",
8-
"@eslint-community/eslint-comments/no-aggregating-enable": "error",
9-
"@eslint-community/eslint-comments/no-duplicate-disable": "error",
10-
"@eslint-community/eslint-comments/no-unlimited-disable": "error",
11-
"@eslint-community/eslint-comments/no-unused-enable": "error",
12-
},
13-
}
3+
export const plugins = [
4+
"@eslint-community/eslint-comments",
5+
] as const satisfies Linter.LegacyConfig["plugins"]
6+
7+
export const rulesRecommended = {
8+
"@eslint-community/eslint-comments/disable-enable-pair": "error",
9+
"@eslint-community/eslint-comments/no-aggregating-enable": "error",
10+
"@eslint-community/eslint-comments/no-duplicate-disable": "error",
11+
"@eslint-community/eslint-comments/no-unlimited-disable": "error",
12+
"@eslint-community/eslint-comments/no-unused-enable": "error",
13+
} as const satisfies Linter.Config["rules"]

0 commit comments

Comments
 (0)