ESLint config generator

Pick the language, where the code runs and a few popular rules, and copy a ready eslint.config.js for ESLint 9 and later. The first line is the npm command that installs exactly the packages the config imports.

Language
Code runs in
Modules in .js files
Separated by spaces or commas. A trailing / means a folder.

Save in the project root and run npx eslint . — with CommonJS, name the file eslint.config.mjs as its first line says.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose JavaScript or TypeScript and where the code runs.
  2. Say whether .js files use import or require.
  3. Tick the rules you want and, if you format with Prettier, the Prettier option.
  4. Run the npm install --save-dev … command from the first line, save the file in the project root and run npx eslint ..

How it works

The output is an array exported with export default:

  • an object with only ignores — global ignores for build folders;
  • js.configs.recommended from @eslint/js (and ...tseslint.configs.recommended for TypeScript);
  • your block: the file patterns, ecmaVersion: 'latest', the globals and the chosen rules;
  • for CommonJS, a block that sets sourceType: 'commonjs' for .js files (ESLint already treats .cjs as CommonJS);
  • eslintConfigPrettier last, if chosen.

Example

The defaults (JavaScript, browser, ES modules, recommended rules, eqeqeq, prefer-const, unused variables as warnings) give:

// npm install --save-dev eslint @eslint/js globals
import js from '@eslint/js';
import globals from 'globals';

export default [
  { ignores: ['dist/', 'build/', 'coverage/'] },
  js.configs.recommended,
  {
    files: ['**/*.{js,mjs,cjs}'],
    languageOptions: {
      ecmaVersion: 'latest',
      globals: globals.browser,
    },
    rules: {
      eqeqeq: ['error', 'always'],
      'prefer-const': 'error',
      'no-unused-vars': 'warn',
    },
  },
];

Tips

  • Add "lint": "eslint ." to the scripts in package.json so everyone runs the same command.
  • npx eslint . --fix repairs what can be fixed automatically, such as let that should be const.
  • Let Prettier handle formatting and ESLint handle code quality; that is what the Prettier option is for.

Frequently asked questions

What is the flat config format?

Since ESLint 9 the configuration is a JavaScript file, eslint.config.js, that exports an array of config objects. Each object can say which files it applies to, which parser and globals to use and which rules to turn on. The old .eslintrc files are no longer read by default.

Why does the config import the globals package?

ESLint does not know which global variables exist in your environment. The globals package lists them, for example window and document for browsers or process and __dirname for Node.js, so no-undef does not report them.

What does typescript-eslint add?

A parser that understands TypeScript syntax and a recommended rule set. It also turns off core rules that TypeScript already checks, which is why the unused-variable rule becomes @typescript-eslint/no-unused-vars.

Why is the Prettier config last?

eslint-config-prettier turns off formatting rules that would fight with Prettier. Later entries in the array override earlier ones, so it has to come after every rule set it switches off.

Why eslint.config.mjs for CommonJS projects?

The config uses import and export. Node.js treats a .js file as CommonJS unless package.json has "type": "module", so in a CommonJS project the file needs the .mjs extension.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.