@projectwallace/css-code-quality 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.test.js DELETED
@@ -1,391 +0,0 @@
1
- import * as assert from 'uvu/assert'
2
- import { suite } from 'uvu'
3
- import { calculate } from './index.js'
4
- import { calculate as pkgCalculate } from '../dist/css-code-quality.modern.js'
5
-
6
- const Index = suite('Index')
7
-
8
- Index('exposes a calculcate function', () => {
9
- assert.is(typeof calculate, 'function')
10
- })
11
-
12
- Index('smoke test', () => {
13
- let css = `
14
- @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
15
-
16
- .my_test,
17
- .my_extra_test {
18
- color: red;
19
- }
20
-
21
- #my_test {
22
- color: green;
23
- }
24
- `
25
- let result = calculate(css)
26
- assert.equal(result, {
27
- "score": 0,
28
- "violations": [
29
- {
30
- "id": "Imports",
31
- "score": 10,
32
- "value": 1,
33
- "actuals": [
34
- "url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap')"
35
- ]
36
- },
37
- {
38
- "id": "IdSelectorRatio",
39
- "score": 3,
40
- "value": 0.3333333333333333,
41
- "actuals": [
42
- "#my_test"
43
- ]
44
- }
45
- ],
46
- "passes": [
47
- {
48
- "id": "EmptyRules",
49
- "score": 0,
50
- "value": 0
51
- },
52
- {
53
- "id": "SelectorDuplications",
54
- "score": 0,
55
- "value": 0
56
- },
57
- {
58
- "id": "DeclarationDuplications",
59
- "score": 0,
60
- "value": 0
61
- },
62
- {
63
- "id": "CssSize",
64
- "score": 0,
65
- "value": 180
66
- },
67
- {
68
- "id": "TooMuchComments",
69
- "score": 0,
70
- "value": 0
71
- },
72
- {
73
- "id": "TooMuchEmbeddedContent",
74
- "score": 0,
75
- "value": 0,
76
- "actuals": []
77
- },
78
- {
79
- "id": "SourceLinesOfCode",
80
- "score": 0,
81
- "value": 6
82
- },
83
- {
84
- "id": "AverageSelectorsPerRule",
85
- "score": 0,
86
- "value": 1.5,
87
- "actuals": [
88
- 2,
89
- 1
90
- ]
91
- },
92
- {
93
- "id": "AverageDeclarationsPerRule",
94
- "score": 0,
95
- "value": 1,
96
- "actuals": [
97
- 1,
98
- 1
99
- ]
100
- },
101
- {
102
- "id": "MaxSelectorsPerRule",
103
- "score": 0,
104
- "value": 2,
105
- "actuals": [
106
- 2,
107
- 1
108
- ]
109
- },
110
- {
111
- "id": "MaxDeclarationsPerRule",
112
- "score": 0,
113
- "value": 1,
114
- "actuals": [
115
- 1,
116
- 1
117
- ]
118
- },
119
- {
120
- "id": "MoreThanMostCommonSelectorsPerRule",
121
- "score": 0,
122
- "value": 1.5,
123
- "actuals": [
124
- 2,
125
- 1
126
- ]
127
- },
128
- {
129
- "id": "MoreThanMostCommonDeclarationsPerRule",
130
- "score": 0,
131
- "value": 1,
132
- "actuals": [
133
- 1,
134
- 1
135
- ]
136
- },
137
- {
138
- "id": "MoreThanMostCommonSelectorComplexity",
139
- "score": 0,
140
- "value": 0,
141
- "actuals": [
142
- 1,
143
- 1,
144
- 1
145
- ]
146
- },
147
- {
148
- "id": "MoreThanMostCommonSelectorSpecificity",
149
- "score": 0,
150
- "value": 0.3333333333333333,
151
- "actuals": [
152
- [
153
- 0,
154
- 1,
155
- 0
156
- ],
157
- [
158
- 0,
159
- 1,
160
- 0
161
- ],
162
- [
163
- 1,
164
- 0,
165
- 0
166
- ]
167
- ]
168
- },
169
- {
170
- "id": "MaxSelectorComplexity",
171
- "score": 0,
172
- "value": 1,
173
- "actuals": [
174
- 1,
175
- 1,
176
- 1
177
- ]
178
- },
179
- {
180
- "id": "AverageSelectorComplexity",
181
- "score": 0,
182
- "value": 1,
183
- "actuals": [
184
- 1,
185
- 1,
186
- 1
187
- ]
188
- },
189
- {
190
- "id": "ImportantRatio",
191
- "score": 0,
192
- "value": 0,
193
- "actuals": 0
194
- }
195
- ],
196
- "performance": {
197
- "score": 90,
198
- "violations": [
199
- {
200
- "id": "Imports",
201
- "score": 10,
202
- "value": 1,
203
- "actuals": [
204
- "url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap')"
205
- ]
206
- }
207
- ],
208
- "passes": [
209
- {
210
- "id": "EmptyRules",
211
- "score": 0,
212
- "value": 0
213
- },
214
- {
215
- "id": "SelectorDuplications",
216
- "score": 0,
217
- "value": 0
218
- },
219
- {
220
- "id": "DeclarationDuplications",
221
- "score": 0,
222
- "value": 0
223
- },
224
- {
225
- "id": "CssSize",
226
- "score": 0,
227
- "value": 180
228
- },
229
- {
230
- "id": "TooMuchComments",
231
- "score": 0,
232
- "value": 0
233
- },
234
- {
235
- "id": "TooMuchEmbeddedContent",
236
- "score": 0,
237
- "value": 0,
238
- "actuals": []
239
- }
240
- ]
241
- },
242
- "maintainability": {
243
- "score": 100,
244
- "violations": [],
245
- "passes": [
246
- {
247
- "id": "SourceLinesOfCode",
248
- "score": 0,
249
- "value": 6
250
- },
251
- {
252
- "id": "AverageSelectorsPerRule",
253
- "score": 0,
254
- "value": 1.5,
255
- "actuals": [
256
- 2,
257
- 1
258
- ]
259
- },
260
- {
261
- "id": "AverageDeclarationsPerRule",
262
- "score": 0,
263
- "value": 1,
264
- "actuals": [
265
- 1,
266
- 1
267
- ]
268
- },
269
- {
270
- "id": "MaxSelectorsPerRule",
271
- "score": 0,
272
- "value": 2,
273
- "actuals": [
274
- 2,
275
- 1
276
- ]
277
- },
278
- {
279
- "id": "MaxDeclarationsPerRule",
280
- "score": 0,
281
- "value": 1,
282
- "actuals": [
283
- 1,
284
- 1
285
- ]
286
- },
287
- {
288
- "id": "MoreThanMostCommonSelectorsPerRule",
289
- "score": 0,
290
- "value": 1.5,
291
- "actuals": [
292
- 2,
293
- 1
294
- ]
295
- },
296
- {
297
- "id": "MoreThanMostCommonDeclarationsPerRule",
298
- "score": 0,
299
- "value": 1,
300
- "actuals": [
301
- 1,
302
- 1
303
- ]
304
- }
305
- ]
306
- },
307
- "complexity": {
308
- "score": 97,
309
- "violations": [
310
- {
311
- "id": "IdSelectorRatio",
312
- "score": 3,
313
- "value": 0.3333333333333333,
314
- "actuals": [
315
- "#my_test"
316
- ]
317
- }
318
- ],
319
- "passes": [
320
- {
321
- "id": "MoreThanMostCommonSelectorComplexity",
322
- "score": 0,
323
- "value": 0,
324
- "actuals": [
325
- 1,
326
- 1,
327
- 1
328
- ]
329
- },
330
- {
331
- "id": "MoreThanMostCommonSelectorSpecificity",
332
- "score": 0,
333
- "value": 0.3333333333333333,
334
- "actuals": [
335
- [
336
- 0,
337
- 1,
338
- 0
339
- ],
340
- [
341
- 0,
342
- 1,
343
- 0
344
- ],
345
- [
346
- 1,
347
- 0,
348
- 0
349
- ]
350
- ]
351
- },
352
- {
353
- "id": "MaxSelectorComplexity",
354
- "score": 0,
355
- "value": 1,
356
- "actuals": [
357
- 1,
358
- 1,
359
- 1
360
- ]
361
- },
362
- {
363
- "id": "AverageSelectorComplexity",
364
- "score": 0,
365
- "value": 1,
366
- "actuals": [
367
- 1,
368
- 1,
369
- 1
370
- ]
371
- },
372
- {
373
- "id": "ImportantRatio",
374
- "score": 0,
375
- "value": 0,
376
- "actuals": 0
377
- }
378
- ]
379
- }
380
- })
381
- })
382
-
383
- Index.run()
384
-
385
- const Package = suite('NPM Package')
386
-
387
- Package('exposes a calculate function', () => {
388
- assert.is(typeof pkgCalculate, 'function')
389
- })
390
-
391
- Package.run()
@@ -1,191 +0,0 @@
1
- import { suite } from 'uvu'
2
- import * as assert from 'uvu/assert'
3
- import { calculate } from './index.js'
4
-
5
- const Maintainability = suite('Maintainability')
6
-
7
- Maintainability('does not deduct points for 1 SLoC', () => {
8
- const actual = calculate(`test {}`)
9
- assert.is(actual.maintainability.score, 100)
10
- assert.is(actual.maintainability.violations.length, 0)
11
- })
12
-
13
- Maintainability('deducts points for having lots of SLoC', () => {
14
- const fixture = Array.from({ length: 10_000 })
15
- .fill('')
16
- .map((_, index) => `selector-${index} { opacity: 0.${index}}`)
17
- .join('')
18
- const actual = calculate(fixture)
19
-
20
- assert.is(actual.maintainability.score, 90)
21
- assert.equal(actual.maintainability.violations, [
22
- {
23
- id: 'SourceLinesOfCode',
24
- score: 10,
25
- value: 20_000,
26
- }
27
- ])
28
- })
29
-
30
- Maintainability('deducts no points for have few Selectors per RuleSet', () => {
31
- const actual = calculate(`
32
- test1 {}
33
-
34
- test2,
35
- test3 {}
36
- `)
37
-
38
- assert.is(actual.maintainability.score, 100)
39
- assert.is(actual.maintainability.violations.length, 0)
40
- })
41
-
42
- Maintainability('deducts points for having too many Selectors per RuleSet', () => {
43
- const actual = calculate(`
44
- test1,
45
- test2,
46
- test3,
47
- test3b {}
48
-
49
- test4,
50
- test5,
51
- test6,
52
- test7,
53
- test8 {}
54
- `)
55
-
56
- assert.is(actual.maintainability.score, 88)
57
- assert.equal(actual.maintainability.violations, [
58
- {
59
- id: 'AverageSelectorsPerRule',
60
- score: 12,
61
- value: 4.5,
62
- actuals: [4, 5],
63
- }
64
- ])
65
- })
66
-
67
- Maintainability('deducts points for having too many Selectors in a RuleSet', () => {
68
- const actual = calculate(`
69
- test1,
70
- test2,
71
- test3,
72
- test4,
73
- test5,
74
- test6,
75
- test7,
76
- test8,
77
- test9,
78
- test10,
79
- test11,
80
- test12,
81
- test13,
82
- test14,
83
- test15 {}
84
-
85
- testA {}
86
- `)
87
-
88
- assert.is(actual.maintainability.score, 82)
89
- assert.equal(actual.maintainability.violations, [
90
- {
91
- id: 'AverageSelectorsPerRule',
92
- score: 15,
93
- value: 8,
94
- actuals: [15, 1],
95
- },
96
- {
97
- id: 'MaxSelectorsPerRule',
98
- score: 3,
99
- value: 15,
100
- actuals: [15, 1],
101
- },
102
- ])
103
- })
104
-
105
- Maintainability('deducts points for having too many Declarations in a single RuleSet', () => {
106
- const fixture = `
107
- selector1 {
108
- color: tomato;
109
- }
110
-
111
- selector2 {
112
- ${Array.from({ length: 23 })
113
- .fill('')
114
- .map(i => `z-index: ${i};`)
115
- .join('')
116
- }}
117
- `
118
- const actual = calculate(fixture)
119
-
120
- assert.is(actual.maintainability.score, 78)
121
- assert.equal(actual.maintainability.violations, [
122
- {
123
- id: "AverageDeclarationsPerRule",
124
- score: 15,
125
- value: 12,
126
- actuals: [1, 23],
127
- },
128
- {
129
- id: 'MaxDeclarationsPerRule',
130
- score: 7, // Math.ceil((23 - 10) * 0.5) === Math.ceil(6.5)
131
- value: 23,
132
- actuals: [1, 23],
133
- },
134
- ])
135
- })
136
-
137
- Maintainability('deducts points for having RuleSets with more Selectors than what is most common', () => {
138
- const fixture = `
139
- ${Array.from({ length: 1000 })
140
- .fill('')
141
- .map(index => `selector-${index} {}`)
142
- .join('')
143
- }
144
-
145
- ${Array.from({ length: 500 })
146
- .fill('')
147
- .map(index => `selector-${index}a, selector-${index}-b {}`)
148
- .join('')
149
- }
150
- `
151
- const actual = calculate(fixture)
152
-
153
- assert.equal(actual.maintainability.violations, [
154
- {
155
- id: 'MoreThanMostCommonSelectorsPerRule',
156
- score: 5,
157
- value: 1,
158
- actuals: (Array.from({ length: 1000 }).fill(1)).concat(Array.from({ length: 500 }).fill(2)),
159
- },
160
- ])
161
- assert.is(actual.maintainability.score, 95)
162
- })
163
-
164
- Maintainability('deducts points for having RuleSets with more Selectors than what is most common', () => {
165
- const fixture = `
166
- ${Array.from({ length: 1000 })
167
- .fill('')
168
- .map(index => `selector-${index}a { z-index: ${index}; }`)
169
- .join('')
170
- }
171
-
172
- ${Array.from({ length: 500 })
173
- .fill('')
174
- .map(index => `selector-${index}b { z-index: ${index}; content: "${index}" }`)
175
- .join('')
176
- }
177
- `
178
- const actual = calculate(fixture)
179
-
180
- assert.equal(actual.maintainability.violations, [
181
- {
182
- id: 'MoreThanMostCommonDeclarationsPerRule',
183
- score: 5,
184
- value: 1,
185
- actuals: (Array.from({ length: 1000 }).fill(1)).concat(Array.from({ length: 500 }).fill(2)),
186
- },
187
- ])
188
- assert.is(actual.maintainability.score, 95)
189
- })
190
-
191
- Maintainability.run()