Skip to content

API: mocg() & factories

mocg(options?)

The umbrella factory. Returns a Promise resolving to a flat-config array. Use it as the default export of your eslint.config.mjs.

js
import { mocg } from 'eslint-config-mocg';

export default mocg(options);

Options

All options are optional. Stack/add-on flags are boolean | undefinedtrue forces on, false forces off, omitted means auto-detect.

OptionTypeDefaultDescription
nodebooleanalways onThe Node/TypeScript base. Always included.
nestbooleanautoNestJS rules (replaces the base with Node + Nest).
reactbooleanautoReact, hooks, and JSX-runtime rules. (Fast Refresh is the vite add-on; React Compiler is opt-in — see /react-compiler.)
nextbooleanautoNext.js rules — React + the official @next/eslint-plugin-next Core Web Vitals rules. Supersedes react.
vuebooleanautoVue SFC rules.
vueTsbooleanfalseUse the TypeScript parser chain for .vue files.
vitebooleanautoReact Fast Refresh rules (auto-enabled when vite is a dependency).
vitestbooleanautoVitest test-file rules (plugin bundled).
jestbooleanautoJest test-file rules.
zodbooleanautoZod schema rules (plugin bundled).
i18nbooleanautoi18next rules.
tailwindbooleanautoTailwind class rules.
rootDirstringprocess.cwd()Project root for resolving tsconfig and detection.
tsconfigstringauto-discoveredExplicit tsconfig filename for type-aware linting.
scriptstsconfigstringtsconfig.scripts.jsonExplicit tsconfig for the scripts/ directory.
gitignorestring<rootDir>/.gitignorePath to the .gitignore to honor as ignores.

Examples

js
export default mocg();                              // auto-detect everything
export default mocg({ react: true, vitest: true }); // explicit stacks
export default mocg({ tsconfig: 'tsconfig.app.json' });
export default mocg({ vue: true, vueTs: true });    // type-aware Vue SFCs

Subpath exports (escape hatches)

Each stack is also exported on its own subpath, importing its optional peers directly. Use these when you want to hand-compose the array instead of letting mocg() orchestrate.

ImportExport(s)
eslint-config-mocgmocg (default & named), createNodeConfig, detectStacks, STACKS, EXTRAS
eslint-config-mocg/nodecreateNodeConfig, default
eslint-config-mocg/reactcreateReactConfig, default (pristine — no Fast Refresh)
eslint-config-mocg/nextcreateNextConfig, default (React + Next)
eslint-config-mocg/react-compilerdefault (opt-in; requires eslint-plugin-react-compiler)
eslint-config-mocg/vitedefault (React Fast Refresh; requires eslint-plugin-react-refresh)
eslint-config-mocg/vuecreateVueConfig, createVueTsConfig, default
eslint-config-mocg/nestcreateNestConfig, default
eslint-config-mocg/vitestdefault
eslint-config-mocg/jestdefault
eslint-config-mocg/zoddefault
eslint-config-mocg/i18ndefault
eslint-config-mocg/tailwinddefault
eslint-config-mocg/stacksSTACKS, EXTRAS, requiredPlugins, PACKAGE_NAME

Why framework factories aren't on the root

The root entry only re-exports createNodeConfig (which has no optional peers). Framework factories live on their subpaths so importing the root never forces React/Vue/Nest plugins to resolve. Import createReactConfig from eslint-config-mocg/react, not from the root.

Hand-composing

js
import { defineConfig } from 'eslint/config';
import { createNodeConfig } from 'eslint-config-mocg/node';
import { createReactConfig } from 'eslint-config-mocg/react';

export default defineConfig([
  ...createNodeConfig({ tsconfig: 'tsconfig.json' }),
  ...createReactConfig(),
]);

detectStacks(rootDir?)

Returns { stacks: string[], extras: string[] } for a project root, based on its declared dependencies. This is what mocg() uses internally and what the CLI uses for pre-selection.

js
import { detectStacks } from 'eslint-config-mocg';

detectStacks(process.cwd()); // → { stacks: ['react'], extras: ['vitest'] }

STACKS / EXTRAS / requiredPlugins

The manifest that drives the installer, doctor, and error messages. requiredPlugins(selection) returns the { packageName: versionRange } map an install would need for a given selection of stack/extra keys. Versions are sourced from this package's own peerDependencies, so there is a single source of truth.

Internal tooling — Master of Code Global