From fc7c92d2c6f7842cc9b754a73131d37c6d10c574 Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Mon, 22 Jul 2024 23:02:38 +0200 Subject: [PATCH] feat: refactor eslint.config - specify exact file mask for every shared config - dry the last vue config with the normal config --- cfg/eslint.config.js | 46 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/cfg/eslint.config.js b/cfg/eslint.config.js index 8b12f29..3b215b6 100644 --- a/cfg/eslint.config.js +++ b/cfg/eslint.config.js @@ -12,31 +12,37 @@ const tseslint = require('typescript-eslint') const hasJest = require('node:fs').existsSync('./node_modules/jest') // console.log({ hasJest }) +const defaultFiles = ['**/*.ts', '**/*.tsx'] + module.exports = [ - eslint.configs.recommended, + { + ...eslint.configs.recommended, + files: defaultFiles, + }, // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts - ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.recommendedTypeChecked.map(c => ({ + ...c, + files: defaultFiles, + })), // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts - ...tseslint.configs.stylisticTypeChecked, + ...tseslint.configs.stylisticTypeChecked.map(c => ({ + ...c, + files: defaultFiles, + })), // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/configs/recommended.js - require('eslint-plugin-unicorn').configs['flat/recommended'], - // https://eslint.vuejs.org/user-guide/#user-guide - ...require('eslint-plugin-vue').configs['flat/recommended'], { - files: ['**/*.ts', '**/*.tsx'], - ...getConfig(), + ...require('eslint-plugin-unicorn').configs['flat/recommended'], + files: defaultFiles, }, + // https://eslint.vuejs.org/user-guide/#user-guide + // ...require('eslint-plugin-vue').configs['flat/recommended'], + ...require('eslint-plugin-vue').configs['flat/recommended'].map(c => ({ + ...c, + files: defaultFiles, + })), { - files: ['*.vue', '**/*.vue'], - languageOptions: { - parserOptions: { - project: 'tsconfig.json', - parser: tseslint.parser, - extraFileExtensions: ['.vue', '.html'], - }, - }, - plugins: getConfig().plugins, - rules: getConfig().rules, + files: defaultFiles, + ...getConfig(), }, { ignores: ['**/__exclude/**', '**/*.scss', '**/*.js'], @@ -63,10 +69,10 @@ function getConfig() { // testcafe fixture: 'readonly', }, - parser: tseslint.parser, + // parser: tseslint.parser, parserOptions: { project: 'tsconfig.json', - ecmaVersion: 'latest', + parser: tseslint.parser, extraFileExtensions: ['.vue', '.html'], }, },