1- import { LogSeverity , LogType } from '../../Parser' ;
1+ import { LintSeverity , LintItem } from '../../Parser' ;
22import { Comment , CommentStructure } from '../@types/CommentTypes' ;
33import { MessageUtil } from './message.util' ;
44
5- export function groupComments ( logs : LogType [ ] , suppressRules : Array < string > ) : Comment [ ] {
6- const commentMap = logs . reduce ( ( state : CommentStructure , log ) => {
7- const { source : file , line, nLines } = log ;
5+ export function groupComments (
6+ items : LintItem [ ] ,
7+ suppressRules : Array < string > ,
8+ ) : Comment [ ] {
9+ const commentMap = items . reduce ( ( state : CommentStructure , item ) => {
10+ const { source : file , line, nLines } = item ;
811
912 if ( ! line ) return state ;
1013
1114 const currentComment = getOrInitComment ( state , file , line , nLines ) ;
12- const updatedComment = updateComment ( currentComment , log , suppressRules ) ;
15+ const updatedComment = updateComment ( currentComment , item , suppressRules ) ;
1316 return updateCommentStructure ( state , updatedComment ) ;
1417 } , { } ) ;
1518
@@ -35,8 +38,12 @@ function getOrInitComment(
3538 ) ;
3639}
3740
38- function buildText ( currentComment : Comment , log : LogType , isSuppressed : boolean ) : string {
39- const { severity, msg } = log ;
41+ function buildText (
42+ currentComment : Comment ,
43+ item : LintItem ,
44+ isSuppressed : boolean ,
45+ ) : string {
46+ const { severity, msg } = item ;
4047 const { text : currentText } = currentComment ;
4148 const msgWithSuppression = isSuppressed ? `(SUPPRESSED) ${ msg } ` : msg ;
4249 const text = MessageUtil . createMessageWithEmoji ( msgWithSuppression , severity ) ;
@@ -45,43 +52,43 @@ function buildText(currentComment: Comment, log: LogType, isSuppressed: boolean)
4552
4653function calculateErrors (
4754 currentComment : Comment ,
48- log : LogType ,
55+ item : LintItem ,
4956 isSuppressed : boolean ,
5057) : number {
5158 if ( isSuppressed ) return currentComment . errors ;
52- const { severity } = log ;
53- return currentComment . errors + ( severity === LogSeverity . error ? 1 : 0 ) ;
59+ const { severity } = item ;
60+ return currentComment . errors + ( severity === LintSeverity . error ? 1 : 0 ) ;
5461}
5562
5663function calculateWarnings (
5764 currentComment : Comment ,
58- log : LogType ,
65+ item : LintItem ,
5966 isSuppressed : boolean ,
6067) : number {
6168 if ( isSuppressed ) return currentComment . warnings ;
62- const { severity } = log ;
63- return currentComment . warnings + ( severity === LogSeverity . warning ? 1 : 0 ) ;
69+ const { severity } = item ;
70+ return currentComment . warnings + ( severity === LintSeverity . warning ? 1 : 0 ) ;
6471}
6572
6673function calculateSuppresses ( currentComment : Comment , isSuppressed : boolean ) : number {
6774 return currentComment . suppresses + ( isSuppressed ? 1 : 0 ) ;
6875}
6976
70- function shouldBeSuppressed ( log : LogType , suppressRules : Array < string > ) : boolean {
77+ function shouldBeSuppressed ( item : LintItem , suppressRules : Array < string > ) : boolean {
7178 const suppressRegexps : Array < RegExp > = suppressRules . map ( ( rule ) => new RegExp ( rule ) ) ;
72- return suppressRegexps . some ( ( regexp ) => regexp . test ( log . ruleId ) ) ;
79+ return suppressRegexps . some ( ( regexp ) => regexp . test ( item . ruleId ) ) ;
7380}
7481
7582function updateComment (
7683 currentComment : Comment ,
77- log : LogType ,
84+ item : LintItem ,
7885 suppressRules : Array < string > ,
7986) : Comment {
80- const isSuppressed = shouldBeSuppressed ( log , suppressRules ) ;
87+ const isSuppressed = shouldBeSuppressed ( item , suppressRules ) ;
8188 return {
82- text : buildText ( currentComment , log , isSuppressed ) ,
83- errors : calculateErrors ( currentComment , log , isSuppressed ) ,
84- warnings : calculateWarnings ( currentComment , log , isSuppressed ) ,
89+ text : buildText ( currentComment , item , isSuppressed ) ,
90+ errors : calculateErrors ( currentComment , item , isSuppressed ) ,
91+ warnings : calculateWarnings ( currentComment , item , isSuppressed ) ,
8592 suppresses : calculateSuppresses ( currentComment , isSuppressed ) ,
8693 file : currentComment . file ,
8794 line : currentComment . line ,
0 commit comments