-
-
Notifications
You must be signed in to change notification settings - Fork 929
/
index.js
196 lines (192 loc) · 4.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
const { messages, ruleName } = require('..');
testRule({
ruleName,
config: [true],
accept: [
{
code: '@media screen and (min-width: 768px) {}',
description: 'Basic media feature',
},
{
code: '@media screen and (min-width: 0) {}',
description: 'Length of zero, without a unit',
},
{
code: '@media screen and ( min-resolution : 2dpcm ) {}',
description: 'A resolution',
},
{
code: '@media screen and ( -moz-min-resolution : 2dpcm ) {}',
description: 'A resolution with a vendor prefix',
},
{
code: '@media screen and (resolution: 10.1dpcm) {}',
description: 'A resolution with a floating point value',
},
{
code: '@media screen and (min-width: $sm) {}',
description: 'Non-standard syntax is not checked by this rule',
},
{
code: '@media (color) {}',
description: 'Boolean context',
},
{
code: '@media (color : 1) {}',
description: 'Integer value',
},
{
code: '@media (aspect-ratio : 1 / 1) {}',
description: 'Aspect ratio value',
},
{
code: '@media (aspect-ratio : 1.2) {}',
description: 'Float value for aspect ratio',
},
{
code: '@media (aspect-ratio : 1 / calc(Pi)) {}',
description: 'Math expression in aspect ratio',
},
{
code: '@media (width: max(sin(90deg) * 10px, 100px)) {}',
description: 'Math expression in length',
},
{
code: '@media screen and (min-width <= 768px) {}',
description: 'Range context, media feature in allowed list',
},
{
code: '@media (hover: #foo) {}',
description: 'General enclosed because hash tokens are invalid syntax',
},
{
code: '@media (hover: 10%) {}',
description: 'General enclosed because percentage tokens are invalid syntax',
},
{
code: '@media screen and (min-width: env(some-width-variable)) and (hover: env(some-width-variable)) and (aspect-ratio < env(some-number-variable) / 100) {}',
description: 'Environment variables',
},
{
code: '@media (-webkit-hover: -webkit-hover) {}',
description: 'Double vendor prefixes when valid',
},
{
code: '@media (foo: 100px) {}',
description: 'Unknown media feature',
},
],
reject: [
{
code: '@media screen and (min-width: 1000khz) {}',
description: 'Frequency value when only lengths are allowed',
message: messages.rejected('min-width', '1000khz'),
line: 1,
column: 31,
endLine: 1,
endColumn: 37,
},
{
code: '@media screen and (width <= 1000khz) {}',
description: 'Frequency value when only lengths are allowed in a range context',
message: messages.rejected('width', '1000khz'),
line: 1,
column: 29,
endLine: 1,
endColumn: 35,
},
{
code: '@media screen and (-webkit-width = 1000khz) {}',
description: 'Validates vendor-prefixed media features',
message: messages.rejected('-webkit-width', '1000khz'),
line: 1,
column: 36,
endLine: 1,
endColumn: 42,
},
{
code: '@media (-webkit-hover: -webkit-pointer) {}',
description: 'Double vendor prefixes when invalid',
message: messages.rejected('-webkit-hover', '-webkit-pointer'),
line: 1,
column: 24,
endLine: 1,
endColumn: 38,
},
{
code: '@media (color: 1.1) {}',
description: 'Float value when only integers are allowed',
message: messages.rejected('color', '1.1'),
line: 1,
column: 16,
endLine: 1,
endColumn: 18,
},
{
code: '@media (color: 1 / 1) {}',
description: 'Aspect ratio value when only integers are allowed',
message: messages.rejected('color', '1 / 1'),
line: 1,
column: 16,
endLine: 1,
endColumn: 20,
},
{
code: '@media (hover: 15) {}',
description: 'Integer when only keywords are allowed',
message: messages.rejected('hover', '15'),
line: 1,
column: 16,
endLine: 1,
endColumn: 17,
},
{
code: '@media (width: 15) {}',
description: 'Integer when only lengths are allowed',
message: messages.rejected('width', '15'),
line: 1,
column: 16,
endLine: 1,
endColumn: 17,
},
{
code: '@media (hover: 10px) {}',
description: 'Dimension when only keywords are allowed',
message: messages.rejected('hover', '10px'),
line: 1,
column: 16,
endLine: 1,
endColumn: 19,
},
{
code: '@media (hover: sin(90deg)) {}',
description: 'Math expressions when only keywords are allowed',
message: messages.rejected('hover', 'sin(90deg)'),
line: 1,
column: 16,
endLine: 1,
endColumn: 25,
},
{
code: '@media (color: purple) and (hover: pointer) {}',
description: 'Incorrect keywords',
warnings: [
{
message: messages.rejected('color', 'purple'),
line: 1,
column: 16,
endLine: 1,
endColumn: 21,
},
{
message: messages.rejected('hover', 'pointer'),
line: 1,
column: 36,
endLine: 1,
endColumn: 42,
},
],
},
],
});