From bc705da91d798535839b73fc8fa8165d292e07ea Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Fri, 20 Sep 2024 09:33:12 +0200 Subject: [PATCH] feat: eslint to include `*.html` files by default --- cfg/_cnst.js | 1 + cfg/biome.jsonc | 2 +- cfg/eslint.config.js | 2 +- cfg/lint-staged.config.js | 6 +++--- src/lint.util.ts | 23 +++++++++++++++-------- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/cfg/_cnst.js b/cfg/_cnst.js index 1f60d73..9962ff4 100644 --- a/cfg/_cnst.js +++ b/cfg/_cnst.js @@ -6,6 +6,7 @@ module.exports = { prettierExtensionsExclusive: 'js,jsx,json,md,graphql,yml,yaml,html', // everything that prettier supports: prettierExtensionsAll: 'ts,tsx,cts,mts,css,scss,js,jsx,cjs,mjs,json,md,graphql,yml,yaml,html,vue', + eslintExtensions: 'ts,tsx,cts,mts,vue,html', stylelintExtensions: 'css,scss', lintExclude: ['./**/__exclude/**', './**/dist/**', './**/cache/**', './CHANGELOG.md'], } diff --git a/cfg/biome.jsonc b/cfg/biome.jsonc index 1239501..b02be10 100644 --- a/cfg/biome.jsonc +++ b/cfg/biome.jsonc @@ -1,7 +1,7 @@ { "$schema": "https://biomejs.dev/schemas/1.9.2/schema.json", "files": { - "ignore": ["**/tsconfig.json", "**/tsconfig.*.json", "**/__exclude", "**/try.ts", "*.compact.json"] + "ignore": ["**/*.html", "**/tsconfig.json", "**/tsconfig.*.json", "**/__exclude", "**/try.ts", "*.compact.json"] }, "formatter": { "enabled": true, diff --git a/cfg/eslint.config.js b/cfg/eslint.config.js index a5ad277..3d9a757 100644 --- a/cfg/eslint.config.js +++ b/cfg/eslint.config.js @@ -12,7 +12,7 @@ const tseslint = require('typescript-eslint') const hasJest = require('node:fs').existsSync('./node_modules/jest') // console.log({ hasJest }) -const defaultFiles = ['**/*.ts', '**/*.tsx'] +const defaultFiles = ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'] module.exports = [ { diff --git a/cfg/lint-staged.config.js b/cfg/lint-staged.config.js index fef688c..751788c 100644 --- a/cfg/lint-staged.config.js +++ b/cfg/lint-staged.config.js @@ -59,8 +59,8 @@ if (!stylelintCmd) { } const linters = { - // *.{ts,tsx,vue} files: biome, eslint, prettier - './src/**/*.{ts,tsx,cts,mts,vue}': match => { + // biome, eslint, prettier + './src/**/*.{ts,tsx,cts,mts,vue,html}': match => { const filesList = getFilesList(match) if (!filesList) return [] return [ @@ -141,7 +141,7 @@ if (fs.existsSync(`./scripts`)) { ) Object.assign(linters, { // biome, eslint, Prettier - './scripts/**/*.{ts,tsx,cts,mts}': match => { + './scripts/**/*.{ts,tsx,cts,mts,vue,html}': match => { const filesList = getFilesList(match) if (!filesList) return [] return [ diff --git a/src/lint.util.ts b/src/lint.util.ts index 05eeb51..ef720be 100644 --- a/src/lint.util.ts +++ b/src/lint.util.ts @@ -8,6 +8,7 @@ const { prettierDirs, prettierExtensionsAll, stylelintExtensions, + eslintExtensions, lintExclude, } = require('../cfg/_cnst') @@ -92,7 +93,7 @@ export async function eslintAll(opt?: EslintAllOptions): Promise { const { argv } = yargs.options({ ext: { type: 'string', - default: 'ts,tsx,vue', + default: eslintExtensions, }, fix: { type: 'boolean', @@ -138,26 +139,32 @@ export async function eslintAll(opt?: EslintAllOptions): Promise { // /src runESLint(`./src`, eslintConfigPathRoot, undefined, extensions, fix), // /scripts - runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix), + runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, extensions, fix), // /e2e - runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix), + runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, extensions, fix), // /playwright // todo: remove after migration to e2e folder is completed - runESLint(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix), + runESLint( + `./playwright`, + eslintConfigPathPlaywright, + tsconfigPathPlaywright, + extensions, + fix, + ), ]) } else { // with no-fix - let's run serially // /src await runESLint(`./src`, eslintConfigPathRoot, undefined, extensions, fix) // /scripts - await runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix) + await runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, extensions, fix) // /e2e - await runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix) + await runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, extensions, fix) // /e2e await runESLint( `./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, - undefined, + extensions, fix, ) } @@ -169,7 +176,7 @@ async function runESLint( dir: string, eslintConfigPath: string | undefined, tsconfigPath?: string, - extensions = ['ts', 'tsx', 'vue'], + extensions = eslintExtensions, fix = true, ): Promise { if (!eslintConfigPath || !fs.existsSync(dir)) return // faster to bail-out like this