From d414c99b6e325a2be1073f63cb5836f51f6cb853 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 15 Oct 2024 15:54:23 +0800 Subject: [PATCH] fix: if no matching files found, skip setting the corresponding config ESLint config's schema requires the `files` key to be a non-empty array Fixes https://github.com/neanes/neanes/pull/1030#pullrequestreview-2367528558 --- src/index.ts | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 812037d..c8d887e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,7 +51,10 @@ export default function createConfig({ files: ['**/*.js', '**/*.jsx'], ...tseslint.configs.disableTypeChecked, }, - { + ] + + if (otherVueFiles.length > 0) { + projectServiceConfigs.push({ name: 'vue-typescript/skip-type-checking-for-vue-files-without-ts', files: otherVueFiles, ...tseslint.configs.disableTypeChecked, @@ -63,9 +66,9 @@ export default function createConfig({ // https://github.com/typescript-eslint/typescript-eslint/issues/4755#issuecomment-1080961338 '@typescript-eslint/consistent-type-imports': 'off', '@typescript-eslint/prefer-optional-chain': 'off', - } - }, - ] + }, + }) + } const mayHaveJsxInSfc = supportedScriptLangs.jsx || supportedScriptLangs.tsx const needsTypeAwareLinting = configNamesToExtend.some( @@ -87,18 +90,20 @@ export default function createConfig({ }, }) - projectServiceConfigs.push({ - name: 'vue-typescript/default-project-service-for-vue-files', - files: vueFilesWithScriptTs, - languageOptions: { - parser: vueParser, - parserOptions: { - projectService: true, - parser: tseslint.parser, - extraFileExtensions, + if (vueFilesWithScriptTs.length > 0) { + projectServiceConfigs.push({ + name: 'vue-typescript/default-project-service-for-vue-files', + files: vueFilesWithScriptTs, + languageOptions: { + parser: vueParser, + parserOptions: { + projectService: true, + parser: tseslint.parser, + extraFileExtensions, + }, }, - }, - }) + }) + } // Vue's own typing inevitably contains some `any`s, so some of the `no-unsafe-*` rules can't be used. projectServiceConfigs.push({