/
index.js
195 lines (181 loc) · 3.83 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
'use strict';
const standalone = require('../../../standalone');
const { messages, ruleName } = require('..');
it('warns that the rule is deprecated', () => {
const config = {
rules: {
[ruleName]: [{ margin: ['em'] }],
},
};
const code = '';
return standalone({ code, config }).then((output) => {
const result = output.results[0];
expect(result.deprecations).toHaveLength(1);
expect(result.deprecations[0].text).toEqual(
`'${ruleName}' has been deprecated. Instead use 'declaration-property-unit-disallowed-list'.`,
);
expect(result.deprecations[0].reference).toEqual(
`https://stylelint.io/user-guide/rules/${ruleName}/`,
);
});
});
testRule({
ruleName,
config: [
{
'font-size': ['px', 'em'],
margin: ['em'],
'background-position': ['%'],
animation: ['s'],
},
],
accept: [
{
code: 'a { color: pink; }',
},
{
code: 'a { top: 0; }',
},
{
code: 'a { color: #000; }',
},
{
code: 'a { margin: 0 0 0 0 }',
},
{
code: 'a { margin: 0 10px 5rem 2in; }',
},
{
code: 'a { margin: 0 10pX 5rem 2in; }',
},
{
code: 'a { margin: 0 10PX 5rem 2in; }',
},
{
code: 'a { background-position: top right, 1em 5vh; }',
},
{
code: 'a { margin: calc(30vh - 10vh); }',
},
{
code: 'a { animation: animation-name 300ms ease; }',
},
{
code: 'a { -webkit-animation: animation-name 300ms ease; }',
},
{
code: 'a { animation-duration: 3s; }',
},
{
code: 'a { -webkit-animation-duration: 3s; }',
},
{
code: 'a { font-size: /* 100px */ 1.2rem; }',
description: 'ignore unit within comments',
},
{
code: 'a::before { font-size: "10px"}',
description: 'ignore unit within quotes',
},
{
code: 'a { font-size: $fs10px; }',
description: 'ignore preprocessor variable includes unit',
},
{
code: 'a { font-size: --some-fs-10px; }',
description: 'ignore css variable includes unit',
},
],
reject: [
{
code: 'a { font-size: 12px; }',
message: messages.rejected('font-size', 'px'),
line: 1,
column: 16,
},
{
code: 'a { font-size: 12pX; }',
message: messages.rejected('font-size', 'pX'),
line: 1,
column: 16,
},
{
code: 'a { font-size: 12PX; }',
message: messages.rejected('font-size', 'PX'),
line: 1,
column: 16,
},
{
code: 'a { margin: 10px 0 5em; }',
message: messages.rejected('margin', 'em'),
line: 1,
column: 20,
},
{
code: 'a { background-position: 0 10%; }',
message: messages.rejected('background-position', '%'),
line: 1,
column: 28,
},
{
code: 'a { background-position: top right, 0 10%; }',
message: messages.rejected('background-position', '%'),
line: 1,
column: 39,
},
{
code: 'a { margin: calc(10vh - 10em); }',
message: messages.rejected('margin', 'em'),
column: 25,
},
{
code: 'a { animation: foo 3s; }',
message: messages.rejected('animation', 's'),
},
{
code: 'a { -webkit-animation: foo 3s; }',
message: messages.rejected('-webkit-animation', 's'),
},
],
});
testRule({
ruleName,
config: [
{
'/^animation/': ['s'],
},
],
skipBasicChecks: true,
accept: [
{
code: 'a { animation: animation-name 300ms ease; }',
},
{
code: 'a { -webkit-animation: animation-name 300ms ease; }',
},
{
code: 'a { animation-duration: 300ms; }',
},
{
code: 'a { -webkit-animation-duration: 300ms; }',
},
],
reject: [
{
code: 'a { animation: animation-name 3s ease; }',
message: messages.rejected('animation', 's'),
},
{
code: 'a { -webkit-animation: animation-name 3s ease; }',
message: messages.rejected('-webkit-animation', 's'),
},
{
code: 'a { animation-duration: 3s; }',
message: messages.rejected('animation-duration', 's'),
},
{
code: 'a { -webkit-animation-duration: 3s; }',
message: messages.rejected('-webkit-animation-duration', 's'),
},
],
});