From da30fce3267056c5e212eee0a9fb35b0e6f8dd06 Mon Sep 17 00:00:00 2001 From: mouse_484 <38714187+mouse484@users.noreply.github.com> Date: Sat, 22 Jun 2024 04:06:15 +0000 Subject: [PATCH 1/4] chore: update action node version --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 485fe6e..db03c4c 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x, 22.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: From 29acfae4cff1a05a866858abc3e22b4c509848ec Mon Sep 17 00:00:00 2001 From: mouse_484 <38714187+mouse484@users.noreply.github.com> Date: Sat, 22 Jun 2024 04:49:32 +0000 Subject: [PATCH 2/4] chore: ni --- .gitpod.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitpod.yml b/.gitpod.yml index a52c477..614b531 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,5 +1,5 @@ tasks: - - init: npm install + - init: npm i -g @antfu/ni && ni vscode: extensions: From fbd8721b746f736433b9033b8be173670561e482 Mon Sep 17 00:00:00 2001 From: mouse_484 <38714187+mouse484@users.noreply.github.com> Date: Sat, 22 Jun 2024 05:26:57 +0000 Subject: [PATCH 3/4] feat(eslint): max-len --- package-lock.json | 1 + package.json | 3 ++- packages/eslint/src/index.js | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80192c9..9a6b680 100644 --- a/package-lock.json +++ b/package-lock.json @@ -119,6 +119,7 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", + "extraneous": true, "inBundle": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index 092143d..036b075 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ ], "scripts": { "lint": "eslint .", - "lint:fix": "eslint --fix ." + "lint:fix": "eslint --fix .", + "lint:view": "npx @eslint/config-inspector" }, "devDependencies": { "@mouse_484/eslint-config": "*", diff --git a/packages/eslint/src/index.js b/packages/eslint/src/index.js index 6d917bf..21d11e7 100644 --- a/packages/eslint/src/index.js +++ b/packages/eslint/src/index.js @@ -1,4 +1,4 @@ -import antfu from '@antfu/eslint-config' +import antfu, { GLOB_SRC } from '@antfu/eslint-config' /** * @typedef {import('@antfu/eslint-config').OptionsConfig} OptionsConfig @@ -19,5 +19,20 @@ import antfu from '@antfu/eslint-config' * The merged ESLint configurations. */ export function mouse(options, ...userConfigs) { - return antfu(options, ...userConfigs) + /** @type {TypedFlatConfigItem[]} */ + const configs = [] + + configs.push({ + name: 'mouse/source-files', + files: [GLOB_SRC], + rules: { + 'style/max-len': ['error', { + code: 80, + tabWidth: 2, + comments: 120, + }], + }, + }) + + return antfu(options, ...configs, ...userConfigs) } From 5a696f2606a45a6b2c4f1451d0594cbd3db57d33 Mon Sep 17 00:00:00 2001 From: mouse_484 <38714187+mouse484@users.noreply.github.com> Date: Sat, 22 Jun 2024 06:29:12 +0000 Subject: [PATCH 4/4] feat: eslint typescript --- eslint.config.js | 2 +- package-lock.json | 260 ++++++++++++----------------------- packages/eslint/package.json | 3 + packages/eslint/src/index.js | 50 ++++++- 4 files changed, 138 insertions(+), 177 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 1b1d9bf..a48ea75 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,3 +1,3 @@ import { mouse } from '@mouse_484/eslint-config' -export default mouse() +export default mouse({}) diff --git a/package-lock.json b/package-lock.json index 9a6b680..a60fb9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -119,7 +119,6 @@ }, "node_modules/@clack/prompts/node_modules/is-unicode-supported": { "version": "1.3.0", - "extraneous": true, "inBundle": true, "license": "MIT", "engines": { @@ -14614,6 +14613,9 @@ "license": "MIT", "dependencies": { "@antfu/eslint-config": "^2.21.1" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^7.13.1" } }, "packages/eslint/node_modules/@antfu/eslint-config": { @@ -14721,112 +14723,6 @@ } } }, - "packages/eslint/node_modules/@antfu/eslint-config/node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.1.tgz", - "integrity": "sha512-kZqi+WZQaZfPKnsflLJQCz6Ze9FFSMfXrrIOcyargekQxG37ES7DJNpJUE9Q/X5n3yTIP/WPutVNzgknQ7biLg==", - "dependencies": { - "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/type-utils": "7.13.1", - "@typescript-eslint/utils": "7.13.1", - "@typescript-eslint/visitor-keys": "7.13.1", - "graphemer": "^1.4.0", - "ignore": "^5.3.1", - "natural-compare": "^1.4.0", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "packages/eslint/node_modules/@antfu/eslint-config/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/type-utils": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.13.1.tgz", - "integrity": "sha512-aWDbLu1s9bmgPGXSzNCxELu+0+HQOapV/y+60gPXafR8e2g1Bifxzevaa+4L2ytCWm+CHqpELq4CSoN9ELiwCg==", - "dependencies": { - "@typescript-eslint/typescript-estree": "7.13.1", - "@typescript-eslint/utils": "7.13.1", - "debug": "^4.3.4", - "ts-api-utils": "^1.3.0" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "packages/eslint/node_modules/@antfu/eslint-config/node_modules/@typescript-eslint/eslint-plugin/node_modules/@typescript-eslint/utils": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", - "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/types": "7.13.1", - "@typescript-eslint/typescript-estree": "7.13.1" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, - "packages/eslint/node_modules/@antfu/eslint-config/node_modules/@typescript-eslint/parser": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.13.1.tgz", - "integrity": "sha512-1ELDPlnLvDQ5ybTSrMhRTFDfOQEOXNM+eP+3HT/Yq7ruWpciQw+Avi73pdEbA4SooCawEWo3dtYbF68gN7Ed1A==", - "dependencies": { - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/types": "7.13.1", - "@typescript-eslint/typescript-estree": "7.13.1", - "@typescript-eslint/visitor-keys": "7.13.1", - "debug": "^4.3.4" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "packages/eslint/node_modules/@antfu/eslint-config/node_modules/eslint-plugin-unused-imports": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.2.0.tgz", @@ -14924,7 +14820,92 @@ "eslint": ">=8.40.0" } }, - "packages/eslint/node_modules/@stylistic/eslint-plugin-ts/node_modules/@typescript-eslint/utils": { + "packages/eslint/node_modules/@typescript-eslint/eslint-plugin": { + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.1.tgz", + "integrity": "sha512-kZqi+WZQaZfPKnsflLJQCz6Ze9FFSMfXrrIOcyargekQxG37ES7DJNpJUE9Q/X5n3yTIP/WPutVNzgknQ7biLg==", + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "7.13.1", + "@typescript-eslint/type-utils": "7.13.1", + "@typescript-eslint/utils": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^7.0.0", + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "packages/eslint/node_modules/@typescript-eslint/parser": { + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.13.1.tgz", + "integrity": "sha512-1ELDPlnLvDQ5ybTSrMhRTFDfOQEOXNM+eP+3HT/Yq7ruWpciQw+Avi73pdEbA4SooCawEWo3dtYbF68gN7Ed1A==", + "dependencies": { + "@typescript-eslint/scope-manager": "7.13.1", + "@typescript-eslint/types": "7.13.1", + "@typescript-eslint/typescript-estree": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "packages/eslint/node_modules/@typescript-eslint/type-utils": { + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.13.1.tgz", + "integrity": "sha512-aWDbLu1s9bmgPGXSzNCxELu+0+HQOapV/y+60gPXafR8e2g1Bifxzevaa+4L2ytCWm+CHqpELq4CSoN9ELiwCg==", + "dependencies": { + "@typescript-eslint/typescript-estree": "7.13.1", + "@typescript-eslint/utils": "7.13.1", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "packages/eslint/node_modules/@typescript-eslint/utils": { "version": "7.13.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", @@ -15131,27 +15112,6 @@ "eslint": "^8.56.0 || ^9.0.0-0" } }, - "packages/eslint/node_modules/eslint-plugin-import-x/node_modules/@typescript-eslint/utils": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", - "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/types": "7.13.1", - "@typescript-eslint/typescript-estree": "7.13.1" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, "packages/eslint/node_modules/eslint-plugin-import-x/node_modules/minimatch": { "version": "9.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", @@ -15331,27 +15291,6 @@ } } }, - "packages/eslint/node_modules/eslint-plugin-perfectionist/node_modules/@typescript-eslint/utils": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", - "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/types": "7.13.1", - "@typescript-eslint/typescript-estree": "7.13.1" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, "packages/eslint/node_modules/eslint-plugin-perfectionist/node_modules/minimatch": { "version": "9.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", @@ -15461,27 +15400,6 @@ } } }, - "packages/eslint/node_modules/eslint-plugin-vitest/node_modules/@typescript-eslint/utils": { - "version": "7.13.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", - "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.13.1", - "@typescript-eslint/types": "7.13.1", - "@typescript-eslint/typescript-estree": "7.13.1" - }, - "engines": { - "node": "^18.18.0 || >=20.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.56.0" - } - }, "packages/eslint/node_modules/eslint-plugin-vue": { "version": "9.26.0", "resolved": "https://registry.npmjs.org/eslint-plugin-vue/-/eslint-plugin-vue-9.26.0.tgz", diff --git a/packages/eslint/package.json b/packages/eslint/package.json index e506f01..8a95b61 100644 --- a/packages/eslint/package.json +++ b/packages/eslint/package.json @@ -18,5 +18,8 @@ "main": "src/index.js", "dependencies": { "@antfu/eslint-config": "^2.21.1" + }, + "devDependencies": { + "@typescript-eslint/eslint-plugin": "^7.13.1" } } diff --git a/packages/eslint/src/index.js b/packages/eslint/src/index.js index 21d11e7..6595837 100644 --- a/packages/eslint/src/index.js +++ b/packages/eslint/src/index.js @@ -1,10 +1,16 @@ -import antfu, { GLOB_SRC } from '@antfu/eslint-config' +// @ts-check +import antfu, { + GLOB_SRC, + GLOB_TS, + GLOB_TSX, + interopDefault, + renameRules, + resolveSubOptions, +} from '@antfu/eslint-config' /** * @typedef {import('@antfu/eslint-config').OptionsConfig} OptionsConfig * @typedef {import('@antfu/eslint-config').TypedFlatConfigItem} TypedFlatConfigItem - * @typedef {import('@antfu/eslint-config').Awaitable} Awaitable - * @typedef {import('@antfu/eslint-config').TypedFlatConfigItem} TypedFlatConfigItem */ /** @@ -13,12 +19,12 @@ import antfu, { GLOB_SRC } from '@antfu/eslint-config' * * @param {OptionsConfig & TypedFlatConfigItem} options * The options for generating the ESLint configurations. - * @param {Awaitable[]} userConfigs + * @param {import('@antfu/eslint-config').Awaitable[]} userConfigs * The user configurations to be merged with the generated configurations. * @returns {Promise} * The merged ESLint configurations. */ -export function mouse(options, ...userConfigs) { +export async function mouse(options, ...userConfigs) { /** @type {TypedFlatConfigItem[]} */ const configs = [] @@ -34,5 +40,39 @@ export function mouse(options, ...userConfigs) { }, }) + if (options?.typescript) { + const pluginTs = await interopDefault( + import('@typescript-eslint/eslint-plugin'), + ) + + /** + * @param {string} key + * @returns {import("eslint").Linter.RulesRecord} + * if tsconfigPath is defined, append '-type-checked' to the key + */ + const getRules = (key) => { + const typescriptOptions = resolveSubOptions(options, 'typescript') + const tsconfigPath = 'tsconfigPath' in typescriptOptions + ? typescriptOptions.tsconfigPath + : undefined + + return renameRules( + pluginTs.configs[ + tsconfigPath ? `${key}-type-checked` : key + ]?.rules ?? {}, + { '@typescript-eslint': 'ts' }, + ) + } + + configs.push({ + name: 'mouse/typescript', + files: [GLOB_TS, GLOB_TSX], + rules: { + ...getRules('strict'), + ...getRules('stylistic'), + }, + }) + } + return antfu(options, ...configs, ...userConfigs) }