Skip to content

Commit

Permalink
fix: add ignore config
Browse files Browse the repository at this point in the history
  • Loading branch information
ASafaeirad committed Jun 9, 2024
1 parent bdda8b2 commit c4ed3c8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 57 deletions.
37 changes: 19 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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'];

Expand All @@ -42,6 +42,7 @@ const defaultOptions = {
typescript: isPackageExists('typescript') ? { projects: true } : false,
unocss: isPackageExists('unocss'),
playwright: isPackageExists('playwright'),
ignores: [],
};

/**
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/init.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
39 changes: 0 additions & 39 deletions src/modules/ignores.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/utils/compose.js
Original file line number Diff line number Diff line change
@@ -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;
32 changes: 32 additions & 0 deletions src/utils/globs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c4ed3c8

Please sign in to comment.