|
| 1 | +--- |
| 2 | +title: Debug Your Configuration |
| 3 | +eleventyNavigation: |
| 4 | + key: debug config |
| 5 | + parent: configure |
| 6 | + title: Debug Your Configuration |
| 7 | + order: 8 |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +ESLint creates a configuration for each file that is linted based on your configuration file and command line options. The larger the configuration file, the more difficult it can be to determine why a file isn't linted as expected. To aid in debugging your configuration, ESLint provides several tools. |
| 12 | + |
| 13 | +## Run the CLI in Debug Mode |
| 14 | + |
| 15 | +**Use When:** You aren't sure if the correct configuration file is being read. This may happen if you have multiple configuration files in the same project. |
| 16 | + |
| 17 | +**What To Do:** Run ESLint with the `--debug` command line flag and pass the file to check, like this: |
| 18 | + |
| 19 | +```shell |
| 20 | +npx eslint --debug file.js |
| 21 | +``` |
| 22 | + |
| 23 | +This outputs all of ESLint's debugging information onto the console. You should copy this output to a file and then search for "eslint.config.js` to see which file is loaded. Here's some example output: |
| 24 | + |
| 25 | +```text |
| 26 | +eslint:eslint Using file patterns: bin/eslint.js +0ms |
| 27 | +eslint:eslint Searching for eslint.config.js +0ms |
| 28 | +eslint:eslint Loading config from C:\Users\nzakas\projects\eslint\eslint\eslint.config.js +5ms |
| 29 | +eslint:eslint Config file URL is file:///C:/Users/nzakas/projects/eslint/eslint/eslint.config.js +0ms |
| 30 | +``` |
| 31 | + |
| 32 | +## Print a File's Calculated Configuration |
| 33 | + |
| 34 | +**Use When:** You aren't sure why linting isn't producing the expected results, either because it seems like your rule configuration isn't being honored or the wrong language options are being used. |
| 35 | + |
| 36 | +**What To Do:** Run ESLint with the `--print-config` command line flag and pass the file to check, like this: |
| 37 | + |
| 38 | +```shell |
| 39 | +npx eslint --print-config file.js |
| 40 | +``` |
| 41 | + |
| 42 | +This outputs a JSON representation of the file's calculated config, such as: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "linterOptions": { |
| 47 | + "reportUnusedDisableDirectives": 1 |
| 48 | + }, |
| 49 | + "language": "@/js", |
| 50 | + "languageOptions": { |
| 51 | + "sourceType": "module", |
| 52 | + "ecmaVersion": "latest" |
| 53 | + }, |
| 54 | + "plugins": [ |
| 55 | + "@" |
| 56 | + ], |
| 57 | + "rules": { |
| 58 | + "prefer-const": 2 |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +::: tip |
| 64 | +You won't see any entries for `files`, `ignores`, or `name`, because those are only used in calculating the final configuration and so do not appear in the result. You will see any default configuration applied by ESLint itself. |
| 65 | +::: |
| 66 | + |
| 67 | +## Use the Config Inspector |
| 68 | + |
| 69 | +**Use When:** You aren't sure if certain configuration objects in your configuration file match a given filename. |
| 70 | + |
| 71 | +**What To Do:** Run ESLint with the `--inspect-config` command line flag and pass the file to check, like this: |
| 72 | + |
| 73 | +```shell |
| 74 | +npx eslint --inspect-config |
| 75 | +``` |
| 76 | + |
| 77 | +This initiates the config inspector by installing and starting [`@eslint/config-inspector`](https://github.com/eslint/config-inspector). You can then type in the filename in question to see which configuration objects will apply. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +The config inspector also shows you when rules are deprecated, how many available rules you're using, and more. |
0 commit comments