Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit a8d38d8

Browse files
authored
fix: Add declaration-property-unit-whitelist rule to enforce unitless line-height values. (#133)
1 parent 505692e commit a8d38d8

File tree

6 files changed

+93
-27
lines changed

6 files changed

+93
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# HEAD
22

3+
- Added: `declaration-property-unit-whitelist` rule to enforce unitless `line-height` values.
34
- Changed: Relocated repo to https://github.com/WordPress-Coding-Standards
45

56
# 10.0.2

__tests__/selectors.js

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ describe("flags warnings with invalid selectors css", () => {
4646
))
4747
})
4848

49-
it("flags two warnings", () => {
49+
it("flags warnings", () => {
5050
return result.then(data => (
51-
expect(data.results[0].warnings.length).toBe(2)
51+
expect(data.results[0].warnings.length).toBe(3)
5252
))
5353
})
5454

5555
it("correct first warning text", () => {
5656
return result.then(data => (
57-
expect(data.results[0].warnings[0].text).toBe("Selector should use lowercase and separate words with hyphens (selector-id-pattern)")
57+
expect(data.results[0].warnings[0].text).toBe("Unexpected unit \"%\" for property \"line-height\" (declaration-property-unit-whitelist)")
5858
))
5959
})
6060

6161
it("correct first warning rule flagged", () => {
6262
return result.then(data => (
63-
expect(data.results[0].warnings[0].rule).toBe("selector-id-pattern")
63+
expect(data.results[0].warnings[0].rule).toBe("declaration-property-unit-whitelist")
6464
))
6565
})
6666

@@ -72,25 +72,25 @@ describe("flags warnings with invalid selectors css", () => {
7272

7373
it("correct first warning line number", () => {
7474
return result.then(data => (
75-
expect(data.results[0].warnings[0].line).toBe(21)
75+
expect(data.results[0].warnings[0].line).toBe(18)
7676
))
7777
})
7878

7979
it("correct first warning column number", () => {
8080
return result.then(data => (
81-
expect(data.results[0].warnings[0].column).toBe(1)
81+
expect(data.results[0].warnings[0].column).toBe(15)
8282
))
8383
})
8484

8585
it("correct second warning text", () => {
8686
return result.then(data => (
87-
expect(data.results[0].warnings[1].text).toBe("Expected double quotes (string-quotes)")
87+
expect(data.results[0].warnings[1].text).toBe("Selector should use lowercase and separate words with hyphens (selector-id-pattern)")
8888
))
8989
})
9090

9191
it("correct second warning rule flagged", () => {
9292
return result.then(data => (
93-
expect(data.results[0].warnings[1].rule).toBe("string-quotes")
93+
expect(data.results[0].warnings[1].rule).toBe("selector-id-pattern")
9494
))
9595
})
9696

@@ -102,13 +102,43 @@ describe("flags warnings with invalid selectors css", () => {
102102

103103
it("correct second warning line number", () => {
104104
return result.then(data => (
105-
expect(data.results[0].warnings[1].line).toBe(17)
105+
expect(data.results[0].warnings[1].line).toBe(21)
106106
))
107107
})
108108

109109
it("correct second warning column number", () => {
110110
return result.then(data => (
111-
expect(data.results[0].warnings[1].column).toBe(12)
111+
expect(data.results[0].warnings[1].column).toBe(1)
112+
))
113+
})
114+
115+
it("correct third warning text", () => {
116+
return result.then(data => (
117+
expect(data.results[0].warnings[2].text).toBe("Expected double quotes (string-quotes)")
118+
))
119+
})
120+
121+
it("correct third warning rule flagged", () => {
122+
return result.then(data => (
123+
expect(data.results[0].warnings[2].rule).toBe("string-quotes")
124+
))
125+
})
126+
127+
it("correct third warning severity flagged", () => {
128+
return result.then(data => (
129+
expect(data.results[0].warnings[2].severity).toBe("error")
130+
))
131+
})
132+
133+
it("correct third warning line number", () => {
134+
return result.then(data => (
135+
expect(data.results[0].warnings[2].line).toBe(17)
136+
))
137+
})
138+
139+
it("correct third warning column number", () => {
140+
return result.then(data => (
141+
expect(data.results[0].warnings[2].column).toBe(12)
112142
))
113143
})
114144
})

__tests__/values-invalid.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
.class {
1010
font-family: Times New Roman, serif; /* Quote font names when required */
1111
font-weight: bold; /* Avoid named font weights */
12+
line-height: 1.4em;
1213
}

__tests__/values-valid.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.class { /* Correct usage of zero values */
88
font-family: Georgia, serif;
99
font-weight: bolder; /* Ignore relative font weights */
10+
line-height: 1.4;
1011
text-shadow:
1112
0 -1px 0 rgba(0, 0, 0, 0.5),
1213
0 1px 0 #fff;

__tests__/values.js

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ describe("flags warnings with invalid values css", () => {
4646
))
4747
})
4848

49-
it("flags eight warnings", () => {
49+
it("flags warnings", () => {
5050
return result.then(data => (
51-
expect(data.results[0].warnings.length).toBe(8)
51+
expect(data.results[0].warnings.length).toBe(9)
5252
))
5353
})
5454

@@ -114,13 +114,13 @@ describe("flags warnings with invalid values css", () => {
114114

115115
it("correct third warning text", () => {
116116
return result.then(data => (
117-
expect(data.results[0].warnings[2].text).toBe("Expected quotes around \"Times New Roman\" (font-family-name-quotes)")
117+
expect(data.results[0].warnings[2].text).toBe("Unexpected unit \"em\" for property \"line-height\" (declaration-property-unit-whitelist)")
118118
))
119119
})
120120

121121
it("correct third warning rule flagged", () => {
122122
return result.then(data => (
123-
expect(data.results[0].warnings[2].rule).toBe("font-family-name-quotes")
123+
expect(data.results[0].warnings[2].rule).toBe("declaration-property-unit-whitelist")
124124
))
125125
})
126126

@@ -132,7 +132,7 @@ describe("flags warnings with invalid values css", () => {
132132

133133
it("correct third warning line number", () => {
134134
return result.then(data => (
135-
expect(data.results[0].warnings[2].line).toBe(10)
135+
expect(data.results[0].warnings[2].line).toBe(12)
136136
))
137137
})
138138

@@ -144,13 +144,13 @@ describe("flags warnings with invalid values css", () => {
144144

145145
it("correct forth warning text", () => {
146146
return result.then(data => (
147-
expect(data.results[0].warnings[3].text).toBe("Expected numeric font-weight notation (font-weight-notation)")
147+
expect(data.results[0].warnings[3].text).toBe("Expected quotes around \"Times New Roman\" (font-family-name-quotes)")
148148
))
149149
})
150150

151151
it("correct forth warning rule flagged", () => {
152152
return result.then(data => (
153-
expect(data.results[0].warnings[3].rule).toBe("font-weight-notation")
153+
expect(data.results[0].warnings[3].rule).toBe("font-family-name-quotes")
154154
))
155155
})
156156

@@ -162,7 +162,7 @@ describe("flags warnings with invalid values css", () => {
162162

163163
it("correct forth warning line number", () => {
164164
return result.then(data => (
165-
expect(data.results[0].warnings[3].line).toBe(11)
165+
expect(data.results[0].warnings[3].line).toBe(10)
166166
))
167167
})
168168

@@ -174,13 +174,13 @@ describe("flags warnings with invalid values css", () => {
174174

175175
it("correct fifth warning text", () => {
176176
return result.then(data => (
177-
expect(data.results[0].warnings[4].text).toBe("Unexpected unit (length-zero-no-unit)")
177+
expect(data.results[0].warnings[4].text).toBe("Expected numeric font-weight notation (font-weight-notation)")
178178
))
179179
})
180180

181181
it("correct fifth warning rule flagged", () => {
182182
return result.then(data => (
183-
expect(data.results[0].warnings[4].rule).toBe("length-zero-no-unit")
183+
expect(data.results[0].warnings[4].rule).toBe("font-weight-notation")
184184
))
185185
})
186186

@@ -192,13 +192,13 @@ describe("flags warnings with invalid values css", () => {
192192

193193
it("correct fifth warning line number", () => {
194194
return result.then(data => (
195-
expect(data.results[0].warnings[4].line).toBe(6)
195+
expect(data.results[0].warnings[4].line).toBe(11)
196196
))
197197
})
198198

199199
it("correct fifth warning column number", () => {
200200
return result.then(data => (
201-
expect(data.results[0].warnings[4].column).toBe(11)
201+
expect(data.results[0].warnings[4].column).toBe(15)
202202
))
203203
})
204204

@@ -228,7 +228,7 @@ describe("flags warnings with invalid values css", () => {
228228

229229
it("correct sixth warning column number", () => {
230230
return result.then(data => (
231-
expect(data.results[0].warnings[5].column).toBe(15)
231+
expect(data.results[0].warnings[5].column).toBe(11)
232232
))
233233
})
234234

@@ -258,19 +258,19 @@ describe("flags warnings with invalid values css", () => {
258258

259259
it("correct seventh warning column number", () => {
260260
return result.then(data => (
261-
expect(data.results[0].warnings[6].column).toBe(24)
261+
expect(data.results[0].warnings[6].column).toBe(15)
262262
))
263263
})
264264

265265
it("correct eighth warning text", () => {
266266
return result.then(data => (
267-
expect(data.results[0].warnings[7].text).toBe("Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)")
267+
expect(data.results[0].warnings[7].text).toBe("Unexpected unit (length-zero-no-unit)")
268268
))
269269
})
270270

271271
it("correct eighth warning rule flagged", () => {
272272
return result.then(data => (
273-
expect(data.results[0].warnings[7].rule).toBe("shorthand-property-no-redundant-values")
273+
expect(data.results[0].warnings[7].rule).toBe("length-zero-no-unit")
274274
))
275275
})
276276

@@ -288,7 +288,37 @@ describe("flags warnings with invalid values css", () => {
288288

289289
it("correct eighth warning column number", () => {
290290
return result.then(data => (
291-
expect(data.results[0].warnings[7].column).toBe(2)
291+
expect(data.results[0].warnings[7].column).toBe(24)
292+
))
293+
})
294+
295+
it("correct ninth warning text", () => {
296+
return result.then(data => (
297+
expect(data.results[0].warnings[8].text).toBe("Unexpected longhand value '0px 0px 20px 0px' instead of '0px 0px 20px' (shorthand-property-no-redundant-values)")
298+
))
299+
})
300+
301+
it("correct ninth warning rule flagged", () => {
302+
return result.then(data => (
303+
expect(data.results[0].warnings[8].rule).toBe("shorthand-property-no-redundant-values")
304+
))
305+
})
306+
307+
it("correct ninth warning severity flagged", () => {
308+
return result.then(data => (
309+
expect(data.results[0].warnings[8].severity).toBe("error")
310+
))
311+
})
312+
313+
it("correct ninth warning line number", () => {
314+
return result.then(data => (
315+
expect(data.results[0].warnings[8].line).toBe(6)
316+
))
317+
})
318+
319+
it("correct ninth warning column number", () => {
320+
return result.then(data => (
321+
expect(data.results[0].warnings[8].column).toBe(2)
292322
))
293323
})
294324
})

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ module.exports = {
3333
"declaration-colon-newline-after": "always-multi-line",
3434
"declaration-colon-space-after": "always-single-line",
3535
"declaration-colon-space-before": "never",
36+
"declaration-property-unit-whitelist": {
37+
"line-height": [],
38+
},
3639
"font-family-name-quotes": "always-where-recommended",
3740
"font-weight-notation": [ "numeric", {
3841
ignore: ["relative"],

0 commit comments

Comments
 (0)