-
-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add media-feature-range-notation (#6497)
Co-authored-by: sidverma32 <[email protected]> Co-authored-by: Masafumi Koba <[email protected]>
- Loading branch information
1 parent
1916118
commit 042050d
Showing
7 changed files
with
359 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": minor | ||
--- | ||
|
||
Added: `media-feature-range-notation` rule |
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
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,74 @@ | ||
# media-feature-range-notation | ||
|
||
Specify context or prefix notation for media feature ranges. | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (width >= 600px) and (min-width: 600px) {} | ||
/** ↑ ↑ | ||
* These media feature notations */ | ||
``` | ||
|
||
Media features of the range type can be written using prefixes or the more modern context notation. | ||
|
||
Because `min-` and `max-` both equate to range comparisons that include the value, they may be [limiting in certain situations](https://drafts.csswg.org/mediaqueries/#mq-min-max). | ||
|
||
## Options | ||
|
||
`string`: `"context"|"prefix"` | ||
|
||
### `"context"` | ||
|
||
Media feature ranges _must always_ use context notation. | ||
|
||
The following patterns are considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (min-width: 1px) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (min-width: 1px) and (max-width: 2px) {} | ||
``` | ||
|
||
The following patterns are _not_ considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (width >= 1px) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (1px <= width <= 2px) {} | ||
``` | ||
|
||
### `"prefix"` | ||
|
||
Media feature ranges _must always_ use prefix notation. | ||
|
||
The following patterns are considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (width >= 1px) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (1px <= width <= 2px) {} | ||
``` | ||
|
||
The following patterns are _not_ considered problems: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (min-width: 1px) {} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@media (min-width: 1px) and (max-width: 2px) {} | ||
``` |
177 changes: 177 additions & 0 deletions
177
lib/rules/media-feature-range-notation/__tests__/index.js
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,177 @@ | ||
'use strict'; | ||
|
||
const { stripIndent } = require('common-tags'); | ||
|
||
const { messages, ruleName } = require('..'); | ||
|
||
testRule({ | ||
ruleName, | ||
config: ['context'], | ||
|
||
accept: [ | ||
{ | ||
code: '@media {}', | ||
description: 'empty media query', | ||
}, | ||
{ | ||
code: '@media () {}', | ||
description: 'empty media feature', | ||
}, | ||
{ | ||
code: '@media screen {}', | ||
description: 'keyword', | ||
}, | ||
{ | ||
code: '@media (color) {}', | ||
description: 'range type media feature in boolean context', | ||
}, | ||
{ | ||
code: '@media (color > 0) {}', | ||
description: 'range type media feature in non-boolean context', | ||
}, | ||
{ | ||
code: '@media (pointer: fine) {}', | ||
description: 'discrete type media feature', | ||
}, | ||
{ | ||
code: '@media (width >= 1px) {}', | ||
description: 'range type media feature in context notation', | ||
}, | ||
{ | ||
code: '@media screen and (width >= 1px) {}', | ||
description: 'range type media feature in context notation with keyword', | ||
}, | ||
{ | ||
code: '@media not print, (width >= 1px) {}', | ||
description: 'range type media feature in context notation in media query list', | ||
}, | ||
{ | ||
code: '@media (1px <= width <= 2px) {}', | ||
description: 'range type media feature in context notation with two values', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: '@media (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation', | ||
message: messages.expected('context'), | ||
line: 1, | ||
column: 8, | ||
endLine: 1, | ||
endColumn: 24, | ||
}, | ||
{ | ||
code: '@media screen and (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation with keyword', | ||
message: messages.expected('context'), | ||
line: 1, | ||
column: 19, | ||
endLine: 1, | ||
endColumn: 35, | ||
}, | ||
{ | ||
code: '@media not print, (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation in media query list', | ||
message: messages.expected('context'), | ||
line: 1, | ||
column: 19, | ||
endLine: 1, | ||
endColumn: 35, | ||
}, | ||
{ | ||
code: stripIndent` | ||
@media (min-width: 1px) | ||
and (max-width: 2px) {} | ||
`, | ||
description: 'two range type media features in prefix notation', | ||
warnings: [ | ||
{ message: messages.expected('context'), line: 1, column: 8, endLine: 1, endColumn: 24 }, | ||
{ message: messages.expected('context'), line: 2, column: 7, endLine: 2, endColumn: 23 }, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
testRule({ | ||
ruleName, | ||
config: ['prefix'], | ||
|
||
accept: [ | ||
{ | ||
code: '@media {}', | ||
description: 'empty media query', | ||
}, | ||
{ | ||
code: '@media () {}', | ||
description: 'empty media feature', | ||
}, | ||
{ | ||
code: '@media screen {}', | ||
description: 'keyword', | ||
}, | ||
{ | ||
code: '@media (color) {}', | ||
description: 'range type media feature in boolean context', | ||
}, | ||
{ | ||
code: '@media (min-color: 1) {}', | ||
description: 'range type media feature in non-boolean context', | ||
}, | ||
{ | ||
code: '@media (pointer: fine) {}', | ||
description: 'discrete type media query', | ||
}, | ||
{ | ||
code: '@media (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation', | ||
}, | ||
{ | ||
code: '@media screen and (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation with keyword', | ||
}, | ||
{ | ||
code: '@media not print, (min-width: 1px) {}', | ||
description: 'range type media feature in prefix notation in media query list', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: '@media (width >= 1px) {}', | ||
description: 'range type media feature in context notation', | ||
message: messages.expected('prefix'), | ||
line: 1, | ||
column: 8, | ||
endLine: 1, | ||
endColumn: 22, | ||
}, | ||
{ | ||
code: '@media screen and (width >= 1px) {}', | ||
description: 'range type media feature in context notation with keyword', | ||
message: messages.expected('prefix'), | ||
line: 1, | ||
column: 19, | ||
endLine: 1, | ||
endColumn: 33, | ||
}, | ||
{ | ||
code: '@media not print, (width >= 1px) {}', | ||
description: 'range type media feature in context notation in media query list', | ||
message: messages.expected('prefix'), | ||
line: 1, | ||
column: 19, | ||
endLine: 1, | ||
endColumn: 33, | ||
}, | ||
{ | ||
code: '@media (1px < width <= 2px) {}', | ||
description: 'range type media feature in context notation with two values', | ||
message: messages.expected('prefix'), | ||
line: 1, | ||
column: 8, | ||
endLine: 1, | ||
endColumn: 28, | ||
}, | ||
], | ||
}); |
Oops, something went wrong.