Skip to content

Commit b92b30f

Browse files
bpmutternzakas
andauthored
docs: Add Rules page intro and content tweaks (#16523)
* docs: add Rules page intro and content tweaks * Add rules link * Apply suggestions from code review Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com>
1 parent 1769b42 commit b92b30f

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

docs/src/user-guide/configuring/rules.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ eleventyNavigation:
88

99
---
1010

11-
## Configuring Rules
11+
Rules are the core building block of ESLint. A rule validates if your code meets a certain expectation, and what to do if it does not meet that expectation. Rules can also contain additional configuration options specific to that rule.
1212

13-
ESLint comes with a large number of built-in rules and you can add more rules through plugins. You can modify which rules your project uses either using configuration comments or configuration files. To change a rule setting, you must set the rule ID equal to one of these values:
13+
ESLint comes with a large number of [built-in rules](../../rules/) and you can add more rules through plugins. You can modify which rules your project uses with either configuration comments or configuration files.
14+
15+
## Rule Severities
16+
17+
To change a rule's severity, set the rule ID equal to one of these values:
1418

1519
* `"off"` or `0` - turn the rule off
1620
* `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
@@ -40,6 +44,8 @@ If a rule has additional options, you can specify them using array literal synta
4044

4145
This comment specifies the "double" option for the [`quotes`](../../rules/quotes) rule. The first item in the array is always the rule severity (number or string).
4246

47+
#### Configuration Comment Descriptions
48+
4349
Configuration comments can include descriptions to explain why the comment is necessary. The description must occur after the configuration and is separated from the configuration by two or more consecutive `-` characters. For example:
4450

4551
```js
@@ -85,7 +91,11 @@ rules:
8591
- double
8692
```
8793
88-
To configure a rule which is defined within a plugin you have to prefix the rule ID with the plugin name and a `/`. For example:
94+
## Rules from Plugins
95+
96+
To configure a rule that is defined within a plugin, prefix the rule ID with the plugin name and `/`.
97+
98+
In a configuration file, for example:
8999

90100
```json
91101
{
@@ -116,7 +126,9 @@ rules:
116126
plugin1/rule1: error
117127
```
118128

119-
In these configuration files, the rule `plugin1/rule1` comes from the plugin named `plugin1`. You can also use this format with configuration comments, such as:
129+
In these configuration files, the rule `plugin1/rule1` comes from the plugin named `plugin1`, which is contained in an npm package named `eslint-plugin-plugin1`.
130+
131+
You can also use this format with configuration comments, such as:
120132

121133
```js
122134
/* eslint "plugin1/rule1": "error" */
@@ -128,7 +140,7 @@ In these configuration files, the rule `plugin1/rule1` comes from the plugin nam
128140

129141
### Using configuration comments
130142

131-
To temporarily disable rule warnings in your file, use block comments in the following format:
143+
To disable rule warnings in a part of a file, use block comments in the following format:
132144

133145
```js
134146
/* eslint-disable */
@@ -149,7 +161,7 @@ console.log('bar');
149161
/* eslint-enable no-alert, no-console */
150162
```
151163

152-
**Note:** `/* eslint-enable */` without any specific rules listed will cause all disabled rules to be re-enabled.
164+
**Note:** `/* eslint-enable */` without any specific rules listed causes all disabled rules to be re-enabled.
153165

154166
To disable rule warnings in an entire file, put a `/* eslint-disable */` block comment at the top of the file:
155167

@@ -235,7 +247,7 @@ foo(); /* eslint-disable-line example/rule-name */
235247

236248
#### Comment descriptions
237249

238-
Configuration comments can include descriptions to explain why the comment is necessary. The description must come after the configuration and needs to be separated from the configuration by two or more consecutive `-` characters. For example:
250+
Configuration comments can include descriptions to explain why disabling or re-enabling the rule is necessary. The description must come after the configuration and needs to be separated from the configuration by two or more consecutive `-` characters. For example:
239251

240252
```js
241253
// eslint-disable-next-line no-console -- Here's a description about why this configuration is necessary.
@@ -268,7 +280,7 @@ To disable rules inside of a configuration file for a group of files, use the `o
268280

269281
### Disabling Inline Comments
270282

271-
To disable all inline config comments, use the `noInlineConfig` setting. For example:
283+
To disable all inline config comments, use the `noInlineConfig` setting in your configuration file. For example:
272284

273285
```json
274286
{
@@ -277,7 +289,7 @@ To disable all inline config comments, use the `noInlineConfig` setting. For exa
277289
}
278290
```
279291

280-
This setting is similar to [--no-inline-config](../command-line-interface#--no-inline-config) CLI option.
292+
You can also use the [--no-inline-config](../command-line-interface#--no-inline-config) CLI option to disable rule comments, in addition to other in-line configuration.
281293

282294
#### Report unused `eslint-disable` comments
283295

0 commit comments

Comments
 (0)