You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: docs/src/user-guide/configuring/rules.md
+21-9Lines changed: 21 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,13 @@ eleventyNavigation:
8
8
9
9
---
10
10
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.
12
12
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:
14
18
15
19
*`"off"` or `0` - turn the rule off
16
20
*`"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
40
44
41
45
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).
42
46
47
+
#### Configuration Comment Descriptions
48
+
43
49
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:
44
50
45
51
```js
@@ -85,7 +91,11 @@ rules:
85
91
- double
86
92
```
87
93
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:
89
99
90
100
```json
91
101
{
@@ -116,7 +126,9 @@ rules:
116
126
plugin1/rule1: error
117
127
```
118
128
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:
120
132
121
133
```js
122
134
/* eslint "plugin1/rule1": "error" */
@@ -128,7 +140,7 @@ In these configuration files, the rule `plugin1/rule1` comes from the plugin nam
128
140
129
141
### Using configuration comments
130
142
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:
132
144
133
145
```js
134
146
/* eslint-disable */
@@ -149,7 +161,7 @@ console.log('bar');
149
161
/* eslint-enable no-alert, no-console */
150
162
```
151
163
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.
153
165
154
166
To disable rule warnings in an entire file, put a `/* eslint-disable */` block comment at the top of the file:
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:
239
251
240
252
```js
241
253
// 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
268
280
269
281
### Disabling Inline Comments
270
282
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:
272
284
273
285
```json
274
286
{
@@ -277,7 +289,7 @@ To disable all inline config comments, use the `noInlineConfig` setting. For exa
277
289
}
278
290
```
279
291
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.
0 commit comments