11#!/usr/bin/env node
22
33import { resolve } from 'node:path' ;
4- import { argv } from 'node:process' ;
4+ import { argv , exit } from 'node:process' ;
55
66import { Command , Option } from 'commander' ;
77
@@ -12,6 +12,9 @@ import generators from '../src/generators/index.mjs';
1212import createMarkdownLoader from '../src/loaders/markdown.mjs' ;
1313import createMarkdownParser from '../src/parsers/markdown.mjs' ;
1414import createNodeReleases from '../src/releases.mjs' ;
15+ import createLinter from '../src/linter/index.mjs' ;
16+ import reporters from '../src/linter/reporters/index.mjs' ;
17+ import rules from '../src/linter/rules/index.mjs' ;
1518
1619const availableGenerators = Object . keys ( generators ) ;
1720
@@ -50,6 +53,19 @@ program
5053 'Set the processing target modes'
5154 ) . choices ( availableGenerators )
5255 )
56+ . addOption (
57+ new Option ( '--disable-rule [rule...]' , 'Disable a specific linter rule' )
58+ . choices ( Object . keys ( rules ) )
59+ . default ( [ ] )
60+ )
61+ . addOption (
62+ new Option ( '--lint-dry-run' , 'Run linter in dry-run mode' ) . default ( false )
63+ )
64+ . addOption (
65+ new Option ( '-r, --reporter [reporter]' , 'Specify the linter reporter' )
66+ . choices ( Object . keys ( reporters ) )
67+ . default ( 'console' )
68+ )
5369 . parse ( argv ) ;
5470
5571/**
@@ -60,13 +76,27 @@ program
6076 * @property {string } output Specifies the directory where output files will be saved.
6177 * @property {Target[] } target Specifies the generator target mode.
6278 * @property {string } version Specifies the target Node.js version.
63- * @property {string } changelog Specifies the path to the Node.js CHANGELOG.md file
79+ * @property {string } changelog Specifies the path to the Node.js CHANGELOG.md file.
80+ * @property {string[] } disableRule Specifies the linter rules to disable.
81+ * @property {boolean } lintDryRun Specifies whether the linter should run in dry-run mode.
82+ * @property {keyof reporters } reporter Specifies the linter reporter.
6483 *
6584 * @name ProgramOptions
6685 * @type {Options }
6786 * @description The return type for values sent to the program from the CLI.
6887 */
69- const { input, output, target = [ ] , version, changelog } = program . opts ( ) ;
88+ const {
89+ input,
90+ output,
91+ target = [ ] ,
92+ version,
93+ changelog,
94+ disableRule,
95+ lintDryRun,
96+ reporter,
97+ } = program . opts ( ) ;
98+
99+ const linter = createLinter ( lintDryRun , disableRule ) ;
70100
71101const { loadFiles } = createMarkdownLoader ( ) ;
72102const { parseApiDocs } = createMarkdownParser ( ) ;
@@ -80,6 +110,8 @@ const { runGenerators } = createGenerator(parsedApiDocs);
80110// Retrieves Node.js release metadata from a given Node.js version and CHANGELOG.md file
81111const { getAllMajors } = createNodeReleases ( changelog ) ;
82112
113+ linter . lintAll ( parsedApiDocs ) ;
114+
83115await runGenerators ( {
84116 // A list of target modes for the API docs parser
85117 generators : target ,
@@ -92,3 +124,7 @@ await runGenerators({
92124 // A list of all Node.js major versions with LTS status
93125 releases : await getAllMajors ( ) ,
94126} ) ;
127+
128+ linter . report ( reporter ) ;
129+
130+ exit ( Number ( linter . hasError ( ) ) ) ;
0 commit comments