@@ -262,7 +262,7 @@ async function main() {
262262 }
263263
264264 const fixableFiles = Object . entries ( formattedResults )
265- . filter ( ( [ , results ] ) => results . some ( ( result ) => result . fixable ) )
265+ . filter ( ( [ , fileResults ] ) => fileResults . some ( ( flaw ) => flaw . fixable ) )
266266 . map ( ( [ file ] ) => file )
267267 if ( fixableFiles . length ) {
268268 console . log ( '' ) // Just for some whitespace before the next message
@@ -302,7 +302,7 @@ function pluralize(things, word, pluralForm = null) {
302302// (e.g., heading linters) so we need to separate the
303303// list of data files from all other files to run
304304// through markdownlint individually
305- function getFilesToLint ( paths ) {
305+ function getFilesToLint ( inputPaths ) {
306306 const fileList = {
307307 length : 0 ,
308308 content : [ ] ,
@@ -316,7 +316,7 @@ function getFilesToLint(paths) {
316316 // The path passed to Markdownlint is what is displayed
317317 // in the error report, so we want to normalize it and
318318 // and make it relative if it's absolute.
319- for ( const rawPath of paths ) {
319+ for ( const rawPath of inputPaths ) {
320320 const absPath = path . resolve ( rawPath )
321321 if ( fs . statSync ( rawPath ) . isDirectory ( ) ) {
322322 if ( isInDir ( absPath , contentDir ) ) {
@@ -427,16 +427,16 @@ function reportSummaryByRule(results, config) {
427427 result. Results are sorted by severity per file, with errors
428428 listed first then warnings.
429429*/
430- function getFormattedResults ( allResults , isPrecommit ) {
430+ function getFormattedResults ( allResults , isInPrecommitMode ) {
431431 const output = { }
432432 Object . entries ( allResults )
433433 // Each result key always has an array value, but it may be empty
434434 . filter ( ( [ , results ] ) => results . length )
435- . forEach ( ( [ key , results ] ) => {
435+ . forEach ( ( [ key , fileResults ] ) => {
436436 if ( verbose ) {
437- output [ key ] = [ ...results ]
437+ output [ key ] = [ ...fileResults ]
438438 } else {
439- const formattedResults = results . map ( ( flaw ) => formatResult ( flaw , isPrecommit ) )
439+ const formattedResults = fileResults . map ( ( flaw ) => formatResult ( flaw , isInPrecommitMode ) )
440440
441441 // Only add the file to output if there are results after filtering
442442 if ( formattedResults . length > 0 ) {
@@ -465,8 +465,8 @@ function getErrorCountByFile(results, fixed = false) {
465465 return getCountBySeverity ( results , 'error' , fixed )
466466}
467467function getCountBySeverity ( results , severityLookup , fixed ) {
468- return Object . values ( results ) . filter ( ( results ) =>
469- results . some ( ( result ) => {
468+ return Object . values ( results ) . filter ( ( fileResults ) =>
469+ fileResults . some ( ( result ) => {
470470 // If --fix was applied, we don't want to know about files that
471471 // no longer have errors or warnings.
472472 return result . severity === severityLookup && ( ! fixed || ! result . fixable )
@@ -477,7 +477,7 @@ function getCountBySeverity(results, severityLookup, fixed) {
477477// Removes null values and properties that are not relevant to content
478478// writers, adds the severity to each result object, and transforms
479479// some error and fix data into a more readable format.
480- function formatResult ( object , isPrecommit ) {
480+ function formatResult ( object , isInPrecommitMode ) {
481481 const formattedResult = { }
482482
483483 // Add severity to each result object
@@ -486,7 +486,8 @@ function formatResult(object, isPrecommit) {
486486 throw new Error ( `Rule not found in allConfig: '${ ruleName } '` )
487487 }
488488 formattedResult . severity =
489- allConfig [ ruleName ] . severity || getSearchReplaceRuleSeverity ( ruleName , object , isPrecommit )
489+ allConfig [ ruleName ] . severity ||
490+ getSearchReplaceRuleSeverity ( ruleName , object , isInPrecommitMode )
490491
491492 formattedResult . context = allConfig [ ruleName ] . context || ''
492493
@@ -540,7 +541,7 @@ function listRules() {
540541 Rules that can't be run on partials have the property
541542 `partial-markdown-files` set to false.
542543*/
543- function getMarkdownLintConfig ( errorsOnly , runRules ) {
544+ function getMarkdownLintConfig ( filterErrorsOnly , runRules ) {
544545 const config = {
545546 content : structuredClone ( defaultConfig ) ,
546547 data : structuredClone ( defaultConfig ) ,
@@ -559,7 +560,7 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
559560 // search-replace is handled differently than other rules because
560561 // it has nested metadata and rules.
561562 if (
562- errorsOnly &&
563+ filterErrorsOnly &&
563564 getRuleSeverity ( ruleConfig , isPrecommit ) !== 'error' &&
564565 ruleName !== 'search-replace'
565566 ) {
@@ -585,7 +586,7 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
585586
586587 for ( const searchRule of ruleConfig . rules ) {
587588 const searchRuleSeverity = getRuleSeverity ( searchRule , isPrecommit )
588- if ( errorsOnly && searchRuleSeverity !== 'error' ) continue
589+ if ( filterErrorsOnly && searchRuleSeverity !== 'error' ) continue
589590 // Add search-replace rules to frontmatter configuration for rules that make sense in frontmatter
590591 // This ensures rules like TODOCS detection work in frontmatter
591592 // Rules with applyToFrontmatter should ONLY run in the frontmatter pass (which lints the entire file)
@@ -640,14 +641,16 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
640641// Return the severity value of a rule but keep in mind it could be
641642// running as a precommit hook, which means the severity could be
642643// deliberately different.
643- function getRuleSeverity ( rule , isPrecommit ) {
644- return isPrecommit ? rule . precommitSeverity || rule . severity : rule . severity
644+ function getRuleSeverity ( ruleConfig , isInPrecommitMode ) {
645+ return isInPrecommitMode
646+ ? ruleConfig . precommitSeverity || ruleConfig . severity
647+ : ruleConfig . severity
645648}
646649
647650// Gets a custom rule function from the name of the rule
648651// in the configuration file
649652function getCustomRule ( ruleName ) {
650- const rule = customRules . find ( ( rule ) => rule . names . includes ( ruleName ) )
653+ const rule = customRules . find ( ( r ) => r . names . includes ( ruleName ) )
651654 if ( ! rule )
652655 throw new Error (
653656 `A content-lint rule ('${ ruleName } ') is configured in the markdownlint config file but does not have a corresponding rule function.` ,
@@ -696,24 +699,24 @@ export function shouldIncludeRule(ruleName, runRules) {
696699 fixInfo: null
697700 }
698701*/
699- function getSearchReplaceRuleSeverity ( ruleName , object , isPrecommit ) {
702+ function getSearchReplaceRuleSeverity ( ruleName , object , isInPrecommitMode ) {
700703 const pluginRuleName = object . errorDetail . split ( ':' ) [ 0 ] . trim ( )
701- const rule = allConfig [ ruleName ] . rules . find ( ( rule ) => rule . name === pluginRuleName )
702- return isPrecommit ? rule . precommitSeverity || rule . severity : rule . severity
704+ const rule = allConfig [ ruleName ] . rules . find ( ( r ) => r . name === pluginRuleName )
705+ return isInPrecommitMode ? rule . precommitSeverity || rule . severity : rule . severity
703706}
704707
705708function isOptionsValid ( ) {
706709 // paths should only contain existing files and directories
707- const paths = program . opts ( ) . paths || [ ]
708- for ( const path of paths ) {
710+ const optionPaths = program . opts ( ) . paths || [ ]
711+ for ( const filePath of optionPaths ) {
709712 try {
710- fs . statSync ( path )
713+ fs . statSync ( filePath )
711714 } catch {
712- if ( 'paths' . includes ( path ) ) {
715+ if ( 'paths' . includes ( filePath ) ) {
713716 console . log ( 'error: did you mean --paths' )
714717 } else {
715718 console . log (
716- `error: invalid --paths (-p) option. The value '${ path } ' is not a valid file or directory` ,
719+ `error: invalid --paths (-p) option. The value '${ filePath } ' is not a valid file or directory` ,
717720 )
718721 }
719722 return false
@@ -722,14 +725,14 @@ function isOptionsValid() {
722725
723726 // rules should only contain existing, correctly spelled rules
724727 const allRulesList = [ ...allRules . map ( ( rule ) => rule . names ) . flat ( ) , ...Object . keys ( allConfig ) ]
725- const rules = program . opts ( ) . rules || [ ]
726- for ( const rule of rules ) {
727- if ( ! allRulesList . includes ( rule ) ) {
728- if ( 'rules' . includes ( rule ) ) {
728+ const optionRules = program . opts ( ) . rules || [ ]
729+ for ( const ruleName of optionRules ) {
730+ if ( ! allRulesList . includes ( ruleName ) ) {
731+ if ( 'rules' . includes ( ruleName ) ) {
729732 console . log ( 'error: did you mean --rules' )
730733 } else {
731734 console . log (
732- `error: invalid --rules (-r) option. The value '${ rule } ' is not a valid rule name.` ,
735+ `error: invalid --rules (-r) option. The value '${ ruleName } ' is not a valid rule name.` ,
733736 )
734737 }
735738 return false
0 commit comments