Course contentsShow
← JavaScript
Lesson 2570 of 2,72352. Linting and FormattingFree lesson

Introduction to Flat Config (eslint.config.js)

Understand ESLint's new flat config system introduced in ESLint 8+ and its simpler object-based structure.

Introduction to Flat Config (eslint.config.js)

You'll learn about ESLint's modern flat config system that simplifies configuration with a single JavaScript file.

What Is Flat Config?

Starting with ESLint 8.21.0, a new configuration system called flat config was introduced (and became the default in ESLint 9.0). Instead of the legacy .eslintrc file formats you've been using, flat config uses a single eslint.config.js file that exports an array of configuration objects.

Think of it like moving from a complex inheritance tree to a simple list. The old system involved multiple file formats (.eslintrc.json, .eslintrc.yml, etc.) with complex cascading rules across directories. Flat config streamlines this into one JavaScript file with a straightforward structure.

The Core Structure

In flat config, you export an array where each object defines rules for specific files:

export default [
  {
    files: ["**/*.js"],
    languageOptions: {
      ecmaVersion: 2022,
      sourceType: "module"
    },
    rules: {
      "no-unused-vars": "error",
      "semi": ["error", "always"]
    }
  }
];

Notice how everything is plain JavaScript objects—no special JSON or YAML formats. The files pattern determines which files these settings apply to, and rules work exactly as you've learned before.

Why It's Better

Flat config eliminates the confusing cascade behavior where multiple config files in different directories could conflict. Now you have one source of truth, making debugging configuration issues much simpler. Plus, since it's just JavaScript, you can use variables, imports, and functions naturally.

Key Takeaway: Flat config (eslint.config.js) is ESLint's modern configuration system that replaces .eslintrc files with a simpler, array-based structure using plain JavaScript objects, making configuration more predictable and easier to understand.