11/* eslint-disable no-console */
22import type { LintIssue , LintOptions , PickierConfig , PickierPlugin , RuleContext , RulesConfigMap } from './types'
33import { readFileSync , writeFileSync } from 'node:fs'
4- import { relative } from 'node:path'
4+ import { isAbsolute , relative , resolve } from 'node:path'
55import process from 'node:process'
66import { glob as tinyGlob } from 'tinyglobby'
77import { detectQuoteIssues , hasIndentIssue } from './format'
88import { formatStylish } from './formatter'
99import { getAllPlugins } from './plugins'
10- import { colors , expandPatterns , isCodeFile , loadConfigFromPath } from './utils'
10+ import { colors , expandPatterns , isCodeFile , loadConfigFromPath , shouldIgnorePath } from './utils'
1111
1212function trace ( ...args : any [ ] ) {
1313 if ( process . env . PICKIER_TRACE === '1' )
@@ -79,19 +79,22 @@ export async function runLintProgrammatic(
7979 try {
8080 const { statSync } = await import ( 'node:fs' )
8181 const st = statSync ( patterns [ 0 ] )
82- if ( st . isFile ( ) )
83- entries = [ patterns [ 0 ] ]
82+ if ( st . isFile ( ) ) {
83+ const abs = isAbsolute ( patterns [ 0 ] ) ? patterns [ 0 ] : resolve ( process . cwd ( ) , patterns [ 0 ] )
84+ entries = [ abs ]
85+ }
8486 }
8587 catch { }
8688 }
8789
8890 const simpleDirPattern = patterns . length === 1 && / \* \* \/ * \* $ / . test ( patterns [ 0 ] )
8991 if ( ! entries . length && simpleDirPattern ) {
9092 const base = patterns [ 0 ] . replace ( / \/ ? \* \* \/ * \* \* ? $ / , '' )
93+ const rootBase = isAbsolute ( base ) ? base : resolve ( process . cwd ( ) , base )
9194 try {
9295 const { readdirSync, statSync } = await import ( 'node:fs' )
9396 const { join } = await import ( 'node:path' )
94- const stack : string [ ] = [ base ]
97+ const stack : string [ ] = [ rootBase ]
9598 while ( stack . length ) {
9699 if ( signal ?. aborted )
97100 throw new Error ( 'AbortError' )
@@ -100,6 +103,8 @@ export async function runLintProgrammatic(
100103 for ( const it of items ) {
101104 const full = join ( dir , it )
102105 const st = statSync ( full )
106+ if ( shouldIgnorePath ( full , cfg . ignores ) )
107+ continue
103108 if ( st . isDirectory ( ) )
104109 stack . push ( full )
105110 else entries . push ( full )
@@ -126,7 +131,19 @@ export async function runLintProgrammatic(
126131
127132 if ( signal ?. aborted )
128133 throw new Error ( 'AbortError' )
129- const files = entries . filter ( ( f : string ) => isCodeFile ( f , extSet ) )
134+ // filter with trace counters
135+ let cntTotal = 0 ; let cntIncluded = 0 ; let cntNodeModules = 0 ; let cntIgnored = 0 ; let cntWrongExt = 0
136+ const files : string [ ] = [ ]
137+ for ( const f of entries ) {
138+ cntTotal ++
139+ const p = f . replace ( / \\ / g, '/' )
140+ if ( p . includes ( '/node_modules/' ) ) { cntNodeModules ++ ; continue }
141+ if ( shouldIgnorePath ( f , cfg . ignores ) ) { cntIgnored ++ ; continue }
142+ if ( ! isCodeFile ( f , extSet ) ) { cntWrongExt ++ ; continue }
143+ files . push ( f )
144+ cntIncluded ++
145+ }
146+ trace ( 'filter:programmatic' , { total : cntTotal , included : cntIncluded , node_modules : cntNodeModules , ignored : cntIgnored , wrongExt : cntWrongExt } )
130147
131148 let allIssues : LintIssue [ ] = [ ]
132149 for ( const file of files ) {
@@ -628,13 +645,16 @@ export async function runLint(globs: string[], options: LintOptions): Promise<nu
628645 try {
629646 const { readdirSync, statSync } = await import ( 'node:fs' )
630647 const { join } = await import ( 'node:path' )
631- const stack : string [ ] = [ base ]
648+ const rootBase = isAbsolute ( base ) ? base : resolve ( process . cwd ( ) , base )
649+ const stack : string [ ] = [ rootBase ]
632650 while ( stack . length ) {
633651 const dir = stack . pop ( ) !
634652 const items = readdirSync ( dir )
635653 for ( const it of items ) {
636654 const full = join ( dir , it )
637655 const st = statSync ( full )
656+ if ( shouldIgnorePath ( full , cfg . ignores ) )
657+ continue
638658 if ( st . isDirectory ( ) )
639659 stack . push ( full )
640660 else
@@ -662,7 +682,19 @@ export async function runLint(globs: string[], options: LintOptions): Promise<nu
662682 }
663683
664684 trace ( 'globbed entries' , entries . length )
665- const files = entries . filter ( ( f : string ) => isCodeFile ( f , extSet ) )
685+ // filter with trace counters
686+ let cntTotal = 0 ; let cntIncluded = 0 ; let cntNodeModules = 0 ; let cntIgnored = 0 ; let cntWrongExt = 0
687+ const files : string [ ] = [ ]
688+ for ( const f of entries ) {
689+ cntTotal ++
690+ const p = f . replace ( / \\ / g, '/' )
691+ if ( p . includes ( '/node_modules/' ) ) { cntNodeModules ++ ; continue }
692+ if ( shouldIgnorePath ( f , cfg . ignores ) ) { cntIgnored ++ ; continue }
693+ if ( ! isCodeFile ( f , extSet ) ) { cntWrongExt ++ ; continue }
694+ files . push ( f )
695+ cntIncluded ++
696+ }
697+ trace ( 'filter:cli' , { total : cntTotal , included : cntIncluded , node_modules : cntNodeModules , ignored : cntIgnored , wrongExt : cntWrongExt } )
666698 trace ( 'filtered files' , files . length )
667699
668700 let allIssues : LintIssue [ ] = [ ]
0 commit comments