File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ export const SCORE_COLOR_RANGE = {
2+ GREEN_MIN : 0.9 ,
3+ YELLOW_MIN : 0.5 ,
4+ } ;
Original file line number Diff line number Diff line change 11import cliui from '@isaacs/cliui' ;
22import chalk from 'chalk' ;
33import Table from 'cli-table3' ;
4+ import { SCORE_COLOR_RANGE } from './constants' ;
45import { NEW_LINE } from './md' ;
56import {
67 CODE_PUSHUP_DOMAIN ,
@@ -101,14 +102,16 @@ function reportToDetailSection(report: ScoredReport): string {
101102}
102103
103104function withColor ( { score, text } : { score : number ; text ?: string } ) {
104- let str = text ?? formatReportScore ( score ) ;
105+ const formattedScore = text ?? formatReportScore ( score ) ;
105106 const style = text ? chalk : chalk . bold ;
106- if ( score < 0.5 ) {
107- str = style . red ( str ) ;
108- } else if ( score < 0.9 ) {
109- str = style . yellow ( str ) ;
110- } else {
111- str = style . green ( str ) ;
107+
108+ if ( score >= SCORE_COLOR_RANGE . GREEN_MIN ) {
109+ return style . green ( formattedScore ) ;
110+ }
111+
112+ if ( score >= SCORE_COLOR_RANGE . YELLOW_MIN ) {
113+ return style . yellow ( formattedScore ) ;
112114 }
113- return str ;
115+
116+ return style . red ( formattedScore ) ;
114117}
Original file line number Diff line number Diff line change 99 Report ,
1010 reportSchema ,
1111} from '@code-pushup/models' ;
12+ import { SCORE_COLOR_RANGE } from './constants' ;
1213import {
1314 ensureDirectoryExists ,
1415 readJsonFile ,
@@ -62,20 +63,20 @@ export function formatReportScore(score: number): string {
6263}
6364
6465export function getRoundScoreMarker ( score : number ) : string {
65- if ( score >= 0.9 ) {
66+ if ( score >= SCORE_COLOR_RANGE . GREEN_MIN ) {
6667 return '🟢' ;
6768 }
68- if ( score >= 0.5 ) {
69+ if ( score >= SCORE_COLOR_RANGE . YELLOW_MIN ) {
6970 return '🟡' ;
7071 }
7172 return '🔴' ;
7273}
7374
7475export function getSquaredScoreMarker ( score : number ) : string {
75- if ( score >= 0.9 ) {
76+ if ( score >= SCORE_COLOR_RANGE . GREEN_MIN ) {
7677 return '🟩' ;
7778 }
78- if ( score >= 0.5 ) {
79+ if ( score >= SCORE_COLOR_RANGE . YELLOW_MIN ) {
7980 return '🟨' ;
8081 }
8182 return '🟥' ;
You can’t perform that action at this time.
0 commit comments