22'use strict' ;
33
44import 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' ;
58
69/**
7- *
10+ * Lint issues in ApiDocMetadataEntry entries
811 */
912export class Linter {
10- #_hasError = false ;
13+ /**
14+ * @type {Array<import('./types.d.ts').LintIssue> }
15+ */
16+ #issues = [ ] ;
1117
1218 /**
13- * @type {Array<import('./types.d.ts').LintMessage > }
19+ * @type {Array<import('./types.d.ts').LintRule > }
1420 */
15- #messages = [ ] ;
21+ #rules = [ missingIntroducedIn , missingChangeVersion , invalidChangeVersion ] ;
1622
1723 /**
18- *
24+ * @param {ApiDocMetadataEntry } entry
25+ * @returns {void }
1926 */
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+ }
2235 }
2336
2437 /**
25- * @param {import('./types.d.ts').LintMessage } msg
38+ * @param {ApiDocMetadataEntry[] } entries
39+ * @returns {void }
2640 */
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 ) ;
3044 }
31-
32- this . #messages. push ( msg ) ;
3345 }
3446
3547 /**
@@ -38,44 +50,8 @@ export class Linter {
3850 report ( reporterName ) {
3951 const reporter = reporters [ reporterName ] ;
4052
41- for ( const message of this . #messages ) {
42- reporter ( message ) ;
53+ for ( const issue of this . #issues ) {
54+ reporter ( issue ) ;
4355 }
4456 }
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- }
8157}
0 commit comments