← Back to list

New version of ESLint(9.x.x) with flat config

ESLint Configuration Changes in v9.x.x

Hongyuyang · 2024-07-12 01:51 · 2 claps · 1.5 min read
#nodejs #eslint #eslint-config #flatconfig
Open on Medium ↗
Wiki topics: 🌐 · Web Development

New version of ESLint(9.x.x) with flat config

ESLint Configuration Changes in v9.x.x

The default configuration format for ESLint has changed in version 9.x.x. The new default configuration file is eslint.config.js.

Refer to the official documentation: Migrate to v9.x — ESLint — Pluggable JavaScript Linter

Changes in Global Definitions

In the previous eslintrc configuration system, you could use eslint-env comments to define globals for a file. These comments are no longer recognized in the new flat config.

Refer to the official documentation: Configuration Migration Guide — ESLint — Pluggable JavaScript Linter

For Node.js project, we can set globals in the new configuration system like this:

import globals from "globals";

export default [
    {
        languageOptions: {
            ecmaVersion: 2022,
            sourceType: "module",
            globals: {
                ...globals.node
            }
        }
        // ...other config
    }
];

Changes in eslint:recommended Configuration

In version 9.x.x, you can no longer use extends to include configurations like eslint:recommended.

Previous way using extends:

"extends": [
  "eslint:recommended",
]

New way in eslint.config.js:

Example eslint.config.js for node.js Project

Here is what the eslint.config.js file looks like for Node.js project(with commonJS and conbine with eslint-plugin-prettie for using .prettierc file rules in ESLint):

const js = require('@eslint/js');
const prettierConfig = require('eslint-config-prettier');
const prettierPlugin = require('eslint-plugin-prettier');
const globals = require('globals');

module.exports = [
  js.configs.recommended,
  {
    languageOptions: {
      sourceType: 'script', // for commonJS
      globals: {
        ...globals.node
      }
    },
    plugins: {
      prettier: prettierPlugin
    },
    rules: {
      ...prettierConfig.rules, // Integrate Prettier rules to disable conflicting ESLint rules
      'prettier/prettier': 'error' // Ensure Prettier formatting issues are reported as ESLint errors
    }
  }
];

메타데이터
post_id
c8ad3e5d5413
slug
new-version-of-eslint-9-x-x-with-flat-config-c8ad3e5d5413
url
https://medium.com/@hongyuyang084/new-version-of-eslint-9-x-x-with-flat-config-c8ad3e5d5413
canonical_url
https://medium.com/@hongyuyang084/new-version-of-eslint-9-x-x-with-flat-config-c8ad3e5d5413
author_url
https://medium.com/@hongyuyang084
status
ok
fetched_at
2026-07-28 16:12:54