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

Flat Config: Files and Ignores

Learn how to specify file patterns and ignore patterns directly in flat config objects.

Flat Config: Files and Ignores

What you'll learn: How to control which files ESLint processes by specifying file patterns and ignore patterns directly in your flat config objects.

The Core Idea

In the flat config system (eslint.config.js), each configuration object can include a files array to specify which files it applies to, and an ignores array to exclude certain patterns. This gives you fine-grained control over your linting setup without needing a separate .eslintignore file.

Think of it like creating different "zones" in your project—each zone gets its own rules, and you can fence off areas that shouldn't be linted at all.

Files: Targeting Specific Patterns

The files property accepts glob patterns to match files:

export default [
  {
    files: ["src/**/*.js"],
    rules: {
      "no-console": "warn"
    }
  }
];

This configuration only applies to .js files inside the src directory and its subdirectories.

Ignores: Excluding Patterns

The ignores property tells ESLint to skip certain files:

export default [
  {
    ignores: ["dist/**", "build/**", "**/*.min.js"]
  }
];

When an object contains only ignores (no other properties), it acts as a global ignore pattern for your entire project.

Combining Both

You can use files and ignores together in the same object:

export default [
  {
    files: ["src/**/*.js"],
    ignores: ["src/**/*.test.js"],
    rules: {
      "no-console": "error"
    }
  }
];

This applies rules to all .js files in src, except test files.

Key Takeaway: Flat config's files and ignores properties let you define precise linting boundaries directly in configuration objects, replacing the need for separate ignore files and giving you pattern-level control over where rules apply.