User story
See parent issue:
Usage examples
Default config only
Input
npm init @code-pushup/cli
Which configurations would you like to set up?
Output
Installs required peer dependencies:
npm install --save-dev \
eslint@^9.0.0 \
@eslint/js@^9.0.0 \
"eslint-plugin-functional@^7.0.0 || ^8.0.0 || ^9.0.0" \
eslint-plugin-import@^2.31.0 \
"eslint-plugin-promise@>=6.4.0" \
eslint-plugin-sonarjs@^1.0.4 \
"eslint-plugin-unicorn@>=50.0.0" \
"globals@>=14.0.0" \
typescript-eslint@^8.0.0
Installs our config package:
npm install --save-dev @code-pushup/eslint-config
Creates eslint.config.js:
import javascript from '@code-pushup/eslint-config/javascript.js';
import { defineConfig } from 'eslint/config';
export default defineConfig(...javascript);
Multiple configs, with additional configuration steps
Input
npm init @code-pushup/cli
Which configurations would you like to set up?
The selected "TypeScript (strict)" configuration requires additional setup. Which tsconfig should be used?
- Enter file path: tsconfig.json
Output
Installs required peer dependencies:
npm install --save-dev \
eslint@^9.0.0 \
@eslint/js@^9.0.0 \
"eslint-plugin-functional@^7.0.0 || ^8.0.0 || ^9.0.0" \
eslint-plugin-import@^2.31.0 \
"eslint-plugin-promise@>=6.4.0" \
eslint-plugin-sonarjs@^1.0.4 \
"eslint-plugin-unicorn@>=50.0.0" \
"globals@>=14.0.0" \
typescript-eslint@^8.0.0
Installs optional peer dependencies that are required by selected configs:
npm install --save-dev \
"eslint-import-resolver-typescript@^3.0.0 || ^4.0.0" \
@vitest/eslint-plugin@^1.1.9
Installs our config package:
npm install --save-dev @code-pushup/eslint-config
Creates eslint.config.js, including all configs and their additional setup steps:
import typescript from '@code-pushup/eslint-config/typescript.js';
import vitest from '@code-pushup/eslint-config/vitest.js';
import { defineConfig } from 'eslint/config';
export default defineConfig(
...typescript,
...vitest,
{
files: ['**/*.ts'],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: 'tsconfig.json',
},
},
},
},
);
Extending existing config
Input
The user has the following eslint.config.js:
import jsxA11y from 'eslint-plugin-jsx-a11y';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
export default [
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
jsxA11y.flatConfigs.recommended,
{
plugins: { 'react-hooks': reactHooks },
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
}
},
];
The user runs npm init @code-pushup/eslint-config and selects React and React Testing Library configs.
Output
The selected configs are appended to the flat config array.
import jsxA11y from 'eslint-plugin-jsx-a11y';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import cpReact from '@code-pushup/eslint-config/react.js';
import cpReactTestingLibrary from '@code-pushup/eslint-config/react-testing-library.js';
export default [
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
jsxA11y.flatConfigs.recommended,
{
plugins: { 'react-hooks': reactHooks },
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
}
},
...cpReact,
...cpReactTestingLibrary,
];
Implementation
In general, use the same approach as for @code-pushup/create-cli.
Acceptance criteria
User story
See parent issue:
@code-pushup/eslint-config#45Usage examples
Default config only
Input
Which configurations would you like to set up?
Output
Installs required peer dependencies:
Installs our config package:
Creates
eslint.config.js:Multiple configs, with additional configuration steps
Input
Which configurations would you like to set up?
The selected "TypeScript (strict)" configuration requires additional setup. Which tsconfig should be used?
Output
Installs required peer dependencies:
Installs optional peer dependencies that are required by selected configs:
npm install --save-dev \ "eslint-import-resolver-typescript@^3.0.0 || ^4.0.0" \ @vitest/eslint-plugin@^1.1.9Installs our config package:
Creates
eslint.config.js, including all configs and their additional setup steps:Extending existing config
Input
The user has the following
eslint.config.js:The user runs
npm init @code-pushup/eslint-configand selects React and React Testing Library configs.Output
The selected configs are appended to the flat config array.
Implementation
In general, use the same approach as for
@code-pushup/create-cli.Acceptance criteria
npm initcommand.javascriptconfig is always pre-selected.typescriptconfig is pre-selected if there's atsconfig.jsonfile ortypescriptis installed.nodeconfig is pre-selected if any well-known backend frameworks (express,@nestjs/core,@apollo/server,fastify) or full-stack frameworks (next,@angular/ssr,nuxt,@sveltejs/kit) are installed.angularconfig is pre-selected if@angular/coreis installed.ngrxconfig is pre-selected if@ngrx/coreis installed.reactconfig is pre-selected ifreactis installed.graphqlconfig is pre-selected if one of@apollo/server,graphql-yoga, ortype-graphqlis installed.jestconfig is pre-selected ifjestis installed or there's a/^jest\.config\.[cm]?[jt]s$/file.vitestconfig is pre-selected ifvitestis installed or there's a/^(vite|vitest)\.config\.m?[jt]s$/file.cypressconfig is pre-selected ifcypressis installed or there's a/^cypress\.config\.[cm]?[jt]s$/file.playwrightconfig is pre-selected if@playwright/testis installed or there's aplaywright.config.tsfile.storybookconfig is pre-selected ifstorybookis installed or there's a.storybookfolder.react-testing-libraryconfig is pre-selected if@testing-library/reactis installed.typescriptis selected, then the user should provide their tsconfig path. The default value should betsconfig.jsonor anytsconfig.*.jsonif such a file is found.nodeis selected, then the user should provide their Node version source.settings.node.versionis set tofs.readFileSync('.node-version', 'utf8')ineslint.config.js.package.json.settings.node.versionis set to a user-submitted value.@code-pushup/eslint-configpackage is installed.eslint.config.js, then it is created. The selected configs are included in it.eslint.config.jsalready exists, then it is modified. The selected configs are appended to the flat config array.eslint.config.jsfile is in CommonJS format, then the user is informed that Only ESLint configs in ESM format are supported and the setup wizard terminates without making any changes.defineConfigortseslint.config).