-
Notifications
You must be signed in to change notification settings - Fork 22
/
spacing.js
176 lines (175 loc) · 6.03 KB
/
spacing.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
import {ruleName} from '../plugins/spacing.js'
testRule({
plugins: ['./plugins/spacing'],
customSyntax: 'postcss-scss',
ruleName,
config: [true],
fix: true,
accept: [
{
code: '.x { padding: $spacer-4; }',
description: 'One variable is valid.',
},
{
code: '.x { padding: $spacer-4 $spacer-3; }',
description: 'Two variables are valid.',
},
{
code: '.x { padding: 0 0; }',
description: 'Ignore zero values.',
},
{
code: '.x { margin: auto; }',
description: 'Ignore auto values.',
},
{
code: '.x { padding: calc($spacer-4 * 2); }',
description: 'Finds variable calc values.',
},
{
code: '.x { padding: calc(#{$spacer-4} * 2); }',
description: 'Finds interpolated calc values.',
},
{
code: '.x { padding: $spacer-1; .y { padding: $spacer-1; } }',
description: 'Nested css works.',
},
],
reject: [
{
code: '.x { padding-bottom: 0.3em; }',
unfixable: true,
message:
"Please use a primer spacer variable instead of '0.3em'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
line: 1,
column: 22,
description: 'Errors on non-spacer em values.',
},
{
code: '.x { padding: 4px; }',
fixed: '.x { padding: $spacer-1; }',
message: `Please replace 4px with spacing variable '$spacer-1'. (primer/spacing)`,
line: 1,
column: 15,
description: "Replaces '4px' with '$spacer-1'.",
},
{
code: '.x { padding: 0.5em; }',
fixed: '.x { padding: $em-spacer-5; }',
message: `Please replace 0.5em with spacing variable '$em-spacer-5'. (primer/spacing)`,
line: 1,
column: 15,
description: "Replaces '0.5em' with '$em-spacer-5'.",
},
{
code: '.x { padding: -4px; }',
fixed: '.x { padding: -$spacer-1; }',
message: `Please replace 4px with spacing variable '$spacer-1'. (primer/spacing)`,
line: 1,
column: 15,
description: "Replaces '-4px' with '-$spacer-1'.",
},
{
code: '.x { padding: calc(8px * 2); }',
fixed: '.x { padding: calc($spacer-2 * 2); }',
description: 'Replaces "8px" with "$spacer-2" inside calc.',
message: `Please replace 8px with spacing variable '$spacer-2'. (primer/spacing)`,
line: 1,
column: 20,
},
{
code: '.x { padding: 6px ($spacer-3 + 12px + $spacer-2); }',
unfixable: true,
description: 'Complex calc expression.',
warnings: [
{
column: 15,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '6px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
{
column: 32,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '12px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
],
},
{
code: '.x { padding: 3px 4px; }',
fixed: '.x { padding: 3px $spacer-1; }',
description: "Replaces '4px' with '$spacer-1' and errors on '3px'.",
warnings: [
{
column: 15,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '3px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
{
column: 19,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message: "Please replace 4px with spacing variable '$spacer-1'. (primer/spacing)",
},
],
},
{
code: '.x { padding: $spacer-100; }',
unfixable: true,
message:
"Please use a primer spacer variable instead of '$spacer-100'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
line: 1,
column: 15,
description: 'Errors on non-primer spacer.',
},
{
code: '.x { margin-right: (-$spacing-task-item-1); }',
unfixable: true,
message:
"Please use a primer spacer variable instead of '-$spacing-task-item-1'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
line: 1,
column: 21,
description: 'Errors on non-primer spacer in parens.',
},
{
code: '.x { padding: 3px; .y { padding: 3px; .z { padding: 3px; } } }',
unfixable: true,
description: 'Rejects nested CSS.',
warnings: [
{
column: 15,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '3px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
{
column: 34,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '3px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
{
column: 53,
line: 1,
rule: 'primer/spacing',
severity: 'error',
message:
"Please use a primer spacer variable instead of '3px'. Consult the primer docs for a suitable replacement. https://primer.style/css/storybook/?path=/docs/support-spacing--docs (primer/spacing)",
},
],
},
],
})