@projectwallace/css-code-quality 1.0.1 → 1.0.3

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 ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis
3
+ */
4
+ export function calculate(analysis: ReturnType<typeof import('@projectwallace/css-analyzer').analyze>): {
5
+ /** @deprecated */
6
+ score: number;
7
+ violations: {
8
+ id: string;
9
+ score: number;
10
+ value: number;
11
+ }[];
12
+ passes: {
13
+ id: string;
14
+ score: number;
15
+ value: number;
16
+ }[];
17
+ performance: {
18
+ score: number;
19
+ violations: {
20
+ id: string;
21
+ score: number;
22
+ value: number;
23
+ }[];
24
+ passes: {
25
+ id: string;
26
+ score: number;
27
+ value: number;
28
+ }[];
29
+ };
30
+ maintainability: {
31
+ score: number;
32
+ violations: {
33
+ id: string;
34
+ score: number;
35
+ value: number;
36
+ }[];
37
+ passes: {
38
+ id: string;
39
+ score: number;
40
+ value: number;
41
+ }[];
42
+ };
43
+ complexity: {
44
+ score: number;
45
+ violations: {
46
+ id: string;
47
+ score: number;
48
+ value: number;
49
+ }[];
50
+ passes: {
51
+ id: string;
52
+ score: number;
53
+ value: number;
54
+ }[];
55
+ };
56
+ };
@@ -0,0 +1,295 @@
1
+ import { compareSpecificity as i, analyze as l } from "@projectwallace/css-analyzer";
2
+ const m = [
3
+ // Should not contain @import rules
4
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
5
+ (e) => ({
6
+ id: "Imports",
7
+ score: e.atrules.import.total * 10,
8
+ value: e.atrules.import.total,
9
+ actuals: Object.keys(e.atrules.import.unique)
10
+ }),
11
+ // Should not contain empty rules
12
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
13
+ (e) => ({
14
+ id: "EmptyRules",
15
+ score: e.rules.empty.total,
16
+ value: e.rules.empty.total
17
+ }),
18
+ // Too many selectors appear multiple times
19
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
20
+ (e) => {
21
+ const s = {
22
+ id: "SelectorDuplications",
23
+ score: 0,
24
+ value: 1 - e.selectors.uniquenessRatio
25
+ };
26
+ return e.selectors.uniquenessRatio < 0.66 && (s.score = Math.floor((1 - e.selectors.uniquenessRatio) * 10)), s;
27
+ },
28
+ // Too many declarations appear multiple times
29
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
30
+ (e) => {
31
+ const s = {
32
+ id: "DeclarationDuplications",
33
+ score: 0,
34
+ value: 1 - e.declarations.unique.ratio
35
+ };
36
+ return e.declarations.unique.ratio < 0.66 && (s.score = Math.floor((1 - e.declarations.unique.ratio) * 10)), s;
37
+ },
38
+ // The total amount of CSS should not be too high
39
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
40
+ (e) => ({
41
+ id: "CssSize",
42
+ score: e.stylesheet.size > 2e5 ? 5 : 0,
43
+ value: e.stylesheet.size
44
+ }),
45
+ // Should not contain (too much) comments
46
+ // Deduct 1 point for every 250 bytes
47
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
48
+ (e) => {
49
+ const { comments: s } = e.stylesheet;
50
+ return {
51
+ id: "TooMuchComments",
52
+ score: Math.min(10, Math.floor(s.size / 250)),
53
+ value: s.size
54
+ };
55
+ },
56
+ // Should not contain too much embedded content
57
+ // Deduct 1 point for every 250 bytes
58
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
59
+ (e) => {
60
+ const { size: s } = e.stylesheet.embeddedContent;
61
+ return {
62
+ id: "TooMuchEmbeddedContent",
63
+ score: Math.min(20, Math.floor(s.total / 250)),
64
+ value: s.total,
65
+ actuals: Object.keys(e.stylesheet.embeddedContent.unique)
66
+ };
67
+ }
68
+ ], u = [
69
+ // Source Lines of Code should be low
70
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
71
+ (e) => {
72
+ const s = {
73
+ id: "SourceLinesOfCode",
74
+ score: 0,
75
+ value: e.stylesheet.sourceLinesOfCode
76
+ };
77
+ if (e.stylesheet.sourceLinesOfCode > 1e4) {
78
+ const o = Math.floor((e.stylesheet.sourceLinesOfCode - 1e4) / 1e3);
79
+ s.score = Math.min(15, o);
80
+ }
81
+ return s;
82
+ },
83
+ // Average count of Selectors per RuleSet should be low
84
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
85
+ (e) => {
86
+ const o = e.rules.selectors.mean, t = {
87
+ id: "AverageSelectorsPerRule",
88
+ score: 0,
89
+ value: o,
90
+ actuals: e.rules.selectors.items
91
+ };
92
+ if (o > 2) {
93
+ const c = Math.floor((o - 2) * 5);
94
+ t.score = Math.min(15, c);
95
+ }
96
+ return t;
97
+ },
98
+ // Average count of Declarations per RuleSet should be low
99
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
100
+ (e) => {
101
+ const o = {
102
+ id: "AverageDeclarationsPerRule",
103
+ score: 0,
104
+ value: e.rules.declarations.mean,
105
+ actuals: e.rules.declarations.items
106
+ };
107
+ if (e.rules.declarations.mean > 5) {
108
+ const t = Math.floor((e.rules.declarations.mean - 5) * 5);
109
+ o.score = Math.min(15, t);
110
+ }
111
+ return o;
112
+ },
113
+ // Max number of Selectors per Rule should be low
114
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
115
+ (e) => {
116
+ const o = {
117
+ id: "MaxSelectorsPerRule",
118
+ score: 0,
119
+ value: e.rules.selectors.max,
120
+ actuals: e.rules.selectors.items
121
+ };
122
+ if (e.rules.selectors.max > 10) {
123
+ const t = Math.ceil((e.rules.selectors.max - 10) * 0.5);
124
+ o.score = Math.min(t, 15);
125
+ }
126
+ return o;
127
+ },
128
+ // Max number of Declarations per Rule should be low
129
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
130
+ (e) => {
131
+ const o = {
132
+ id: "MaxDeclarationsPerRule",
133
+ score: 0,
134
+ value: e.rules.declarations.max,
135
+ actuals: e.rules.declarations.items
136
+ };
137
+ if (e.rules.declarations.max > 10) {
138
+ const t = Math.ceil((e.rules.declarations.max - 10) * 0.5);
139
+ o.score = Math.min(15, t);
140
+ }
141
+ return o;
142
+ },
143
+ // Number of Selectors per RuleSet should not differ too much from the most common amount of
144
+ // Selectors per RuleSet
145
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
146
+ (e) => {
147
+ const s = e.rules.selectors.mode, o = e.rules.selectors.items.filter((c) => c > s).length, t = {
148
+ id: "MoreThanMostCommonSelectorsPerRule",
149
+ score: 0,
150
+ value: e.rules.selectors.mode,
151
+ actuals: e.rules.selectors.items
152
+ };
153
+ if (o > e.rules.total * 0.1) {
154
+ const c = Math.floor(o * 0.01);
155
+ t.score = Math.min(15, c);
156
+ }
157
+ return t;
158
+ },
159
+ // Number of Declarations per RuleSet should not differ too much from the most common amount of
160
+ // Declarations per RuleSet
161
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
162
+ (e) => {
163
+ const s = e.rules.selectors.mode, o = e.rules.declarations.items.filter((c) => c > s).length, t = {
164
+ id: "MoreThanMostCommonDeclarationsPerRule",
165
+ score: 0,
166
+ value: e.rules.declarations.mode,
167
+ actuals: e.rules.declarations.items
168
+ };
169
+ if (o > e.rules.total * 0.1) {
170
+ const c = Math.floor(o * 0.01);
171
+ t.score = Math.min(15, c);
172
+ }
173
+ return t;
174
+ }
175
+ ], E = [
176
+ // Complexity per Selector should not differ too much from the most common Complexity
177
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
178
+ (e) => {
179
+ const s = e.selectors.complexity.mode, o = e.selectors.complexity.items.filter((c) => c > s).length, t = {
180
+ id: "MoreThanMostCommonSelectorComplexity",
181
+ score: 0,
182
+ value: e.selectors.total === 0 ? 0 : o / e.selectors.total,
183
+ actuals: e.selectors.complexity.items
184
+ };
185
+ if (o > e.selectors.total * 0.1) {
186
+ const c = Math.floor(o * 0.01);
187
+ t.score = Math.min(10, c);
188
+ }
189
+ return t;
190
+ },
191
+ // Specificity per Selector should not differ too much from the most common Specificity
192
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
193
+ (e) => {
194
+ const s = e.selectors.specificity.mode, o = e.selectors.specificity.items.filter((c) => i(c, s) < 0).length, t = {
195
+ id: "MoreThanMostCommonSelectorSpecificity",
196
+ score: 0,
197
+ value: e.selectors.total === 0 ? 0 : o / e.selectors.total,
198
+ actuals: e.selectors.specificity.items
199
+ };
200
+ if (o > e.selectors.total * 0.1) {
201
+ const c = Math.floor(o * 0.01);
202
+ t.score = Math.min(10, c);
203
+ }
204
+ return t;
205
+ },
206
+ // Maximum Selector Complexity should be low
207
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
208
+ (e) => {
209
+ const o = e.selectors.complexity.max, t = {
210
+ id: "MaxSelectorComplexity",
211
+ score: 0,
212
+ value: e.selectors.complexity.max,
213
+ actuals: e.selectors.complexity.items
214
+ };
215
+ if (o > 5) {
216
+ const c = Math.ceil((o - 5) * 0.5);
217
+ t.score = Math.min(5, c);
218
+ }
219
+ return t;
220
+ },
221
+ // Average Selector Complexity should be low
222
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
223
+ (e) => {
224
+ const o = e.selectors.complexity.mean, t = {
225
+ id: "AverageSelectorComplexity",
226
+ score: 0,
227
+ value: o,
228
+ actuals: e.selectors.complexity.items
229
+ };
230
+ if (o > 2) {
231
+ const c = Math.ceil((o - 2) * 2);
232
+ t.score = Math.min(10, c);
233
+ }
234
+ return t;
235
+ },
236
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
237
+ (e) => {
238
+ const o = e.selectors.id.ratio, t = {
239
+ id: "IdSelectorRatio",
240
+ score: 0,
241
+ value: o,
242
+ actuals: Object.keys(e.selectors.id.unique)
243
+ };
244
+ if (o > 0.01) {
245
+ const c = Math.floor((o - 0.01) * 10);
246
+ t.score = Math.min(c, 5);
247
+ }
248
+ return t;
249
+ },
250
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
251
+ (e) => {
252
+ const o = e.declarations.importants.ratio, t = {
253
+ id: "ImportantRatio",
254
+ score: 0,
255
+ value: o,
256
+ actuals: e.declarations.importants.total
257
+ };
258
+ if (o > 0.01) {
259
+ const c = Math.floor((o - 0.01) * 10);
260
+ t.score = Math.min(c, 5);
261
+ }
262
+ return t;
263
+ }
264
+ ];
265
+ function r(e, s) {
266
+ let o = 100, t = [], c = [];
267
+ for (const n of s) {
268
+ const a = n(e);
269
+ a.score > 0 ? (o -= a.score, t.push(a)) : c.push(a);
270
+ }
271
+ return {
272
+ score: Math.max(o, 0),
273
+ violations: t,
274
+ passes: c
275
+ };
276
+ }
277
+ function d(e) {
278
+ const s = r(e, m), o = r(e, u), t = r(e, E);
279
+ return {
280
+ /** @deprecated */
281
+ score: 0,
282
+ violations: s.violations.concat(o.violations).concat(t.violations),
283
+ passes: s.passes.concat(o.passes).concat(t.passes),
284
+ performance: s,
285
+ maintainability: o,
286
+ complexity: t
287
+ };
288
+ }
289
+ function M(e) {
290
+ const s = l(e);
291
+ return d(s);
292
+ }
293
+ export {
294
+ M as calculate
295
+ };
@@ -0,0 +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 l=[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.unique.ratio};return e.declarations.unique.ratio<.66&&(s.score=Math.floor((1-e.declarations.unique.ratio)*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,actuals:Object.keys(e.stylesheet.embeddedContent.unique)}}],u=[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=>{const o={id:"MaxSelectorsPerRule",score:0,value:e.rules.selectors.max,actuals:e.rules.selectors.items};if(e.rules.selectors.max>10){const t=Math.ceil((e.rules.selectors.max-10)*.5);o.score=Math.min(t,15)}return o},e=>{const o={id:"MaxDeclarationsPerRule",score:0,value:e.rules.declarations.max,actuals:e.rules.declarations.items};if(e.rules.declarations.max>10){const t=Math.ceil((e.rules.declarations.max-10)*.5);o.score=Math.min(15,t)}return o},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}],m=[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,o=e.selectors.specificity.items.filter(c=>r.compareSpecificity(c,s)<0).length,t={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:e.selectors.total===0?0:o/e.selectors.total,actuals:e.selectors.specificity.items};if(o>e.selectors.total*.1){const c=Math.floor(o*.01);t.score=Math.min(10,c)}return t},e=>{const o=e.selectors.complexity.max,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 i(e,s){let o=100,t=[],c=[];for(const M of s){const n=M(e);n.score>0?(o-=n.score,t.push(n)):c.push(n)}return{score:Math.max(o,0),violations:t,passes:c}}function E(e){const s=i(e,l),o=i(e,u),t=i(e,m);return{score:0,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 d(e){const s=r.analyze(e);return E(s)}a.calculate=d,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -1,53 +1,55 @@
1
- /** @param {string} css */
2
- export function calculate(css: string): {
3
- score: number;
4
- violations: {
5
- score: number;
6
- value: number;
7
- id: string;
8
- }[];
9
- passes: {
10
- score: number;
11
- value: number;
12
- id: string;
13
- }[];
14
- performance: {
15
- score: number;
16
- violations: {
17
- score: number;
18
- value: number;
19
- id: string;
20
- }[];
21
- passes: {
22
- score: number;
23
- value: number;
24
- id: string;
25
- }[];
26
- };
27
- maintainability: {
28
- score: number;
29
- violations: {
30
- score: number;
31
- value: number;
32
- id: string;
33
- }[];
34
- passes: {
35
- score: number;
36
- value: number;
37
- id: string;
38
- }[];
39
- };
40
- complexity: {
41
- score: number;
42
- violations: {
43
- score: number;
44
- value: number;
45
- id: string;
46
- }[];
47
- passes: {
48
- score: number;
49
- value: number;
50
- id: string;
51
- }[];
52
- };
53
- };
1
+ /**
2
+ * @param {string} css
3
+ */
4
+ export function calculate(css: string): {
5
+ score: number;
6
+ violations: {
7
+ id: string;
8
+ score: number;
9
+ value: number;
10
+ }[];
11
+ passes: {
12
+ id: string;
13
+ score: number;
14
+ value: number;
15
+ }[];
16
+ performance: {
17
+ score: number;
18
+ violations: {
19
+ id: string;
20
+ score: number;
21
+ value: number;
22
+ }[];
23
+ passes: {
24
+ id: string;
25
+ score: number;
26
+ value: number;
27
+ }[];
28
+ };
29
+ maintainability: {
30
+ score: number;
31
+ violations: {
32
+ id: string;
33
+ score: number;
34
+ value: number;
35
+ }[];
36
+ passes: {
37
+ id: string;
38
+ score: number;
39
+ value: number;
40
+ }[];
41
+ };
42
+ complexity: {
43
+ score: number;
44
+ violations: {
45
+ id: string;
46
+ score: number;
47
+ value: number;
48
+ }[];
49
+ passes: {
50
+ id: string;
51
+ score: number;
52
+ value: number;
53
+ }[];
54
+ };
55
+ };
package/package.json CHANGED
@@ -1,8 +1,14 @@
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": "1.0.1",
5
- "repository": "git@github.com:projectwallace/css-code-quality.git",
4
+ "version": "1.0.3",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git@github.com:projectwallace/css-code-quality.git"
8
+ },
9
+ "homepage": "https://github.com/projectwallace/css-code-quality",
10
+ "issues": "https://github.com/projectwallace/css-code-quality/issues",
11
+ "license": "MIT",
6
12
  "author": {
7
13
  "email": "bart@projectwallace.com",
8
14
  "name": "Bart Veneman"
@@ -14,39 +20,43 @@
14
20
  "quality",
15
21
  "complexity",
16
22
  "performance",
17
- "maintainability"
23
+ "maintainability",
24
+ "score"
18
25
  ],
19
26
  "files": [
20
27
  "dist",
21
- "src"
28
+ "src",
29
+ "!src/**/*.test.js"
22
30
  ],
23
31
  "type": "module",
24
32
  "source": "src/index.js",
25
- "main": "./dist/css-code-quality.cjs",
26
- "module": "./dist/css-code-quality.module.js",
27
- "unpkg": "./dist/css-code-quality.umd.js",
33
+ "main": "./dist/css-code-quality.umd.cjs",
34
+ "module": "./dist/css-code-quality.js",
35
+ "unpkg": "./dist/css-code-quality.umd.cjs",
28
36
  "exports": {
29
37
  ".": {
30
- "import": "./dist/css-code-quality.modern.js",
31
- "require": "./dist/css-code-quality.cjs",
32
- "types": "./dist/index.d.ts"
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/css-code-quality.js",
40
+ "require": "./dist/css-code-quality.umd.cjs"
33
41
  },
34
42
  "./core": {
43
+ "types": "./dist/core.d.ts",
35
44
  "import": "./src/core.js"
36
45
  }
37
46
  },
38
47
  "types": "./dist/index.d.ts",
39
48
  "scripts": {
40
49
  "test": "uvu",
41
- "lint": "oxlint",
42
- "build": "microbundle"
50
+ "build": "vite build",
51
+ "check": "tsc --noEmit"
43
52
  },
44
53
  "dependencies": {
45
54
  "@projectwallace/css-analyzer": "^5.14.0"
46
55
  },
47
56
  "devDependencies": {
48
- "microbundle": "^0.15.1",
49
- "oxlint": "^0.2.13",
50
- "uvu": "^0.5.6"
57
+ "typescript": "^5.4.5",
58
+ "uvu": "^0.5.6",
59
+ "vite": "^5.2.12",
60
+ "vite-plugin-dts": "^3.9.1"
51
61
  }
52
62
  }
package/src/complexity.js CHANGED
@@ -3,6 +3,7 @@ import { compareSpecificity } from '@projectwallace/css-analyzer'
3
3
  export const guards = [
4
4
 
5
5
  // Complexity per Selector should not differ too much from the most common Complexity
6
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
6
7
  result => {
7
8
  const mode = result.selectors.complexity.mode
8
9
  const selectorsAboveMode = result.selectors.complexity.items
@@ -25,6 +26,7 @@ export const guards = [
25
26
  },
26
27
 
27
28
  // Specificity per Selector should not differ too much from the most common Specificity
29
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
28
30
  result => {
29
31
  const mode = result.selectors.specificity.mode
30
32
  const selectorsAboveMode = result.selectors.specificity.items
@@ -47,6 +49,7 @@ export const guards = [
47
49
  },
48
50
 
49
51
  // Maximum Selector Complexity should be low
52
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
50
53
  result => {
51
54
  const MAX_SELECTOR_COMPLEXITY = 5
52
55
  const actual = result.selectors.complexity.max
@@ -68,6 +71,7 @@ export const guards = [
68
71
  },
69
72
 
70
73
  // Average Selector Complexity should be low
74
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
71
75
  result => {
72
76
  const ALLOWED_COMPLEXITY = 2
73
77
  const actual = result.selectors.complexity.mean
@@ -88,6 +92,7 @@ export const guards = [
88
92
  return outcome
89
93
  },
90
94
 
95
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
91
96
  result => {
92
97
  const ALLOWED = 0.01
93
98
  const actual = result.selectors.id.ratio
@@ -106,6 +111,7 @@ export const guards = [
106
111
  return outcome
107
112
  },
108
113
 
114
+ /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
109
115
  result => {
110
116
  const ALLOWED = 0.01
111
117
  const actual = result.declarations.importants.ratio
package/src/core.js CHANGED
@@ -2,13 +2,16 @@ import { guards as performanceGuards } from './performance.js'
2
2
  import { guards as maintainabilityGuards } from './maintainability.js'
3
3
  import { guards as complexityGuards } from './complexity.js'
4
4
 
5
- function calculateScore({ result, guards }) {
5
+ /**
6
+ * @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result
7
+ * @param {performanceGuards | maintainabilityGuards | complexityGuards} guards
8
+ */
9
+ function calculateScore(result, guards) {
6
10
  let score = 100
7
11
  let violations = []
8
12
  let passes = []
9
13
 
10
14
  for (const guard of guards) {
11
- /** @type {{score: number, value: number, id: string}} */
12
15
  const outcome = guard(result)
13
16
 
14
17
  if (outcome.score > 0) {
@@ -26,11 +29,13 @@ function calculateScore({ result, guards }) {
26
29
  }
27
30
  }
28
31
 
29
- /** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */
32
+ /**
33
+ * @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis
34
+ */
30
35
  export function calculate(analysis) {
31
- const performance = calculateScore({ result: analysis, guards: performanceGuards })
32
- const maintainability = calculateScore({ result: analysis, guards: maintainabilityGuards })
33
- const complexity = calculateScore({ result: analysis, guards: complexityGuards })
36
+ const performance = calculateScore(analysis, performanceGuards)
37
+ const maintainability = calculateScore(analysis, maintainabilityGuards)
38
+ const complexity = calculateScore(analysis, complexityGuards)
34
39
 
35
40
  return {
36
41
  /** @deprecated */
package/src/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { analyze } from '@projectwallace/css-analyzer'
2
2
  import { calculate as calculateFromAnalysis } from './core.js'
3
3
 
4
- /** @param {string} css */
4
+ /**
5
+ * @param {string} css
6
+ */
5
7
  export function calculate(css) {
6
8
  const analysis = analyze(css)
7
9
  return calculateFromAnalysis(analysis)