-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathindex.mjs
More file actions
66 lines (57 loc) · 1.38 KB
/
index.mjs
File metadata and controls
66 lines (57 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// @ts-check
'use strict';
import reporters from './reporters/index.mjs';
import { invalidChangeVersion } from './rules/invalid-change-version.mjs';
import { missingChangeVersion } from './rules/missing-change-version.mjs';
import { missingIntroducedIn } from './rules/missing-introduced-in.mjs';
/**
* Lint issues in ApiDocMetadataEntry entries
*/
export class Linter {
/**
* @type {Array<import('./types.d.ts').LintIssue>}
*/
#issues = [];
/**
* @type {Array<import('./types.d.ts').LintRule>}
*/
#rules = [missingIntroducedIn, missingChangeVersion, invalidChangeVersion];
/**
* @param {ApiDocMetadataEntry} entry
* @returns {void}
*/
lint(entry) {
for (const rule of this.#rules) {
const issues = rule(entry);
if (issues.length > 0) {
this.#issues.push(...issues);
}
}
}
/**
* @param {ApiDocMetadataEntry[]} entries
* @returns {void}
*/
lintAll(entries) {
for (const entry of entries) {
this.lint(entry);
}
}
/**
* @param {keyof reporters} reporterName
*/
report(reporterName) {
const reporter = reporters[reporterName];
for (const issue of this.#issues) {
reporter(issue);
}
}
/**
* Returns whether there are any issues with a level of 'error'
*
* @returns {boolean}
*/
get hasError() {
return this.#issues.some(issue => issue.level === 'error');
}
}