(
{ audit, plugin }: IssueContext,
report: Report,
)
| 150 | } |
| 151 | |
| 152 | export function getAuditImpactValue( |
| 153 | { audit, plugin }: IssueContext, |
| 154 | report: Report, |
| 155 | ): number { |
| 156 | if (!report.categories) { |
| 157 | return 0; |
| 158 | } |
| 159 | return report.categories |
| 160 | .map((category): number => { |
| 161 | const weights = category.refs.map((ref): number => { |
| 162 | if (ref.plugin !== plugin.slug) { |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | switch (ref.type) { |
| 167 | case 'audit': |
| 168 | return ref.slug === audit.slug ? ref.weight : 0; |
| 169 | |
| 170 | case 'group': |
| 171 | return calculateGroupImpact(ref, audit, report); |
| 172 | } |
| 173 | }); |
| 174 | |
| 175 | return ( |
| 176 | weights.reduce((acc, weight) => acc + weight, 0) / |
| 177 | category.refs.reduce((acc, { weight }) => acc + weight, 0) |
| 178 | ); |
| 179 | }) |
| 180 | .reduce((acc, value) => acc + value, 0); |
| 181 | } |
| 182 | |
| 183 | export function calculateGroupImpact( |
| 184 | ref: CategoryRef, |
no test coverage detected