1
- import { LogSeverity , LogType } from '../../Parser' ;
1
+ import { LintSeverity , LintItem } from '../../Parser' ;
2
2
import { Comment , CommentStructure } from '../@types/CommentTypes' ;
3
3
import { MessageUtil } from './message.util' ;
4
4
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 ;
8
11
9
12
if ( ! line ) return state ;
10
13
11
14
const currentComment = getOrInitComment ( state , file , line , nLines ) ;
12
- const updatedComment = updateComment ( currentComment , log , suppressRules ) ;
15
+ const updatedComment = updateComment ( currentComment , item , suppressRules ) ;
13
16
return updateCommentStructure ( state , updatedComment ) ;
14
17
} , { } ) ;
15
18
@@ -35,8 +38,12 @@ function getOrInitComment(
35
38
) ;
36
39
}
37
40
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 ;
40
47
const { text : currentText } = currentComment ;
41
48
const msgWithSuppression = isSuppressed ? `(SUPPRESSED) ${ msg } ` : msg ;
42
49
const text = MessageUtil . createMessageWithEmoji ( msgWithSuppression , severity ) ;
@@ -45,43 +52,43 @@ function buildText(currentComment: Comment, log: LogType, isSuppressed: boolean)
45
52
46
53
function calculateErrors (
47
54
currentComment : Comment ,
48
- log : LogType ,
55
+ item : LintItem ,
49
56
isSuppressed : boolean ,
50
57
) : number {
51
58
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 ) ;
54
61
}
55
62
56
63
function calculateWarnings (
57
64
currentComment : Comment ,
58
- log : LogType ,
65
+ item : LintItem ,
59
66
isSuppressed : boolean ,
60
67
) : number {
61
68
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 ) ;
64
71
}
65
72
66
73
function calculateSuppresses ( currentComment : Comment , isSuppressed : boolean ) : number {
67
74
return currentComment . suppresses + ( isSuppressed ? 1 : 0 ) ;
68
75
}
69
76
70
- function shouldBeSuppressed ( log : LogType , suppressRules : Array < string > ) : boolean {
77
+ function shouldBeSuppressed ( item : LintItem , suppressRules : Array < string > ) : boolean {
71
78
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 ) ) ;
73
80
}
74
81
75
82
function updateComment (
76
83
currentComment : Comment ,
77
- log : LogType ,
84
+ item : LintItem ,
78
85
suppressRules : Array < string > ,
79
86
) : Comment {
80
- const isSuppressed = shouldBeSuppressed ( log , suppressRules ) ;
87
+ const isSuppressed = shouldBeSuppressed ( item , suppressRules ) ;
81
88
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 ) ,
85
92
suppresses : calculateSuppresses ( currentComment , isSuppressed ) ,
86
93
file : currentComment . file ,
87
94
line : currentComment . line ,
0 commit comments