From c4ed3c843d97a4b222a3d6a62899f724cc12b4e9 Mon Sep 17 00:00:00 2001 From: Alireza Safaierad Date: Sun, 9 Jun 2024 02:02:28 +0200 Subject: [PATCH] fix: add ignore config --- src/index.js | 37 +++++++++++++++++++------------------ src/init.d.ts | 1 + src/modules/ignores.js | 39 --------------------------------------- src/utils/compose.js | 14 ++++++++++++++ src/utils/globs.js | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 57 deletions(-) delete mode 100644 src/modules/ignores.js create mode 100644 src/utils/compose.js diff --git a/src/index.js b/src/index.js index 6be4d43..22f1152 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,6 @@ const merge = require('deepmerge'); const { isPackageExists } = require('local-pkg'); const base = require('./modules/base'); const cypress = require('./modules/cypress'); -const ignores = require('./modules/ignores'); const imports = require('./modules/imports'); const prettier = require('./modules/prettier'); const tailwind = require('./modules/tailwind'); @@ -18,6 +17,7 @@ const react = require('./modules/react'); const storybook = require('./modules/storybook'); const typescript = require('./modules/typescript'); const playwright = require('./modules/playwright'); +const compose = require('./utils/compose'); const testPackages = ['jest', 'vitest', 'cypress', 'playwright']; @@ -42,6 +42,7 @@ const defaultOptions = { typescript: isPackageExists('typescript') ? { projects: true } : false, unocss: isPackageExists('unocss'), playwright: isPackageExists('playwright'), + ignores: [], }; /** @@ -60,28 +61,28 @@ function init(initOptions, ...extend) { options.import = {}; } - const rules = [ignores(), base()]; + const rules = [compose(base, options)]; - if (options.fp) rules.push(fp(options)); - if (options.import) rules.push(imports(options)); - if (options.tailwind) rules.push(tailwind(options)); - if (options.test) rules.push(tests(options)); - if (options.node) rules.push(node(options)); - if (options.jest) rules.push(jest(options)); - if (options.vitest) rules.push(vitest(options)); - if (options.cypress) rules.push(cypress(options)); - if (options.react) rules.push(react(options)); - if (options.storybook) rules.push(storybook(options)); - if (options.typescript) rules.push(typescript(options)); - if (options.playwright) rules.push(playwright(options)); + if (options.fp) rules.push(compose(fp, options)); + if (options.import) rules.push(compose(imports, options)); + if (options.tailwind) rules.push(compose(tailwind, options)); + if (options.test) rules.push(compose(tests, options)); + if (options.node) rules.push(compose(node, options)); + if (options.jest) rules.push(compose(jest, options)); + if (options.vitest) rules.push(compose(vitest, options)); + if (options.cypress) rules.push(compose(cypress, options)); + if (options.react) rules.push(compose(react, options)); + if (options.storybook) rules.push(compose(storybook, options)); + if (options.typescript) rules.push(compose(typescript, options)); + if (options.playwright) rules.push(compose(playwright, options)); // ISSUE: Waiting for FlatConfig support https://github.com/dimaMachina/graphql-eslint/issues/2178 - // if (false && options.graphql) rules.push(graphql(options)); + // if (false && options.graphql) rules.push(compose(graphql,options)); // ISSUE: Waiting for FlatConfig support https://github.com/vercel/next/issues/64409#issuecomment-2057325722 - // if (false && options.next) rules.push(next(options)); + // if (false && options.next) rules.push(compose(next,options)); - if (options.strict) rules.push(strict(options)); - if (options.prettier) rules.push(prettier(options)); + if (options.strict) rules.push(compose(strict, options)); + if (options.prettier) rules.push(compose(prettier, options)); return rules.concat(extend); } diff --git a/src/init.d.ts b/src/init.d.ts index 581ea47..f8b2a27 100644 --- a/src/init.d.ts +++ b/src/init.d.ts @@ -17,6 +17,7 @@ export interface Options { playwright?: boolean; typescript?: { projects: string[] | string | boolean; tsconfigRootDir?: string }; disableExpensiveRules?: boolean; + ignores?: string[]; } export declare const init: (opts: Options) => import('eslint').Linter.FlatConfig[]; diff --git a/src/modules/ignores.js b/src/modules/ignores.js deleted file mode 100644 index 4f45c38..0000000 --- a/src/modules/ignores.js +++ /dev/null @@ -1,39 +0,0 @@ -/** @return { import('eslint').Linter.FlatConfig } */ -function ignores() { - return { - name: 'fullstacksjs/ignores', - ignores: [ - '**/node_modules', - '**/dist', - '**/package-lock.json', - '**/yarn.lock', - '**/pnpm-lock.yaml', - '**/bun.lockb', - - '**/output', - '**/coverage', - '**/temp', - '**/.temp', - '**/tmp', - '**/.tmp', - '**/.nx', - '**/.history', - '**/.vitepress/cache', - '**/.nuxt', - '**/.next', - '**/.vercel', - '**/.changeset', - '**/.idea', - '**/.cache', - '**/.output', - '**/.vite-inspect', - '**/.yarn', - '**/LICENSE*', - '**/*.min.*', - - '**/__snapshots__', - ], - }; -} - -module.exports = ignores; diff --git a/src/utils/compose.js b/src/utils/compose.js new file mode 100644 index 0000000..192cc23 --- /dev/null +++ b/src/utils/compose.js @@ -0,0 +1,14 @@ +import { ignoreGlobs } from './globs'; + +/** + * @param { (options: import('eslint').Linter.FlatConfig) => import('eslint').Linter.FlatConfig } module + * @param { import('../init').Options } options + * @return { import('eslint').Linter.FlatConfig } + */ +function compose(module, options) { + const config = module(options); + config.ignores = [config.ignores, ...options.ignores, ...ignoreGlobs]; + return config; +} + +module.exports = compose; diff --git a/src/utils/globs.js b/src/utils/globs.js index 014dfd3..f946b1e 100644 --- a/src/utils/globs.js +++ b/src/utils/globs.js @@ -35,6 +35,38 @@ const globs = { }; const allSrc = [globs.src, globs.style, globs.allJson, globs.md, globs.svelte, globs.vue, globs.yaml, globs.xml, globs.html]; +const ignoreGlobs = [ + '**/node_modules', + '**/dist', + '**/package-lock.json', + '**/yarn.lock', + '**/pnpm-lock.yaml', + '**/bun.lockb', + + '**/output', + '**/coverage', + '**/temp', + '**/.temp', + '**/tmp', + '**/.tmp', + '**/.nx', + '**/.history', + '**/.vitepress/cache', + '**/.nuxt', + '**/.next', + '**/.vercel', + '**/.changeset', + '**/.idea', + '**/.cache', + '**/.output', + '**/.vite-inspect', + '**/.yarn', + '**/LICENSE*', + '**/*.min.*', + + '**/__snapshots__', +]; module.exports.globs = globs; module.exports.allSrc = allSrc; +module.exports.ignoreGlobs = ignoreGlobs;