11import { analyze } from '@projectwallace/css-analyzer'
2- import { guards as performanceGuards } from './performance.js'
3- import { guards as maintainabilityGuards } from './maintainability.js'
4- import { guards as complexityGuards } from './complexity.js'
2+ import { calculate as calculateFromAnalysis } from './core.js'
53
6- function calculateScore ( { result, guards } ) {
7- let score = 100
8- let violations = [ ]
9- let passes = [ ]
10-
11- for ( const guard of guards ) {
12- /** @type {{score: number, actual: number, id: string} } */
13- const outcome = guard ( result )
14-
15- if ( outcome . score > 0 ) {
16- score -= outcome . score
17- violations . push ( outcome )
18- } else {
19- passes . push ( outcome )
20- }
21- }
22-
23- return {
24- score : Math . max ( score , 0 ) ,
25- violations,
26- passes,
27- }
28- }
29-
30- function calculate ( css ) {
31- const result = analyze ( css )
32-
33- const performance = calculateScore ( { result, guards : performanceGuards } )
34- const maintainability = calculateScore ( { result, guards : maintainabilityGuards } )
35- const complexity = calculateScore ( { result, guards : complexityGuards } )
36-
37- return {
38- score : 0 ,
39- violations : performance . violations
40- . concat ( maintainability . violations )
41- . concat ( complexity . violations ) ,
42- passes : performance . passes
43- . concat ( maintainability . passes )
44- . concat ( complexity . passes ) ,
45- performance,
46- maintainability,
47- complexity,
48- }
4+ export function calculate ( css ) {
5+ const analysis = analyze ( css )
6+ return calculateFromAnalysis ( analysis )
497}
50-
51- export {
52- calculate
53- }
0 commit comments