2
2
'use strict' ;
3
3
4
4
import reporters from './reporters/index.mjs' ;
5
+ import { invalidChangeVersion } from './rules/invalid-change-version.mjs' ;
6
+ import { missingChangeVersion } from './rules/missing-change-version.mjs' ;
7
+ import { missingIntroducedIn } from './rules/missing-introduced-in.mjs' ;
5
8
6
9
/**
7
- *
10
+ * Lint issues in ApiDocMetadataEntry entries
8
11
*/
9
12
export class Linter {
10
- #_hasError = false ;
13
+ /**
14
+ * @type {Array<import('./types.d.ts').LintIssue> }
15
+ */
16
+ #issues = [ ] ;
11
17
12
18
/**
13
- * @type {Array<import('./types.d.ts').LintMessage > }
19
+ * @type {Array<import('./types.d.ts').LintRule > }
14
20
*/
15
- #messages = [ ] ;
21
+ #rules = [ missingIntroducedIn , missingChangeVersion , invalidChangeVersion ] ;
16
22
17
23
/**
18
- *
24
+ * @param {ApiDocMetadataEntry } entry
25
+ * @returns {void }
19
26
*/
20
- get hasError ( ) {
21
- return this . #_hasError;
27
+ lint ( entry ) {
28
+ for ( const rule of this . #rules) {
29
+ const issues = rule ( entry ) ;
30
+
31
+ if ( issues . length > 0 ) {
32
+ this . #issues. push ( ...issues ) ;
33
+ }
34
+ }
22
35
}
23
36
24
37
/**
25
- * @param {import('./types.d.ts').LintMessage } msg
38
+ * @param {ApiDocMetadataEntry[] } entries
39
+ * @returns {void }
26
40
*/
27
- log ( msg ) {
28
- if ( msg . level === 'error' ) {
29
- this . #_hasError = true ;
41
+ lintAll ( entries ) {
42
+ for ( const entry of entries ) {
43
+ this . lint ( entry ) ;
30
44
}
31
-
32
- this . #messages. push ( msg ) ;
33
45
}
34
46
35
47
/**
@@ -38,44 +50,8 @@ export class Linter {
38
50
report ( reporterName ) {
39
51
const reporter = reporters [ reporterName ] ;
40
52
41
- for ( const message of this . #messages ) {
42
- reporter ( message ) ;
53
+ for ( const issue of this . #issues ) {
54
+ reporter ( issue ) ;
43
55
}
44
56
}
45
-
46
- /**
47
- * @param {string } msg
48
- * @param {import('./types.d.ts').LintMessageLocation | undefined } location
49
- */
50
- info ( msg , location ) {
51
- this . log ( {
52
- level : 'info' ,
53
- msg,
54
- location,
55
- } ) ;
56
- }
57
-
58
- /**
59
- * @param {string } msg
60
- * @param {import('./types.d.ts').LintMessageLocation | undefined } location
61
- */
62
- warn ( msg , location ) {
63
- this . log ( {
64
- level : 'warn' ,
65
- msg,
66
- location,
67
- } ) ;
68
- }
69
-
70
- /**
71
- * @param {string } msg
72
- * @param {import('./types.d.ts').LintMessageLocation | undefined } location
73
- */
74
- error ( msg , location ) {
75
- this . log ( {
76
- level : 'error' ,
77
- msg,
78
- location,
79
- } ) ;
80
- }
81
57
}
0 commit comments