From 2459d41d4369176c4090f7da75ba68f27c4be9a2 Mon Sep 17 00:00:00 2001 From: "Marcus R. Brown" Date: Sun, 8 Sep 2024 23:47:29 -0700 Subject: [PATCH] chore(eslint): add `eslint-typegen` (#414) --- .gitignore | 3 + eslint.config.ts | 148 +++++++++++++++++++++++------------------------ package.json | 3 +- pnpm-lock.yaml | 58 ++++++++++++++----- tsconfig.json | 4 +- 5 files changed, 122 insertions(+), 94 deletions(-) diff --git a/.gitignore b/.gitignore index 4ecb7a9d..4617132f 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,6 @@ Thumbs.db # Ignore built ts files __tests__/runner/* lib/**/* + +# eslint-typegen (https://github.com/antfu/eslint-typegen) +eslint-typegen.d.ts diff --git a/eslint.config.ts b/eslint.config.ts index 522a0c0d..ca237363 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -2,88 +2,88 @@ import eslint from '@eslint/js' import type {Linter} from 'eslint' import globals from 'globals' import tseslint from 'typescript-eslint' +import typegen from 'eslint-typegen' -/// -/// - -export default tseslint.config( - eslint.configs.recommended, - ...tseslint.configs.recommendedTypeChecked, - { - ignores: ['**/__tests__', '**/dist', '**/lib', '**/node_modules'], - }, - - { - languageOptions: { - ecmaVersion: 2022, - globals: { - ...globals.es2021, - ...globals.node, - }, +export default typegen( + tseslint.config( + eslint.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, + { + ignores: ['**/__tests__', '**/dist', '**/lib', '**/node_modules'], + }, - parserOptions: { + { + languageOptions: { ecmaVersion: 2022, - projectService: true, + globals: { + ...globals.es2021, + ...globals.node, + }, + + parserOptions: { + ecmaVersion: 2022, + projectService: true, + sourceType: 'module', + }, sourceType: 'module', }, - sourceType: 'module', - }, - rules: { - 'i18n-text/no-en': 'off', - 'eslint-comments/no-use': 'off', - 'import/no-namespace': 'off', - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'error', + rules: { + 'i18n-text/no-en': 'off', + 'eslint-comments/no-use': 'off', + 'import/no-namespace': 'off', + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': 'error', - '@typescript-eslint/explicit-member-accessibility': [ - 'error', - { - accessibility: 'no-public', - }, - ], + '@typescript-eslint/explicit-member-accessibility': [ + 'error', + { + accessibility: 'no-public', + }, + ], - '@typescript-eslint/no-require-imports': 'error', - '@typescript-eslint/array-type': 'error', - '@typescript-eslint/await-thenable': 'error', - '@typescript-eslint/ban-ts-comment': 'error', - camelcase: 'off', - '@typescript-eslint/consistent-type-assertions': 'error', + '@typescript-eslint/no-require-imports': 'error', + '@typescript-eslint/array-type': 'error', + '@typescript-eslint/await-thenable': 'error', + '@typescript-eslint/ban-ts-comment': 'error', + camelcase: 'off', + '@typescript-eslint/consistent-type-assertions': 'error', - '@typescript-eslint/explicit-function-return-type': [ - 'error', - { - allowExpressions: true, - }, - ], + '@typescript-eslint/explicit-function-return-type': [ + 'error', + { + allowExpressions: true, + }, + ], - // Moved to https://eslint.style - https://github.com/typescript-eslint/typescript-eslint/issues/8074 - // '@typescript-eslint/func-call-spacing': ['error', 'never'], - '@typescript-eslint/no-array-constructor': 'error', - '@typescript-eslint/no-empty-interface': 'error', - '@typescript-eslint/no-explicit-any': 'error', - '@typescript-eslint/no-extraneous-class': 'error', - '@typescript-eslint/no-for-in-array': 'error', - '@typescript-eslint/no-inferrable-types': 'error', - '@typescript-eslint/no-misused-new': 'error', - '@typescript-eslint/no-namespace': 'error', - '@typescript-eslint/no-non-null-assertion': 'warn', - '@typescript-eslint/no-unnecessary-qualifier': 'error', - '@typescript-eslint/no-unnecessary-type-assertion': 'error', - '@typescript-eslint/no-useless-constructor': 'error', - '@typescript-eslint/no-var-requires': 'error', - '@typescript-eslint/prefer-for-of': 'warn', - '@typescript-eslint/prefer-function-type': 'warn', - '@typescript-eslint/prefer-includes': 'error', - '@typescript-eslint/prefer-string-starts-ends-with': 'error', - '@typescript-eslint/promise-function-async': 'error', - '@typescript-eslint/require-array-sort-compare': 'error', - '@typescript-eslint/restrict-plus-operands': 'error', - semi: 'off', - // Moved to https://eslint.style - https://github.com/typescript-eslint/typescript-eslint/issues/8074 - // '@typescript-eslint/semi': ['error', 'never'], - // '@typescript-eslint/type-annotation-spacing': 'error', - '@typescript-eslint/unbound-method': 'error', + // Moved to https://eslint.style - https://github.com/typescript-eslint/typescript-eslint/issues/8074 + // '@typescript-eslint/func-call-spacing': ['error', 'never'], + '@typescript-eslint/no-array-constructor': 'error', + '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-extraneous-class': 'error', + '@typescript-eslint/no-for-in-array': 'error', + '@typescript-eslint/no-inferrable-types': 'error', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-namespace': 'error', + '@typescript-eslint/no-non-null-assertion': 'warn', + '@typescript-eslint/no-unnecessary-qualifier': 'error', + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + '@typescript-eslint/no-useless-constructor': 'error', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/prefer-for-of': 'warn', + '@typescript-eslint/prefer-function-type': 'warn', + '@typescript-eslint/prefer-includes': 'error', + '@typescript-eslint/prefer-string-starts-ends-with': 'error', + '@typescript-eslint/promise-function-async': 'error', + '@typescript-eslint/require-array-sort-compare': 'error', + '@typescript-eslint/restrict-plus-operands': 'error', + semi: 'off', + // Moved to https://eslint.style - https://github.com/typescript-eslint/typescript-eslint/issues/8074 + // '@typescript-eslint/semi': ['error', 'never'], + // '@typescript-eslint/type-annotation-spacing': 'error', + '@typescript-eslint/unbound-method': 'error', + }, }, - }, -) as Linter.Config + ) as Linter.Config[], +) diff --git a/package.json b/package.json index 7e8d01cf..ddd2e6c5 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,6 @@ "devDependencies": { "@bfra.me/prettier-config": "0.5.0", "@bfra.me/tsconfig": "0.6.0", - "@eslint-types/import": "2.29.1", - "@eslint-types/typescript-eslint": "7.5.0", "@eslint/js": "9.10.0", "@semantic-release/git": "10.0.1", "@types/eslint__js": "8.42.3", @@ -43,6 +41,7 @@ "@vercel/ncc": "0.38.1", "conventional-changelog-conventionalcommits": "8.0.0", "eslint": "9.10.0", + "eslint-typegen": "0.3.2", "globals": "15.9.0", "jiti": "1.21.6", "js-yaml": "4.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67973108..d9cd2393 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,12 +18,6 @@ importers: '@bfra.me/tsconfig': specifier: 0.6.0 version: 0.6.0 - '@eslint-types/import': - specifier: 2.29.1 - version: 2.29.1 - '@eslint-types/typescript-eslint': - specifier: 7.5.0 - version: 7.5.0 '@eslint/js': specifier: 9.10.0 version: 9.10.0 @@ -45,6 +39,9 @@ importers: eslint: specifier: 9.10.0 version: 9.10.0(jiti@1.21.6) + eslint-typegen: + specifier: 0.3.2 + version: 0.3.2(eslint@9.10.0(jiti@1.21.6)) globals: specifier: 15.9.0 version: 15.9.0 @@ -82,6 +79,10 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} + '@apidevtools/json-schema-ref-parser@11.7.0': + resolution: {integrity: sha512-pRrmXMCwnmrkS3MLgAIW5dXRzeTv6GLjkjb4HmxNnvAKXN1Nfzp4KmGADBQvlVUcqi+a5D+hfGDLLnd5NnYxog==} + engines: {node: '>= 16'} + '@babel/code-frame@7.24.7': resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} engines: {node: '>=6.9.0'} @@ -259,12 +260,6 @@ packages: resolution: {integrity: sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==} engines: {node: ^12.0.0 || ^14.0.0 || >=16.0.0} - '@eslint-types/import@2.29.1': - resolution: {integrity: sha512-22yG9mnWk/mC6rQwtgzEbE/in7H7eA36v1eBVrVdYDeapylP/N0Qw0WPq83YSlQ1kM0B72az9FCZvlMfmwQ+YA==} - - '@eslint-types/typescript-eslint@7.5.0': - resolution: {integrity: sha512-zKvsPBDq6o0L4p2sRtq8fxOtGc+mm37aZSXLsiD4DIRl2kYUxKNO9CKDTAgmuMYUzih9J7lbLxAomreLrdAiVQ==} - '@eslint/config-array@0.18.0': resolution: {integrity: sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -315,6 +310,9 @@ packages: '@jridgewell/trace-mapping@0.3.25': resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==} + '@jsdevtools/ono@7.1.3': + resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -908,6 +906,11 @@ packages: resolution: {integrity: sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + eslint-typegen@0.3.2: + resolution: {integrity: sha512-YD/flDDDYoBszomo6wVAJ01HcEWTLfOb04+Mwir8/oR66t2bnajw+qUI6JfBoBQO3HbebcCmEtgjKgWVB67ggQ==} + peerDependencies: + eslint: ^8.45.0 || ^9.0.0 + eslint-visitor-keys@3.4.3: resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1264,6 +1267,9 @@ packages: json-parse-even-better-errors@2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} + json-schema-to-typescript-lite@14.1.0: + resolution: {integrity: sha512-b8K6P3aiLgiYKYcHacgZKrwPXPyjekqRPV5vkNfBt0EoohcOSXEbcuGzgi6KQmsAhuy5Mh2KMxofXodRhMxURA==} + json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==} @@ -1495,6 +1501,9 @@ packages: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} engines: {node: '>=0.10.0'} + ohash@1.1.3: + resolution: {integrity: sha512-zuHHiGTYTA1sYJ/wZN+t5HKZaH23i4yI1HMwbuXm24Nid7Dv0KcuRlKoNKS9UNfAVSBlnGLcuQrnOKWOZoEGaw==} + onetime@5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} engines: {node: '>=6'} @@ -2114,6 +2123,12 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 + '@apidevtools/json-schema-ref-parser@11.7.0': + dependencies: + '@jsdevtools/ono': 7.1.3 + '@types/json-schema': 7.0.15 + js-yaml: 4.1.0 + '@babel/code-frame@7.24.7': dependencies: '@babel/highlight': 7.24.7 @@ -2221,10 +2236,6 @@ snapshots: '@eslint-community/regexpp@4.11.0': {} - '@eslint-types/import@2.29.1': {} - - '@eslint-types/typescript-eslint@7.5.0': {} - '@eslint/config-array@0.18.0': dependencies: '@eslint/object-schema': 2.1.4 @@ -2278,6 +2289,8 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 + '@jsdevtools/ono@7.1.3': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -2927,6 +2940,12 @@ snapshots: esrecurse: 4.3.0 estraverse: 5.3.0 + eslint-typegen@0.3.2(eslint@9.10.0(jiti@1.21.6)): + dependencies: + eslint: 9.10.0(jiti@1.21.6) + json-schema-to-typescript-lite: 14.1.0 + ohash: 1.1.3 + eslint-visitor-keys@3.4.3: {} eslint-visitor-keys@4.0.0: {} @@ -3297,6 +3316,11 @@ snapshots: json-parse-even-better-errors@2.3.1: {} + json-schema-to-typescript-lite@14.1.0: + dependencies: + '@apidevtools/json-schema-ref-parser': 11.7.0 + '@types/json-schema': 7.0.15 + json-schema-traverse@0.4.1: {} json-stable-stringify-without-jsonify@1.0.1: {} @@ -3442,6 +3466,8 @@ snapshots: object-assign@4.1.1: {} + ohash@1.1.3: {} + onetime@5.1.2: dependencies: mimic-fn: 2.1.0 diff --git a/tsconfig.json b/tsconfig.json index ef3c7d8e..2a3f4e46 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,6 @@ "noEmit": true, "target": "ESNext" }, - "exclude": ["dist", "node_modules", "**/*.test.ts"], - "include": ["src", "eslint.config.ts"] + "exclude": ["dist", "node_modules"], + "include": ["**/*.ts"] }