11'use strict' ;
22
3- import createLinterEngine from './engine .mjs' ;
3+ import createContext from './context .mjs' ;
44import reporters from './reporters/index.mjs' ;
5- import rules from './rules/index.mjs' ;
65
76/**
8- * Creates a linter instance to validate ApiDocMetadataEntry entries
7+ * Creates a linter instance to validate API documentation ASTs against a
8+ * defined set of rules.
99 *
10- * @param {boolean } dryRun Whether to run the engine in dry-run mode
11- * @param {string[] } disabledRules List of disabled rules names
10+ * @param {import('./types').LintRule[] } rules - Lint rules to apply
11+ * @param {boolean } [dryRun] - If true, the linter runs without reporting
12+ * @returns {import('./types').Linter }
1213 */
13- const createLinter = ( dryRun , disabledRules ) => {
14+ const createLinter = ( rules , dryRun = false ) => {
1415 /**
15- * Retrieves all enabled rules
16- *
17- * @returns {import('./types').LintRule[] }
18- */
19- const getEnabledRules = ( ) => {
20- return Object . entries ( rules )
21- . filter ( ( [ ruleName ] ) => ! disabledRules . includes ( ruleName ) )
22- . map ( ( [ , rule ] ) => rule ) ;
23- } ;
24-
25- const engine = createLinterEngine ( getEnabledRules ( disabledRules ) ) ;
26-
27- /**
28- * Lint issues found during validations
16+ * Lint issues collected during validations.
2917 *
3018 * @type {Array<import('./types').LintIssue> }
3119 */
3220 const issues = [ ] ;
3321
3422 /**
35- * Lints all entries using the linter engine
23+ * Lints a API doc and collects issues.
3624 *
37- * @param entries
25+ * @param {import('vfile').VFile } file
26+ * @param {import('mdast').Root } tree
27+ * @returns {void }
3828 */
39- const lintAll = entries => {
40- issues . push ( ...engine . lintAll ( entries ) ) ;
29+ const lint = ( file , tree ) => {
30+ const context = createContext ( file , tree ) ;
31+
32+ for ( const rule of rules ) {
33+ rule ( context ) ;
34+ }
35+
36+ issues . push ( ...context . getIssues ( ) ) ;
4137 } ;
4238
4339 /**
44- * Reports found issues using the specified reporter
40+ * Reports collected issues using the specified reporter.
4541 *
46- * @param {keyof typeof reporters } reporterName Reporter name
42+ * @param {keyof typeof reporters } [ reporterName] Reporter name
4743 * @returns {void }
4844 */
49- const report = reporterName => {
45+ const report = ( reporterName = 'console' ) => {
5046 if ( dryRun ) {
5147 return ;
5248 }
@@ -59,7 +55,7 @@ const createLinter = (dryRun, disabledRules) => {
5955 } ;
6056
6157 /**
62- * Checks if any error-level issues were found during linting
58+ * Checks if any error-level issues were collected.
6359 *
6460 * @returns {boolean }
6561 */
@@ -68,7 +64,8 @@ const createLinter = (dryRun, disabledRules) => {
6864 } ;
6965
7066 return {
71- lintAll,
67+ issues,
68+ lint,
7269 report,
7370 hasError,
7471 } ;
0 commit comments