@projectwallace/css-code-quality 1.0.3 → 2.0.0
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/dist/core.d.ts +57 -21
- package/dist/css-code-quality.js +32 -34
- package/dist/css-code-quality.umd.cjs +1 -1
- package/dist/index.d.ts +56 -17
- package/package.json +5 -5
- package/src/complexity.js +5 -3
- package/src/core.js +1 -5
- package/src/maintainability.js +8 -6
- package/src/performance.js +4 -5
package/dist/core.d.ts
CHANGED
|
@@ -1,56 +1,92 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis
|
|
3
|
-
*/
|
|
1
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */
|
|
4
2
|
export function calculate(analysis: ReturnType<typeof import('@projectwallace/css-analyzer').analyze>): {
|
|
5
|
-
|
|
6
|
-
score: number;
|
|
7
|
-
violations: {
|
|
3
|
+
violations: ({
|
|
8
4
|
id: string;
|
|
9
5
|
score: number;
|
|
10
6
|
value: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
7
|
+
} | {
|
|
8
|
+
id: string;
|
|
9
|
+
score: number;
|
|
10
|
+
value: number | undefined;
|
|
11
|
+
actuals: number[];
|
|
12
|
+
})[];
|
|
13
|
+
passes: ({
|
|
13
14
|
id: string;
|
|
14
15
|
score: number;
|
|
15
16
|
value: number;
|
|
16
|
-
}
|
|
17
|
+
} | {
|
|
18
|
+
id: string;
|
|
19
|
+
score: number;
|
|
20
|
+
value: number | undefined;
|
|
21
|
+
actuals: number[];
|
|
22
|
+
})[];
|
|
17
23
|
performance: {
|
|
18
24
|
score: number;
|
|
19
|
-
violations: {
|
|
25
|
+
violations: ({
|
|
20
26
|
id: string;
|
|
21
27
|
score: number;
|
|
22
28
|
value: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
29
|
+
} | {
|
|
30
|
+
id: string;
|
|
31
|
+
score: number;
|
|
32
|
+
value: number | undefined;
|
|
33
|
+
actuals: number[];
|
|
34
|
+
})[];
|
|
35
|
+
passes: ({
|
|
25
36
|
id: string;
|
|
26
37
|
score: number;
|
|
27
38
|
value: number;
|
|
28
|
-
}
|
|
39
|
+
} | {
|
|
40
|
+
id: string;
|
|
41
|
+
score: number;
|
|
42
|
+
value: number | undefined;
|
|
43
|
+
actuals: number[];
|
|
44
|
+
})[];
|
|
29
45
|
};
|
|
30
46
|
maintainability: {
|
|
31
47
|
score: number;
|
|
32
|
-
violations: {
|
|
48
|
+
violations: ({
|
|
33
49
|
id: string;
|
|
34
50
|
score: number;
|
|
35
51
|
value: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
52
|
+
} | {
|
|
53
|
+
id: string;
|
|
54
|
+
score: number;
|
|
55
|
+
value: number | undefined;
|
|
56
|
+
actuals: number[];
|
|
57
|
+
})[];
|
|
58
|
+
passes: ({
|
|
38
59
|
id: string;
|
|
39
60
|
score: number;
|
|
40
61
|
value: number;
|
|
41
|
-
}
|
|
62
|
+
} | {
|
|
63
|
+
id: string;
|
|
64
|
+
score: number;
|
|
65
|
+
value: number | undefined;
|
|
66
|
+
actuals: number[];
|
|
67
|
+
})[];
|
|
42
68
|
};
|
|
43
69
|
complexity: {
|
|
44
70
|
score: number;
|
|
45
|
-
violations: {
|
|
71
|
+
violations: ({
|
|
46
72
|
id: string;
|
|
47
73
|
score: number;
|
|
48
74
|
value: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
75
|
+
} | {
|
|
76
|
+
id: string;
|
|
77
|
+
score: number;
|
|
78
|
+
value: number | undefined;
|
|
79
|
+
actuals: number[];
|
|
80
|
+
})[];
|
|
81
|
+
passes: ({
|
|
51
82
|
id: string;
|
|
52
83
|
score: number;
|
|
53
84
|
value: number;
|
|
54
|
-
}
|
|
85
|
+
} | {
|
|
86
|
+
id: string;
|
|
87
|
+
score: number;
|
|
88
|
+
value: number | undefined;
|
|
89
|
+
actuals: number[];
|
|
90
|
+
})[];
|
|
55
91
|
};
|
|
56
92
|
};
|
package/dist/css-code-quality.js
CHANGED
|
@@ -31,9 +31,9 @@ const m = [
|
|
|
31
31
|
const s = {
|
|
32
32
|
id: "DeclarationDuplications",
|
|
33
33
|
score: 0,
|
|
34
|
-
value: 1 - e.declarations.
|
|
34
|
+
value: 1 - e.declarations.uniquenessRatio
|
|
35
35
|
};
|
|
36
|
-
return e.declarations.
|
|
36
|
+
return e.declarations.uniquenessRatio < 0.66 && (s.score = Math.floor((1 - e.declarations.uniquenessRatio) * 10)), s;
|
|
37
37
|
},
|
|
38
38
|
// The total amount of CSS should not be too high
|
|
39
39
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
@@ -61,8 +61,7 @@ const m = [
|
|
|
61
61
|
return {
|
|
62
62
|
id: "TooMuchEmbeddedContent",
|
|
63
63
|
score: Math.min(20, Math.floor(s.total / 250)),
|
|
64
|
-
value: s.total
|
|
65
|
-
actuals: Object.keys(e.stylesheet.embeddedContent.unique)
|
|
64
|
+
value: s.total
|
|
66
65
|
};
|
|
67
66
|
}
|
|
68
67
|
], u = [
|
|
@@ -113,32 +112,33 @@ const m = [
|
|
|
113
112
|
// Max number of Selectors per Rule should be low
|
|
114
113
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
115
114
|
(e) => {
|
|
116
|
-
|
|
115
|
+
let o = e.rules.selectors.max || 0;
|
|
116
|
+
const t = {
|
|
117
117
|
id: "MaxSelectorsPerRule",
|
|
118
118
|
score: 0,
|
|
119
|
-
value:
|
|
119
|
+
value: o,
|
|
120
120
|
actuals: e.rules.selectors.items
|
|
121
121
|
};
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
|
|
122
|
+
if (o > 10) {
|
|
123
|
+
const c = Math.ceil((o - 10) * 0.5);
|
|
124
|
+
t.score = Math.min(c, 15);
|
|
125
125
|
}
|
|
126
|
-
return
|
|
126
|
+
return t;
|
|
127
127
|
},
|
|
128
128
|
// Max number of Declarations per Rule should be low
|
|
129
129
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
130
130
|
(e) => {
|
|
131
|
-
const o = {
|
|
131
|
+
const o = e.rules.declarations.max || 0, t = {
|
|
132
132
|
id: "MaxDeclarationsPerRule",
|
|
133
133
|
score: 0,
|
|
134
|
-
value:
|
|
134
|
+
value: o,
|
|
135
135
|
actuals: e.rules.declarations.items
|
|
136
136
|
};
|
|
137
|
-
if (
|
|
138
|
-
const
|
|
139
|
-
|
|
137
|
+
if (o > 10) {
|
|
138
|
+
const c = Math.ceil((o - 10) * 0.5);
|
|
139
|
+
t.score = Math.min(15, c);
|
|
140
140
|
}
|
|
141
|
-
return
|
|
141
|
+
return t;
|
|
142
142
|
},
|
|
143
143
|
// Number of Selectors per RuleSet should not differ too much from the most common amount of
|
|
144
144
|
// Selectors per RuleSet
|
|
@@ -191,22 +191,22 @@ const m = [
|
|
|
191
191
|
// Specificity per Selector should not differ too much from the most common Specificity
|
|
192
192
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
193
193
|
(e) => {
|
|
194
|
-
const s = e.selectors.specificity.mode,
|
|
194
|
+
const s = e.selectors.specificity.mode, t = e.selectors.specificity.items.filter((a) => i(a, s) < 0).length, c = {
|
|
195
195
|
id: "MoreThanMostCommonSelectorSpecificity",
|
|
196
196
|
score: 0,
|
|
197
|
-
value: e.selectors.total === 0 ? 0 :
|
|
197
|
+
value: e.selectors.total === 0 ? 0 : t / e.selectors.total,
|
|
198
198
|
actuals: e.selectors.specificity.items
|
|
199
199
|
};
|
|
200
|
-
if (
|
|
201
|
-
const
|
|
202
|
-
|
|
200
|
+
if (t > e.selectors.total * 0.1) {
|
|
201
|
+
const a = Math.floor(t * 0.01);
|
|
202
|
+
c.score = Math.min(10, a);
|
|
203
203
|
}
|
|
204
|
-
return
|
|
204
|
+
return c;
|
|
205
205
|
},
|
|
206
206
|
// Maximum Selector Complexity should be low
|
|
207
207
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
208
208
|
(e) => {
|
|
209
|
-
const o = e.selectors.complexity.max, t = {
|
|
209
|
+
const o = e.selectors.complexity.max || 0, t = {
|
|
210
210
|
id: "MaxSelectorComplexity",
|
|
211
211
|
score: 0,
|
|
212
212
|
value: e.selectors.complexity.max,
|
|
@@ -262,11 +262,11 @@ const m = [
|
|
|
262
262
|
return t;
|
|
263
263
|
}
|
|
264
264
|
];
|
|
265
|
-
function
|
|
265
|
+
function n(e, s) {
|
|
266
266
|
let o = 100, t = [], c = [];
|
|
267
|
-
for (const
|
|
268
|
-
const
|
|
269
|
-
|
|
267
|
+
for (const a of s) {
|
|
268
|
+
const r = a(e);
|
|
269
|
+
r.score > 0 ? (o -= r.score, t.push(r)) : c.push(r);
|
|
270
270
|
}
|
|
271
271
|
return {
|
|
272
272
|
score: Math.max(o, 0),
|
|
@@ -274,11 +274,9 @@ function r(e, s) {
|
|
|
274
274
|
passes: c
|
|
275
275
|
};
|
|
276
276
|
}
|
|
277
|
-
function
|
|
278
|
-
const s =
|
|
277
|
+
function L(e) {
|
|
278
|
+
const s = n(e, m), o = n(e, u), t = n(e, E);
|
|
279
279
|
return {
|
|
280
|
-
/** @deprecated */
|
|
281
|
-
score: 0,
|
|
282
280
|
violations: s.violations.concat(o.violations).concat(t.violations),
|
|
283
281
|
passes: s.passes.concat(o.passes).concat(t.passes),
|
|
284
282
|
performance: s,
|
|
@@ -286,10 +284,10 @@ function d(e) {
|
|
|
286
284
|
complexity: t
|
|
287
285
|
};
|
|
288
286
|
}
|
|
289
|
-
function
|
|
287
|
+
function d(e) {
|
|
290
288
|
const s = l(e);
|
|
291
|
-
return
|
|
289
|
+
return L(s);
|
|
292
290
|
}
|
|
293
291
|
export {
|
|
294
|
-
|
|
292
|
+
d as calculate
|
|
295
293
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@projectwallace/css-analyzer")):typeof define=="function"&&define.amd?define(["exports","@projectwallace/css-analyzer"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.cssCodeQuality={},a.cssAnalyzer))})(this,function(a,r){"use strict";const
|
|
1
|
+
(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@projectwallace/css-analyzer")):typeof define=="function"&&define.amd?define(["exports","@projectwallace/css-analyzer"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.cssCodeQuality={},a.cssAnalyzer))})(this,function(a,r){"use strict";const u=[e=>({id:"Imports",score:e.atrules.import.total*10,value:e.atrules.import.total,actuals:Object.keys(e.atrules.import.unique)}),e=>({id:"EmptyRules",score:e.rules.empty.total,value:e.rules.empty.total}),e=>{const s={id:"SelectorDuplications",score:0,value:1-e.selectors.uniquenessRatio};return e.selectors.uniquenessRatio<.66&&(s.score=Math.floor((1-e.selectors.uniquenessRatio)*10)),s},e=>{const s={id:"DeclarationDuplications",score:0,value:1-e.declarations.uniquenessRatio};return e.declarations.uniquenessRatio<.66&&(s.score=Math.floor((1-e.declarations.uniquenessRatio)*10)),s},e=>({id:"CssSize",score:e.stylesheet.size>2e5?5:0,value:e.stylesheet.size}),e=>{const{comments:s}=e.stylesheet;return{id:"TooMuchComments",score:Math.min(10,Math.floor(s.size/250)),value:s.size}},e=>{const{size:s}=e.stylesheet.embeddedContent;return{id:"TooMuchEmbeddedContent",score:Math.min(20,Math.floor(s.total/250)),value:s.total}}],m=[e=>{const s={id:"SourceLinesOfCode",score:0,value:e.stylesheet.sourceLinesOfCode};if(e.stylesheet.sourceLinesOfCode>1e4){const o=Math.floor((e.stylesheet.sourceLinesOfCode-1e4)/1e3);s.score=Math.min(15,o)}return s},e=>{const o=e.rules.selectors.mean,t={id:"AverageSelectorsPerRule",score:0,value:o,actuals:e.rules.selectors.items};if(o>2){const c=Math.floor((o-2)*5);t.score=Math.min(15,c)}return t},e=>{const o={id:"AverageDeclarationsPerRule",score:0,value:e.rules.declarations.mean,actuals:e.rules.declarations.items};if(e.rules.declarations.mean>5){const t=Math.floor((e.rules.declarations.mean-5)*5);o.score=Math.min(15,t)}return o},e=>{let o=e.rules.selectors.max||0;const t={id:"MaxSelectorsPerRule",score:0,value:o,actuals:e.rules.selectors.items};if(o>10){const c=Math.ceil((o-10)*.5);t.score=Math.min(c,15)}return t},e=>{const o=e.rules.declarations.max||0,t={id:"MaxDeclarationsPerRule",score:0,value:o,actuals:e.rules.declarations.items};if(o>10){const c=Math.ceil((o-10)*.5);t.score=Math.min(15,c)}return t},e=>{const s=e.rules.selectors.mode,o=e.rules.selectors.items.filter(c=>c>s).length,t={id:"MoreThanMostCommonSelectorsPerRule",score:0,value:e.rules.selectors.mode,actuals:e.rules.selectors.items};if(o>e.rules.total*.1){const c=Math.floor(o*.01);t.score=Math.min(15,c)}return t},e=>{const s=e.rules.selectors.mode,o=e.rules.declarations.items.filter(c=>c>s).length,t={id:"MoreThanMostCommonDeclarationsPerRule",score:0,value:e.rules.declarations.mode,actuals:e.rules.declarations.items};if(o>e.rules.total*.1){const c=Math.floor(o*.01);t.score=Math.min(15,c)}return t}],E=[e=>{const s=e.selectors.complexity.mode,o=e.selectors.complexity.items.filter(c=>c>s).length,t={id:"MoreThanMostCommonSelectorComplexity",score:0,value:e.selectors.total===0?0:o/e.selectors.total,actuals:e.selectors.complexity.items};if(o>e.selectors.total*.1){const c=Math.floor(o*.01);t.score=Math.min(10,c)}return t},e=>{const s=e.selectors.specificity.mode,t=e.selectors.specificity.items.filter(n=>r.compareSpecificity(n,s)<0).length,c={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:e.selectors.total===0?0:t/e.selectors.total,actuals:e.selectors.specificity.items};if(t>e.selectors.total*.1){const n=Math.floor(t*.01);c.score=Math.min(10,n)}return c},e=>{const o=e.selectors.complexity.max||0,t={id:"MaxSelectorComplexity",score:0,value:e.selectors.complexity.max,actuals:e.selectors.complexity.items};if(o>5){const c=Math.ceil((o-5)*.5);t.score=Math.min(5,c)}return t},e=>{const o=e.selectors.complexity.mean,t={id:"AverageSelectorComplexity",score:0,value:o,actuals:e.selectors.complexity.items};if(o>2){const c=Math.ceil((o-2)*2);t.score=Math.min(10,c)}return t},e=>{const o=e.selectors.id.ratio,t={id:"IdSelectorRatio",score:0,value:o,actuals:Object.keys(e.selectors.id.unique)};if(o>.01){const c=Math.floor((o-.01)*10);t.score=Math.min(c,5)}return t},e=>{const o=e.declarations.importants.ratio,t={id:"ImportantRatio",score:0,value:o,actuals:e.declarations.importants.total};if(o>.01){const c=Math.floor((o-.01)*10);t.score=Math.min(c,5)}return t}];function l(e,s){let o=100,t=[],c=[];for(const n of s){const i=n(e);i.score>0?(o-=i.score,t.push(i)):c.push(i)}return{score:Math.max(o,0),violations:t,passes:c}}function d(e){const s=l(e,u),o=l(e,m),t=l(e,E);return{violations:s.violations.concat(o.violations).concat(t.violations),passes:s.passes.concat(o.passes).concat(t.passes),performance:s,maintainability:o,complexity:t}}function M(e){const s=r.analyze(e);return d(s)}a.calculate=M,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/dist/index.d.ts
CHANGED
|
@@ -2,54 +2,93 @@
|
|
|
2
2
|
* @param {string} css
|
|
3
3
|
*/
|
|
4
4
|
export function calculate(css: string): {
|
|
5
|
-
|
|
6
|
-
violations: {
|
|
5
|
+
violations: ({
|
|
7
6
|
id: string;
|
|
8
7
|
score: number;
|
|
9
8
|
value: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
9
|
+
} | {
|
|
10
|
+
id: string;
|
|
11
|
+
score: number;
|
|
12
|
+
value: number | undefined;
|
|
13
|
+
actuals: number[];
|
|
14
|
+
})[];
|
|
15
|
+
passes: ({
|
|
12
16
|
id: string;
|
|
13
17
|
score: number;
|
|
14
18
|
value: number;
|
|
15
|
-
}
|
|
19
|
+
} | {
|
|
20
|
+
id: string;
|
|
21
|
+
score: number;
|
|
22
|
+
value: number | undefined;
|
|
23
|
+
actuals: number[];
|
|
24
|
+
})[];
|
|
16
25
|
performance: {
|
|
17
26
|
score: number;
|
|
18
|
-
violations: {
|
|
27
|
+
violations: ({
|
|
19
28
|
id: string;
|
|
20
29
|
score: number;
|
|
21
30
|
value: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
31
|
+
} | {
|
|
32
|
+
id: string;
|
|
33
|
+
score: number;
|
|
34
|
+
value: number | undefined;
|
|
35
|
+
actuals: number[];
|
|
36
|
+
})[];
|
|
37
|
+
passes: ({
|
|
24
38
|
id: string;
|
|
25
39
|
score: number;
|
|
26
40
|
value: number;
|
|
27
|
-
}
|
|
41
|
+
} | {
|
|
42
|
+
id: string;
|
|
43
|
+
score: number;
|
|
44
|
+
value: number | undefined;
|
|
45
|
+
actuals: number[];
|
|
46
|
+
})[];
|
|
28
47
|
};
|
|
29
48
|
maintainability: {
|
|
30
49
|
score: number;
|
|
31
|
-
violations: {
|
|
50
|
+
violations: ({
|
|
32
51
|
id: string;
|
|
33
52
|
score: number;
|
|
34
53
|
value: number;
|
|
35
|
-
}
|
|
36
|
-
|
|
54
|
+
} | {
|
|
55
|
+
id: string;
|
|
56
|
+
score: number;
|
|
57
|
+
value: number | undefined;
|
|
58
|
+
actuals: number[];
|
|
59
|
+
})[];
|
|
60
|
+
passes: ({
|
|
37
61
|
id: string;
|
|
38
62
|
score: number;
|
|
39
63
|
value: number;
|
|
40
|
-
}
|
|
64
|
+
} | {
|
|
65
|
+
id: string;
|
|
66
|
+
score: number;
|
|
67
|
+
value: number | undefined;
|
|
68
|
+
actuals: number[];
|
|
69
|
+
})[];
|
|
41
70
|
};
|
|
42
71
|
complexity: {
|
|
43
72
|
score: number;
|
|
44
|
-
violations: {
|
|
73
|
+
violations: ({
|
|
45
74
|
id: string;
|
|
46
75
|
score: number;
|
|
47
76
|
value: number;
|
|
48
|
-
}
|
|
49
|
-
|
|
77
|
+
} | {
|
|
78
|
+
id: string;
|
|
79
|
+
score: number;
|
|
80
|
+
value: number | undefined;
|
|
81
|
+
actuals: number[];
|
|
82
|
+
})[];
|
|
83
|
+
passes: ({
|
|
50
84
|
id: string;
|
|
51
85
|
score: number;
|
|
52
86
|
value: number;
|
|
53
|
-
}
|
|
87
|
+
} | {
|
|
88
|
+
id: string;
|
|
89
|
+
score: number;
|
|
90
|
+
value: number | undefined;
|
|
91
|
+
actuals: number[];
|
|
92
|
+
})[];
|
|
54
93
|
};
|
|
55
94
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-code-quality",
|
|
3
3
|
"description": "Calculate the Code Quality score of your CSS based on a range of different quality guards",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git@github.com:projectwallace/css-code-quality.git"
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"check": "tsc --noEmit"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@projectwallace/css-analyzer": "^
|
|
54
|
+
"@projectwallace/css-analyzer": "^6.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"typescript": "^5.
|
|
57
|
+
"typescript": "^5.7.3",
|
|
58
58
|
"uvu": "^0.5.6",
|
|
59
|
-
"vite": "^
|
|
60
|
-
"vite-plugin-dts": "^
|
|
59
|
+
"vite": "^6.2.0",
|
|
60
|
+
"vite-plugin-dts": "^4.5.0"
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/complexity.js
CHANGED
|
@@ -29,8 +29,10 @@ export const guards = [
|
|
|
29
29
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
30
30
|
result => {
|
|
31
31
|
const mode = result.selectors.specificity.mode
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/** @type {import('@projectwallace/css-analyzer').Specificity[]} */
|
|
33
|
+
// @ts-expect-error css-analyzer type is incorrect
|
|
34
|
+
const items = result.selectors.specificity.items
|
|
35
|
+
const selectorsAboveMode = items.filter(c => compareSpecificity(c, mode) < 0)
|
|
34
36
|
.length
|
|
35
37
|
|
|
36
38
|
const outcome = {
|
|
@@ -52,7 +54,7 @@ export const guards = [
|
|
|
52
54
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
53
55
|
result => {
|
|
54
56
|
const MAX_SELECTOR_COMPLEXITY = 5
|
|
55
|
-
const actual = result.selectors.complexity.max
|
|
57
|
+
const actual = result.selectors.complexity.max || 0
|
|
56
58
|
|
|
57
59
|
const outcome = {
|
|
58
60
|
id: 'MaxSelectorComplexity',
|
package/src/core.js
CHANGED
|
@@ -29,17 +29,13 @@ function calculateScore(result, guards) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis
|
|
34
|
-
*/
|
|
32
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */
|
|
35
33
|
export function calculate(analysis) {
|
|
36
34
|
const performance = calculateScore(analysis, performanceGuards)
|
|
37
35
|
const maintainability = calculateScore(analysis, maintainabilityGuards)
|
|
38
36
|
const complexity = calculateScore(analysis, complexityGuards)
|
|
39
37
|
|
|
40
38
|
return {
|
|
41
|
-
/** @deprecated */
|
|
42
|
-
score: 0,
|
|
43
39
|
violations: performance.violations
|
|
44
40
|
.concat(maintainability.violations)
|
|
45
41
|
.concat(complexity.violations),
|
package/src/maintainability.js
CHANGED
|
@@ -65,17 +65,18 @@ export const guards = [
|
|
|
65
65
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
66
66
|
result => {
|
|
67
67
|
const MAX_SELECTORS_PER_RULESET = 10
|
|
68
|
+
let max = result.rules.selectors.max || 0
|
|
68
69
|
|
|
69
70
|
const outcome = {
|
|
70
71
|
id: 'MaxSelectorsPerRule',
|
|
71
72
|
score: 0,
|
|
72
|
-
value:
|
|
73
|
+
value: max,
|
|
73
74
|
actuals: result.rules.selectors.items,
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
// Deduct 0.5 points per selectors over 10
|
|
77
|
-
if (
|
|
78
|
-
const score = Math.ceil((
|
|
78
|
+
if (max > MAX_SELECTORS_PER_RULESET) {
|
|
79
|
+
const score = Math.ceil((max - MAX_SELECTORS_PER_RULESET) * 0.5)
|
|
79
80
|
outcome.score = Math.min(score, 15)
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -86,17 +87,18 @@ export const guards = [
|
|
|
86
87
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
87
88
|
result => {
|
|
88
89
|
const MAX_DECLARATIONS_PER_RULESET = 10
|
|
90
|
+
const max = result.rules.declarations.max || 0
|
|
89
91
|
|
|
90
92
|
const outcome = {
|
|
91
93
|
id: 'MaxDeclarationsPerRule',
|
|
92
94
|
score: 0,
|
|
93
|
-
value:
|
|
95
|
+
value: max,
|
|
94
96
|
actuals: result.rules.declarations.items,
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// Deduct 0.5 points per declarations over 10
|
|
98
|
-
if (
|
|
99
|
-
const score = Math.ceil((
|
|
100
|
+
if (max > MAX_DECLARATIONS_PER_RULESET) {
|
|
101
|
+
const score = Math.ceil((max - MAX_DECLARATIONS_PER_RULESET) * 0.5)
|
|
100
102
|
outcome.score = Math.min(15, score)
|
|
101
103
|
}
|
|
102
104
|
|
package/src/performance.js
CHANGED
|
@@ -39,11 +39,11 @@ export const guards = [
|
|
|
39
39
|
const outcome = {
|
|
40
40
|
id: 'DeclarationDuplications',
|
|
41
41
|
score: 0,
|
|
42
|
-
value: 1 - result.declarations.
|
|
42
|
+
value: 1 - result.declarations.uniquenessRatio,
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (result.declarations.
|
|
46
|
-
outcome.score = Math.floor((1 - result.declarations.
|
|
45
|
+
if (result.declarations.uniquenessRatio < 0.66) {
|
|
46
|
+
outcome.score = Math.floor((1 - result.declarations.uniquenessRatio) * 10)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return outcome
|
|
@@ -72,13 +72,12 @@ export const guards = [
|
|
|
72
72
|
// Should not contain too much embedded content
|
|
73
73
|
// Deduct 1 point for every 250 bytes
|
|
74
74
|
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
75
|
-
result => {
|
|
75
|
+
(result) => {
|
|
76
76
|
const { size } = result.stylesheet.embeddedContent
|
|
77
77
|
return {
|
|
78
78
|
id: 'TooMuchEmbeddedContent',
|
|
79
79
|
score: Math.min(20, Math.floor(size.total / 250)),
|
|
80
80
|
value: size.total,
|
|
81
|
-
actuals: Object.keys(result.stylesheet.embeddedContent.unique),
|
|
82
81
|
}
|
|
83
82
|
},
|
|
84
83
|
]
|