@@ -41,7 +41,7 @@ const CONFIG_PATTERNS = [
4141/**
4242 * Get oxfmt exclude patterns from .oxfmtrc.json.
4343 */
44- function getOxfmtExcludePatterns ( ) {
44+ function getOxfmtExcludePatterns ( ) : string [ ] {
4545 try {
4646 const oxfmtConfigPath = path . join ( process . cwd ( ) , '.oxfmtrc.json' )
4747 if ( ! existsSync ( oxfmtConfigPath ) ) {
@@ -59,7 +59,7 @@ function getOxfmtExcludePatterns() {
5959/**
6060 * Check if a file matches any of the exclude patterns.
6161 */
62- function isExcludedByOxfmt ( file , excludePatterns ) {
62+ function isExcludedByOxfmt ( file : string , excludePatterns : string [ ] ) : boolean {
6363 for ( const pattern of excludePatterns ) {
6464 // Convert glob pattern to regex-like matching.
6565 // Support **/ for directory wildcards and * for filename wildcards.
@@ -82,7 +82,10 @@ function isExcludedByOxfmt(file, excludePatterns) {
8282/**
8383 * Check if we should run all linters based on changed files.
8484 */
85- function shouldRunAllLinters ( changedFiles ) {
85+ function shouldRunAllLinters ( changedFiles : string [ ] ) : {
86+ runAll : boolean
87+ reason ?: string
88+ } {
8689 for ( const file of changedFiles ) {
8790 // Core library files
8891 if ( CORE_FILES . has ( file ) ) {
@@ -103,7 +106,7 @@ function shouldRunAllLinters(changedFiles) {
103106/**
104107 * Filter files to only those that should be linted.
105108 */
106- function filterLintableFiles ( files ) {
109+ function filterLintableFiles ( files : string [ ] ) : string [ ] {
107110 // Only include extensions actually supported by oxfmt/oxlint
108111 const lintableExtensions = new Set ( [
109112 '.js' ,
@@ -139,18 +142,27 @@ function filterLintableFiles(files) {
139142 * @param {{ stderr?: string } } result
140143 * @returns {boolean }
141144 */
142- function isOxfmtNoFilesResult ( result ) {
145+ function isOxfmtNoFilesResult ( result : { stderr ?: string } ) : boolean {
143146 const { stderr } = result
144147 return (
145- stderr ?. includes ( 'Expected at least one target file' ) ||
146- stderr ?. includes ( 'No files were processed in the specified paths' )
148+ ( stderr ?. includes ( 'Expected at least one target file' ) ||
149+ stderr ?. includes ( 'No files were processed in the specified paths' ) ) ??
150+ false
147151 )
148152}
149153
150154/**
151155 * Run linters on specific files.
152156 */
153- async function runLintOnFiles ( files , options = { } ) {
157+ interface LintOptions {
158+ fix ?: boolean
159+ quiet ?: boolean
160+ }
161+
162+ async function runLintOnFiles (
163+ files : string [ ] ,
164+ options : LintOptions = { } ,
165+ ) : Promise < number > {
154166 const { fix = false , quiet = false } = options
155167
156168 if ( ! files . length ) {
@@ -217,7 +229,7 @@ async function runLintOnFiles(files, options = {}) {
217229/**
218230 * Run linters on all files.
219231 */
220- async function runLintOnAll ( options = { } ) {
232+ async function runLintOnAll ( options : LintOptions = { } ) : Promise < number > {
221233 const { fix = false , quiet = false } = options
222234
223235 if ( ! quiet ) {
@@ -272,7 +284,21 @@ async function runLintOnAll(options = {}) {
272284/**
273285 * Get files to lint based on options.
274286 */
275- async function getFilesToLint ( options ) {
287+ interface GetFilesToLintOptions {
288+ all ?: boolean
289+ changed ?: boolean
290+ staged ?: boolean
291+ }
292+
293+ interface FilesToLintResult {
294+ files : string [ ] | 'all' | undefined
295+ reason ?: string
296+ mode : string
297+ }
298+
299+ async function getFilesToLint (
300+ options : GetFilesToLintOptions ,
301+ ) : Promise < FilesToLintResult > {
276302 const { all, changed, staged } = options
277303
278304 // If --all, return early
@@ -308,7 +334,7 @@ async function getFilesToLint(options) {
308334
309335 // Check if we should run all based on changed files
310336 const { reason, runAll } = shouldRunAllLinters ( changedFiles )
311- if ( runAll ) {
337+ if ( runAll && reason ) {
312338 return { files : 'all' , reason, mode : 'all' }
313339 }
314340
@@ -318,7 +344,7 @@ async function getFilesToLint(options) {
318344 return { files : undefined , reason : 'no lintable files changed' , mode }
319345 }
320346
321- return { files : lintableFiles , reason : undefined , mode }
347+ return { files : lintableFiles , mode }
322348}
323349
324350async function main ( ) : Promise < void > {
@@ -381,6 +407,7 @@ async function main(): Promise<void> {
381407 }
382408
383409 const quiet = isQuiet ( values )
410+ const fix = Boolean ( values [ 'fix' ] )
384411
385412 if ( ! quiet ) {
386413 printHeader ( 'Lint Runner' )
@@ -396,7 +423,7 @@ async function main(): Promise<void> {
396423 logger . step ( 'Linting specified files' )
397424 }
398425 exitCode = await runLintOnFiles ( files , {
399- fix : values . fix ,
426+ fix,
400427 quiet,
401428 } )
402429 } else {
@@ -414,7 +441,7 @@ async function main(): Promise<void> {
414441 logger . step ( `Linting all files (${ reason } )` )
415442 }
416443 exitCode = await runLintOnAll ( {
417- fix : values . fix ,
444+ fix,
418445 quiet,
419446 } )
420447 } else {
@@ -423,7 +450,7 @@ async function main(): Promise<void> {
423450 logger . step ( `Linting ${ modeText } files` )
424451 }
425452 exitCode = await runLintOnFiles ( files , {
426- fix : values . fix ,
453+ fix,
427454 quiet,
428455 } )
429456 }
0 commit comments