Skip to content

Commit

Permalink
docs: Add Rules page intro and content tweaks (#16523)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
bpmutter and nzakas committed Nov 16, 2022
1 parent 1769b42 commit b92b30f
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions docs/src/user-guide/configuring/rules.md
Expand Up @@ -8,9 +8,13 @@ eleventyNavigation:

---

## Configuring Rules
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.

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:
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.

## Rule Severities

To change a rule's severity, set the rule ID equal to one of these values:

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

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).

#### Configuration Comment Descriptions

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:

```js
Expand Down Expand Up @@ -85,7 +91,11 @@ rules:
- double
```

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:
## Rules from Plugins

To configure a rule that is defined within a plugin, prefix the rule ID with the plugin name and `/`.

In a configuration file, for example:

```json
{
Expand Down Expand Up @@ -116,7 +126,9 @@ rules:
plugin1/rule1: error
```

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:
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`.

You can also use this format with configuration comments, such as:

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

### Using configuration comments

To temporarily disable rule warnings in your file, use block comments in the following format:
To disable rule warnings in a part of a file, use block comments in the following format:

```js
/* eslint-disable */
Expand All @@ -149,7 +161,7 @@ console.log('bar');
/* eslint-enable no-alert, no-console */
```

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

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

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

#### Comment descriptions

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:
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:

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

### Disabling Inline Comments

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

```json
{
Expand All @@ -277,7 +289,7 @@ To disable all inline config comments, use the `noInlineConfig` setting. For exa
}
```

This setting is similar to [--no-inline-config](../command-line-interface#--no-inline-config) CLI option.
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.

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

Expand Down

0 comments on commit b92b30f

Please sign in to comment.