@@ -2,16 +2,14 @@ import util from 'util';
2
2
import isIgnored from '@commitlint/is-ignored' ;
3
3
import parse from '@commitlint/parse' ;
4
4
import defaultRules from '@commitlint/rules' ;
5
- import toPairs from 'lodash/toPairs' ;
6
- import { buildCommitMesage } from './commit-message' ;
7
5
import {
8
6
LintRuleConfig ,
9
7
LintOptions ,
10
8
LintRuleOutcome ,
11
9
Rule ,
12
- RuleSeverity ,
13
- LintOutcome
10
+ RuleSeverity
14
11
} from '@commitlint/types' ;
12
+ import { LintOutcome } from './lint-outcome' ;
15
13
16
14
export default async function lint (
17
15
message : string ,
@@ -27,28 +25,19 @@ export default async function lint(
27
25
if (
28
26
isIgnored ( message , { defaults : opts . defaultIgnores , ignores : opts . ignores } )
29
27
) {
30
- return {
31
- valid : true ,
32
- errors : [ ] ,
33
- warnings : [ ] ,
34
- input : message
35
- } ;
28
+ return LintOutcome . empty ( { message} ) ;
36
29
}
37
30
38
31
// Parse the commit message
39
32
const parsed = await parse ( message , undefined , opts . parserOpts ) ;
33
+
40
34
if (
41
35
parsed . header === null &&
42
36
parsed . body === null &&
43
37
parsed . footer === null
44
38
) {
45
39
// Commit is empty, skip
46
- return {
47
- valid : true ,
48
- errors : [ ] ,
49
- warnings : [ ] ,
50
- input : message
51
- } ;
40
+ return LintOutcome . empty ( { message} ) ;
52
41
}
53
42
54
43
const allRules : Map < string , Rule < unknown > | Rule < never > > = new Map (
@@ -79,7 +68,7 @@ export default async function lint(
79
68
) ;
80
69
}
81
70
82
- const invalid = toPairs ( rulesConfig )
71
+ const invalid = Object . entries ( rulesConfig )
83
72
. map ( ( [ name , config ] ) => {
84
73
if ( ! Array . isArray ( config ) ) {
85
74
return new Error (
@@ -146,7 +135,7 @@ export default async function lint(
146
135
}
147
136
148
137
// Validate against all rules
149
- const results = toPairs ( rulesConfig )
138
+ const results = Object . entries ( rulesConfig )
150
139
. filter ( ( [ , [ level ] ] ) => level > 0 )
151
140
. map ( entry => {
152
141
const [ name , config ] = entry ;
@@ -175,17 +164,8 @@ export default async function lint(
175
164
} )
176
165
. filter ( ( result ) : result is LintRuleOutcome => result !== null ) ;
177
166
178
- const errors = results . filter ( result => result . level === 2 && ! result . valid ) ;
179
- const warnings = results . filter (
180
- result => result . level === 1 && ! result . valid
181
- ) ;
182
-
183
- const valid = errors . length === 0 ;
184
-
185
- return {
186
- valid,
187
- errors,
188
- warnings,
189
- input : buildCommitMesage ( parsed )
190
- } ;
167
+ return LintOutcome . fromResults ( {
168
+ results,
169
+ parsed
170
+ } ) ;
191
171
}
0 commit comments