diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index fdf15bf..bb636a4 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,56 +1,56 @@ import { GLOB_JS, GLOB_TS, GLOB_TSX } from '../globs' import { tseslint } from '../plugins' import { restrictedSyntaxJs } from './javascript' -import type { FlatESLintConfigItem, Rules } from 'eslint-define-config' +import type { FlatESLintConfigItem } from 'eslint-define-config' -export const typescriptRules: Rules = { - '@typescript-eslint/ban-ts-comment': 'off', - '@typescript-eslint/ban-types': 'off', - '@typescript-eslint/consistent-type-assertions': [ - 'error', - { - assertionStyle: 'as', - objectLiteralTypeAssertions: 'allow-as-parameter', +export const typescriptCore = tseslint.config({ + extends: [...tseslint.configs.recommended], + files: [GLOB_TS, GLOB_TSX], + languageOptions: { + parser: tseslint.parser, + parserOptions: { + sourceType: 'module', }, - ], - '@typescript-eslint/consistent-type-imports': [ - 'error', - { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, - ], - '@typescript-eslint/method-signature-style': ['error', 'property'], // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-import-type-side-effects': 'error', - '@typescript-eslint/no-non-null-assertion': 'off', - '@typescript-eslint/no-redeclare': 'error', + }, + rules: { + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/consistent-type-assertions': [ + 'error', + { + assertionStyle: 'as', + objectLiteralTypeAssertions: 'allow-as-parameter', + }, + ], + '@typescript-eslint/consistent-type-imports': [ + 'error', + { disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }, + ], + '@typescript-eslint/method-signature-style': ['error', 'property'], // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-import-type-side-effects': 'error', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-redeclare': 'error', - // handled by unused-imports/no-unused-imports - '@typescript-eslint/no-unused-vars': 'off', + // handled by unused-imports/no-unused-imports + '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/prefer-as-const': 'warn', - '@typescript-eslint/prefer-literal-enum-member': [ - 'error', - { allowBitwiseExpressions: true }, - ], + '@typescript-eslint/prefer-as-const': 'warn', + '@typescript-eslint/prefer-literal-enum-member': [ + 'error', + { allowBitwiseExpressions: true }, + ], - 'no-restricted-syntax': [ - 'error', - ...restrictedSyntaxJs, - 'TSEnumDeclaration[const=true]', - ], -} + 'no-restricted-syntax': [ + 'error', + ...restrictedSyntaxJs, + 'TSEnumDeclaration[const=true]', + ], + }, +}) as FlatESLintConfigItem[] export const typescript: FlatESLintConfigItem[] = [ - ...(tseslint.config({ - extends: [...tseslint.configs.recommended], - files: [GLOB_TS, GLOB_TSX], - languageOptions: { - parser: tseslint.parser, - parserOptions: { - sourceType: 'module', - }, - }, - rules: typescriptRules, - }) as FlatESLintConfigItem[]), + ...typescriptCore, { files: ['**/*.d.ts'], diff --git a/src/configs/vue.ts b/src/configs/vue.ts index 8d85842..1c831fd 100644 --- a/src/configs/vue.ts +++ b/src/configs/vue.ts @@ -2,7 +2,7 @@ import process from 'node:process' import { getPackageInfoSync } from 'local-pkg' import { GLOB_VUE } from '../globs' import { parserVue, pluginVue, tseslint } from '../plugins' -import { typescriptRules } from './typescript' +import { typescriptCore } from './typescript' import type { FlatESLintConfigItem, Rules } from 'eslint-define-config' export function getVueVersion() { @@ -96,6 +96,10 @@ const vue2Rules: Rules = { } export const vue: FlatESLintConfigItem[] = [ + ...(tseslint.config({ + extends: typescriptCore as any[], + files: [GLOB_VUE], + }) as any), { files: [GLOB_VUE], languageOptions: { @@ -115,7 +119,6 @@ export const vue: FlatESLintConfigItem[] = [ }, processor: pluginVue.processors['.vue'], rules: { - ...typescriptRules, ...(isVue3 ? vue3Rules : vue2Rules), ...vueCustomRules, },