Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
1 min readDev Tool

Migrate to ESLint 9 flat config

Convert a browser project’s .eslintrc.json to ESLint 9 flat config, then check the effective globals, rule settings, and ignored files.

You upgrade a browser project to ESLint 9 and the next lint run says it cannot find an eslint.config file. The rules are still in .eslintrc.json. ESLint 9 looks for flat config by default.

Move the settings into the config array

Take a plain JavaScript project with one browser global and a rule that catches undeclared names. In the old config, ignorePatterns skips generated files with a matching basename.

{
  "globals": { "window": "readonly" },
  "parserOptions": { "ecmaVersion": 2022, "sourceType": "module" },
  "ignorePatterns": ["generated.js"],
  "rules": { "no-undef": "error" }
}

With this file alone, ESLint 9 in its default mode stops before it checks the source files.

Save the replacement as eslint.config.mjs at the project root. The .mjs extension lets you use export default even if the package has no "type": "module". Put the language settings and rules in the object for JavaScript files.

export default [
  { ignores: ["**/generated.js"] },
  {
    files: ["**/*.js"],
    languageOptions: {
      ecmaVersion: 2022,
      sourceType: "module",
      globals: { window: "readonly" },
    },
    rules: { "no-undef": "error" },
  },
]

In a project with this config, ESLint loads the browser global for public/app.js and skips public/generated.js.

Keep the ignore in its own object so it applies across the array. The **/ matters. A bare generated.js in flat config matches that path beside the config file. The migration guide shows the same change for nested files.

Check a file that should be linted

With the local ESLint binary on your path, print the calculated config for an ordinary source file. Then run lint against the project.

eslint --print-config public/app.js
eslint .

With window.alert("Ready") and widnow.alert("Typo") in that file, the config shows the window global and lint reports only the misspelled name.

Migrate any patterns from .eslintignore into the standalone ignores object. Flat config does not read .eslintignore. If lint reports errors from generated directories, compare their paths with the standalone ignore patterns. Run the same lint command CI uses before deleting the old files.