@@ -14,7 +14,14 @@ import { formatOutput, writeOutput } from '../services/output';
14
14
import { FailSeverity , ILintConfig , OutputFormat } from '../services/config' ;
15
15
16
16
import { CLIError } from '../errors' ;
17
- import { getScoringConfig } from '../formatters/utils/getScoring' ;
17
+ import { ScoringConfig } from "./../formatters/types" ;
18
+ import {
19
+ getScoringConfig ,
20
+ getScoringLevel ,
21
+ groupBySource ,
22
+ getCountsBySeverity ,
23
+ uniqueErrors
24
+ } from '../formatters//utils' ;
18
25
19
26
const formatOptions = Object . values ( OutputFormat ) ;
20
27
@@ -204,18 +211,22 @@ const lintCommand: CommandModule = {
204
211
results = filterResultsBySeverity ( results , failSeverity ) ;
205
212
}
206
213
214
+ const scoringConfigData = getScoringConfig ( scoringConfig ) ;
215
+
207
216
await Promise . all (
208
217
format . map ( f => {
209
218
const formattedOutput = formatOutput ( results , f , {
210
219
failSeverity : getDiagnosticSeverity ( failSeverity ) ,
211
- scoringConfig : getScoringConfig ( scoringConfig ) ,
220
+ scoringConfig : scoringConfigData ,
212
221
} ) ;
213
222
return writeOutput ( formattedOutput , output ?. [ f ] ?? '<stdout>' ) ;
214
223
} ) ,
215
224
) ;
216
-
225
+ //process.stdout.write(`${scoringThresholdNotEnough(results, scoringConfigData)}\n`);
217
226
if ( results . length > 0 ) {
218
- process . exit ( severeEnoughToFail ( results , failSeverity ) ? 1 : 0 ) ;
227
+ process . exit (
228
+ scoringThresholdNotEnough ( results , scoringConfigData ) ? 1 : severeEnoughToFail ( results , failSeverity ) ? 1 : 0 ,
229
+ ) ;
219
230
} else if ( config . quiet !== true ) {
220
231
const isErrorSeverity = getDiagnosticSeverity ( failSeverity ) === DiagnosticSeverity . Error ;
221
232
process . stdout . write (
@@ -283,6 +294,25 @@ const filterResultsBySeverity = (results: IRuleResult[], failSeverity: FailSever
283
294
return results . filter ( r => r . severity <= diagnosticSeverity ) ;
284
295
} ;
285
296
297
+ const scoringThresholdNotEnough = ( results : IRuleResult [ ] , scoringConfig : ScoringConfig | undefined ) : boolean => {
298
+ if ( scoringConfig !== void 0 ) {
299
+ const groupedResults = groupBySource ( results ) ;
300
+ let groupedUniqueResults = { ...groupedResults } ;
301
+ if ( scoringConfig . uniqueErrors ) {
302
+ groupedUniqueResults = { ...groupBySource ( uniqueErrors ( results ) ) } ;
303
+ }
304
+ return (
305
+ scoringConfig . threshold >
306
+ getScoringLevel (
307
+ getCountsBySeverity ( groupedUniqueResults ) ,
308
+ scoringConfig . scoringSubtract ,
309
+ scoringConfig . warningsSubtract ,
310
+ )
311
+ ) ;
312
+ }
313
+ return false ;
314
+ } ;
315
+
286
316
export const severeEnoughToFail = ( results : IRuleResult [ ] , failSeverity : FailSeverity ) : boolean => {
287
317
const diagnosticSeverity = getDiagnosticSeverity ( failSeverity ) ;
288
318
return results . some ( r => r . severity <= diagnosticSeverity ) ;
0 commit comments