|
| 1 | +<div align="center"> |
| 2 | + <a href="https://eslint.org/"> |
| 3 | + <img |
| 4 | + width="150" |
| 5 | + height="150" |
| 6 | + src="https://eslint.org/assets/img/logo.svg" |
| 7 | + alt="ESLint Logo" |
| 8 | + /> |
| 9 | + </a> |
| 10 | + <h1>eslint-plugin-eslint-config</h1> |
| 11 | + <p>ESLint plugin for ESLint configs</p> |
| 12 | +</div> |
| 13 | + |
| 14 | +This plugin provides rules for linting files that export configs meant for use |
| 15 | +with ESLint, to ensure that they're valid. |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | + npm install --dev eslint eslint-plugin-eslint-config |
| 20 | + |
| 21 | +**Note:** If you installed ESLint globally then you must also install |
| 22 | +`eslint-plugin-eslint-config` globally. |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +Add `config` to the plugins section of your `.eslintrc.js` configuration file. |
| 27 | +You can omit the `eslint-plugin-` prefix: |
| 28 | + |
| 29 | +```json |
| 30 | +{ |
| 31 | + "plugins": ["eslint-config"] |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +Then configure the rules you want to use _for your config(s)_ using `overrides`: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "overrides": [ |
| 40 | + { |
| 41 | + "files": [".eslintrc.js", "react.js", "@typescript-eslint.js"], |
| 42 | + "rules": { |
| 43 | + "eslint-config/no-deprecated-rules": "warn" |
| 44 | + } |
| 45 | + } |
| 46 | + ] |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +The rules assume that the files they're linting are configs meant for ESLint. |
| 51 | + |
| 52 | +## Shareable configurations |
| 53 | + |
| 54 | +This plugin provides three presets: |
| 55 | + |
| 56 | +- `recommended-rules` |
| 57 | +- `rc` |
| 58 | +- `all` |
| 59 | + |
| 60 | +The `rc` preset generally should be used by all projects, as it applies |
| 61 | +recommended rules to supported eslintrc files. |
| 62 | + |
| 63 | +If a project contains other files that export eslint configs (such as an eslint |
| 64 | +config package), the `recommended-rules` preset can be used to apply the |
| 65 | +recommended rules to those files using `overrides`. |
| 66 | + |
| 67 | +<!-- The reason behind having two presets instead of the standard `recommended` |
| 68 | +preset is because the rules provided by this plugin work by executing the source |
| 69 | +code that they're linting to capture the configuration they export that gets |
| 70 | +used by eslint. |
| 71 | +
|
| 72 | +This means that they can trigger side effects in the same way importing a file |
| 73 | +might, and so should not be applied to every file in a code base. |
| 74 | +
|
| 75 | +To facilitate this ESLint allows configs to provide an `overrides` property that |
| 76 | +applies rules to files based on globs (which is what `eslint-config/rc` does), |
| 77 | +but while shared configs can use `overrides` there isn't a way to nicely to add |
| 78 | +to the glob patterns to reuse the rules. --> |
| 79 | + |
| 80 | +While the `recommended` and `rc` configurations only change in major versions, |
| 81 | +the `all` configuration may change in any release and is thus unsuited for |
| 82 | +installations requiring long-term consistency. |
| 83 | + |
| 84 | +## Rules |
| 85 | + |
| 86 | +<!-- begin rules list --> |
| 87 | + |
| 88 | +| Rule | Description | Configurations | Fixable | |
| 89 | +| -------------------------------------------------------- | --------------------------------------------------- | ---------------- | ------------ | |
| 90 | +| [no-deprecated-rules](docs/rules/no-deprecated-rules.md) | Checks for usage of deprecated eslint rules | ![recommended][] | | |
| 91 | +| [no-invalid-config](docs/rules/no-invalid-config.md) | Checks that the config exported by a file is valid | ![recommended][] | | |
| 92 | +| [no-unknown-rules](docs/rules/no-unknown-rules.md) | Ensures that all rules are known | ![recommended][] | | |
| 93 | +| [sort-rules](docs/rules/sort-rules.md) | Ensures that rules are sorted in a consistent order | | ![fixable][] | |
| 94 | + |
| 95 | +<!-- end rules list --> |
| 96 | + |
| 97 | +[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg |
| 98 | +[fixable]: https://img.shields.io/badge/-fixable-green.svg |
0 commit comments