@@ -127,7 +127,6 @@ program
127127
128128const {
129129 fix,
130- paths,
131130 errorsOnly,
132131 rules,
133132 summaryByRule,
@@ -144,8 +143,13 @@ main()
144143async function main ( ) {
145144 if ( ! isOptionsValid ( ) ) return
146145
146+ // Get the updated paths after validation (invalid paths will have been filtered out)
147+ const validatedPaths = program . opts ( ) . paths
148+
147149 // If paths has not been specified, lint all files
148- const files = getFilesToLint ( ( summaryByRule && ALL_CONTENT_DIR ) || paths || getChangedFiles ( ) )
150+ const files = getFilesToLint (
151+ ( summaryByRule && ALL_CONTENT_DIR ) || validatedPaths || getChangedFiles ( ) ,
152+ )
149153
150154 if ( new Set ( files . data ) . size !== files . data . length ) throw new Error ( 'Duplicate data files' )
151155 if ( new Set ( files . content ) . size !== files . content . length )
@@ -162,7 +166,7 @@ async function main() {
162166 const start = Date . now ( )
163167
164168 // Initializes the config to pass to markdownlint based on the input options
165- const { config, configuredRules } = getMarkdownLintConfig ( errorsOnly , rules || [ ] )
169+ const { config, configuredRules } = getMarkdownLintConfig ( errorsOnly , rules )
166170
167171 // Run Markdownlint for content directory
168172 const resultContent = ( await markdownlint . promises . markdownlint ( {
@@ -619,7 +623,7 @@ function listRules() {
619623*/
620624function getMarkdownLintConfig (
621625 filterErrorsOnly : boolean ,
622- runRules : string [ ] ,
626+ runRules : string [ ] | undefined ,
623627) : MarkdownLintConfigResult {
624628 const config = {
625629 content : structuredClone ( defaultConfig ) ,
@@ -793,21 +797,27 @@ function getSearchReplaceRuleSeverity(
793797function isOptionsValid ( ) {
794798 // paths should only contain existing files and directories
795799 const optionPaths = program . opts ( ) . paths || [ ]
800+ const validPaths = [ ]
801+
796802 for ( const filePath of optionPaths ) {
797803 try {
798804 fs . statSync ( filePath )
805+ validPaths . push ( filePath ) // Keep track of valid paths
799806 } catch {
800807 if ( 'paths' . includes ( filePath ) ) {
801- console . log ( 'error : did you mean --paths')
808+ console . warn ( 'warning : did you mean --paths')
802809 } else {
803- console . log (
804- `error: invalid --paths (-p) option. The value '${ filePath } ' is not a valid file or directory` ,
805- )
810+ console . warn ( `warning: the value '${ filePath } ' was not found. Skipping this path.` )
806811 }
807- return false
812+ // Continue processing - don't return false here
808813 }
809814 }
810815
816+ // Update the program options to only include valid paths
817+ if ( optionPaths . length > 0 ) {
818+ program . setOptionValue ( 'paths' , validPaths )
819+ }
820+
811821 // rules should only contain existing, correctly spelled rules
812822 const allRulesList = [ ...allRules . map ( ( rule ) => rule . names ) . flat ( ) , ...Object . keys ( allConfig ) ]
813823 const optionRules = program . opts ( ) . rules || [ ]
@@ -823,7 +833,9 @@ function isOptionsValid() {
823833 return false
824834 }
825835 }
826- return true
836+
837+ // Only return false if paths were specified but none are valid
838+ return optionPaths . length === 0 || validPaths . length > 0
827839}
828840
829841function isAFixtureMdFile ( filePath : string ) : boolean {
0 commit comments