Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
391 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# selector-not-notation | ||
|
||
Specify simple or complex notation for `:not()` pseudo-classes. | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
a:not(.foo, .bar) {} | ||
/** ↑ | ||
* This notation */ | ||
``` | ||
|
||
In Selectors Level 3, only a single _simple selector_ was allowed as the argument to `:not()`, whereas Selectors Level 4 allows a _selector list_. | ||
|
||
Use: | ||
|
||
- `"complex"` to author modern Selectors Level 4 CSS | ||
- `"simple"` for backwards compatibility with older browsers | ||
|
||
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) option can automatically fix most of the problems reported by this rule. | ||
|
||
## Options | ||
|
||
`string`: `"simple"|"complex"` | ||
|
||
### `"simple"` | ||
|
||
The following patterns are considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a, div) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a.foo) {} | ||
``` | ||
|
||
The following patterns are _not_ considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a):not(div) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a) {} | ||
``` | ||
|
||
### `"complex"` | ||
|
||
The following pattern is considered a problem: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a):not(div) {} | ||
``` | ||
|
||
The following patterns are _not_ considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a, div) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a.foo) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
:not(a).foo:not(:empty) {} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
'use strict'; | ||
|
||
const { messages, ruleName } = require('..'); | ||
|
||
testRule({ | ||
ruleName, | ||
config: ['simple'], | ||
fix: true, | ||
|
||
accept: [ | ||
{ | ||
code: ':not() {}', | ||
}, | ||
{ | ||
code: ':not( a ) {}', | ||
}, | ||
{ | ||
code: ':nOt(a) {}', | ||
}, | ||
{ | ||
code: ':not(*) {}', | ||
}, | ||
{ | ||
code: ':not(:link) {}', | ||
}, | ||
{ | ||
code: ':not(.foo) {}', | ||
}, | ||
{ | ||
code: ':not([title]) {}', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: ':not(:not()) {}', | ||
unfixable: true, | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
{ | ||
code: ':not(::before) {}', | ||
unfixable: true, | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
{ | ||
code: ':not(:first-line) {}', | ||
unfixable: true, | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
{ | ||
code: ':not(a, div) {}', | ||
fixed: ':not(a):not(div) {}', | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
{ | ||
code: ':not(a ,) {}', | ||
fixed: ':not(a) {}', | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
{ | ||
code: ':not(a.foo) {}', | ||
unfixable: true, | ||
message: messages.expected('simple'), | ||
line: 1, | ||
column: 1, | ||
}, | ||
], | ||
}); | ||
|
||
testRule({ | ||
ruleName, | ||
config: ['complex'], | ||
fix: true, | ||
|
||
accept: [ | ||
{ | ||
code: ':not()::after {}', | ||
}, | ||
{ | ||
code: ':not(a, div) {}', | ||
}, | ||
{ | ||
code: ':not(a.foo) {}', | ||
}, | ||
{ | ||
code: ':not(a).foo:not(:empty) {}', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: ':not( .foo ,:hover ):not(a,div) {}', | ||
fixed: ':not(.foo, :hover, a, div) {}', | ||
message: messages.expected('complex'), | ||
line: 1, | ||
column: 21, | ||
}, | ||
{ | ||
code: ':not():not(a) {}', | ||
fixed: ':not(a) {}', | ||
message: messages.expected('complex'), | ||
line: 1, | ||
column: 7, | ||
skip: true, | ||
}, | ||
], | ||
}); |
Oops, something went wrong.