Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document errors and warnings better #6426

Merged
merged 4 commits into from
Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions docs/user-guide/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,97 @@ In addition to rule problems, Stylelint surfaces the following errors and warnin

## CSS syntax error

The chosen [PostCSS syntax](usage/options.md#customsyntax) was unable to parse the source.
The CSS parser built into Stylelint, or the chosen [custom syntax](usage/options.md#customsyntax), could not parse your code.

### Unclosed block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] The CSSSyntaxError includes a message, e.g. this demo. I've used those messages as heading within this section so that:

  • they're easier to search for
  • we can give specific advice on how to resolve the issue


You should balance your _curly braces_, typically of _declaration blocks_.

For example:

```diff css
- a { color: red;
+ a { color: red; }
```

### Unclosed bracket

You should balance your _square brackets_, typically of _attribute selectors_ and _grid names_.

For example:

```diff css
- a[foo { grid: [bar; }
+ a[foo] { grid: [bar]; }
```

### Unclosed string

You should balance your _quotation marks_.

For example:

```diff css
- a { content: " }
+ a { content: "" }
```

### Unknown word

You should:

- hyphenate _properties_
- separate _property and value pairs_ with _colons_
- separate _declarations_ with _semicolons_
- pair _selectors_ with _declaration blocks_ in _rules_

For example:

```diff css
a {
- margin top: 1px
- color red
+ margin-top: 1px;
+ color: red
}
```

## Parse error

The chosen [PostCSS syntax](usage/options.md#customsyntax) successfully parsed, but one of the construct-specific parsers failed to parse either a media query, selector or value within that source.
The CSS parser built into Stylelint (or the chosen [custom syntax](usage/options.md#customsyntax)) successfully parsed your code, but one of the construct-specific parsers failed to parse either a media query, selector or value within that source.

The construct-specific parsers are:

- `postcss-media-query-parser`
- `postcss-selector-parser`
- `postcss-value-parser`

You should check that your constructs are wellformed, e.g. parentheses are balanced.

## Unknown rule error

There is an unknown rule in the [configuration object](configure.md).

You should:

- install the latest version of Stylelint (`npm i --save-dev stylelint`), as we may have recently added the rule
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Note] Judging by the historical issues raised, it's usually an outdated version of Stylelint causing this error and the invalid option warning.

- check that the rule exists and is correctly named by searching the [list of rules](rules.md)

## Deprecation warning

There is a deprecated rule in the [configuration object](configure.md).

You should:

- identify in the [CHANGELOG](../../CHANGELOG.md) which release deprecated the rule
- take the action suggested there

## Invalid option warning

There is a misconfigured rule in the [configuration object](configure.md).

You should:

- install the latest version of Stylelint (`npm i --save-dev stylelint`), as we may have recently added the option
- check that the option exists and is correctly named by reading the rule's README
- correctly configure the [`rules`](configure.md#rules) property in the configuration object