# Targeting Files, Globals & Overrides — ESLint and Prettier: Code Quality and Formatting

Source: https://www.skillbyai.com/en/eslint-prettier/eslint-prettier-08

> Target files with the files key, set globals and apply different rules to tests in flat config.

## Environments and globals

In flat config, `languageOptions.globals` replaces `env`, and extra config objects with a `files` pattern replace `overrides`. Later objects win for the files they match.

## Using overrides

Apply stricter rules to source files but looser rules to tests.

```json
import globals from 'globals';

export default [
  { languageOptions: { globals: globals.browser }, rules: { 'no-console': 'error' } },
  {
    files: ['**/*.test.js'],
    languageOptions: { globals: globals.jest },
    rules: { 'no-console': 'off' },
  },
  { ignores: ['dist/', 'coverage/'] },
];
```

Output:

```
Overrides configured: stricter prod, lenient tests
```

## Selective strictness

Test files and scripts often need looser rules. Add a config object with a `files` pattern instead of duplicating your base config, and use a top-level `ignores` object for build output.

Quick check

**Quiz:** How do you apply different rules to test files in flat config?

- [x] Add a config object with a files pattern
- [ ] Use the env key
- [ ] Rename the files
- [ ] Use .eslintignore only

*Answer:* Add a config object with a files pattern. Later matching objects override earlier ones.
