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

Add no-irregular-whitespace #5209

Merged
merged 7 commits into from Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user-guide/rules/list.md
Expand Up @@ -395,3 +395,4 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
- [`no-missing-end-of-source-newline`](../../../lib/rules/no-missing-end-of-source-newline/README.md): Disallow missing end-of-source newlines (Autofixable).
- [`no-empty-first-line`](../../../lib/rules/no-empty-first-line/README.md): Disallow empty first lines (Autofixable).
- [`unicode-bom`](../../../lib/rules/unicode-bom/README.md): Require or disallow Unicode BOM.
- [`no-irregular-whitespace`](../../../lib/rules/no-irregular-whitespace/README.md): Disallow irregular whitespace.
1 change: 1 addition & 0 deletions lib/rules/index.js
Expand Up @@ -245,6 +245,7 @@ const rules = {
'no-invalid-position-at-import-rule': importLazy(() =>
require('./no-invalid-position-at-import-rule'),
)(),
'no-irregular-whitespace': importLazy(() => require('./no-irregular-whitespace'))(),
'no-missing-end-of-source-newline': importLazy(() =>
require('./no-missing-end-of-source-newline'),
)(),
Expand Down
114 changes: 114 additions & 0 deletions lib/rules/no-irregular-whitespace/README.md
@@ -0,0 +1,114 @@
# no-irregular-whitespace

Disallow irregular whitespace
itutto marked this conversation as resolved.
Show resolved Hide resolved

<!-- prettier-ignore -->
```css
.firstClass .secondClass {}
/************* ↑
* Irregular whitespace. Selector would fail to match '.firstClass' */
itutto marked this conversation as resolved.
Show resolved Hide resolved
```

## Options

### `true`

The following patterns are considered violations:

<!-- prettier-ignore -->
```css
.firstClass .secondClass {}
itutto marked this conversation as resolved.
Show resolved Hide resolved
```

The following patterns are _not_ considered violations:

<!-- prettier-ignore -->
```css
.firstClass .secondClass { /* Writing comments with irregular whitespaces */ }
itutto marked this conversation as resolved.
Show resolved Hide resolved
```

## Optional secondary options

### `allow: ["\u0085"]`

The members of the array will be ignored by the rule

For example with `"/u180E"`

Given:

```
["/u180E"]
```

The following pattern are considered violation:

<!-- prettier-ignore -->
```css
a[title="irregular' + '\u00A0' + 'whitespace"] { color: pink; }
```

The following pattern is _not_ considered violation:

<!-- prettier-ignore -->
```css
a[title="irregular' + '\u180E' + 'whitespace"] { color: pink; }
```

### `only: ["\00A0"]`

Only the members of the array will detected by the rule (see `Unicode reference of irregular whitespaces`)

For example with `"/00A0"`

Given:

```
["/00A0"]
```

The following pattern are considered violation:

<!-- prettier-ignore -->
```css
a[title="irregular' + '\u00A0' + 'whitespace"] { color: pink; }
```

The following patterns is _not_ considered violation:

<!-- prettier-ignore -->
```css
a[title="irregular' + '\u180E' + 'whitespace"] { color: pink; }
```

<!-- prettier-ignore -->
```css
a[title="irregular' + '\u2002' + 'whitespace"] { color: pink; }
```

## Unicode reference of irregular whitespaces

\u000B - Line Tabulation (\v) - <VT>
\u000C - Form Feed (\f) - <FF>
\u00A0 - No-Break Space - <NBSP>
\u0085 - Next Line
\u1680 - Ogham Space Mark
\u180E - Mongolian Vowel Separator - <MVS>
\ufeff - Zero Width No-Break Space - <BOM>
\u2000 - En Quad
\u2001 - Em Quad
\u2002 - En Space - <ENSP>
\u2003 - Em Space - <EMSP>
\u2004 - Tree-Per-Em
\u2005 - Four-Per-Em
\u2006 - Six-Per-Em
\u2007 - Figure Space
\u2008 - Punctuation Space - <PUNCSP>
\u2009 - Thin Space
\u200A - Hair Space
\u200B - Zero Width Space - <ZWSP>
\u2028 - Line Separator
\u2029 - Paragraph Separator
\u202F - Narrow No-Break Space
\u205f - Medium Mathematical Space
\u3000 - Ideographic Space
itutto marked this conversation as resolved.
Show resolved Hide resolved