11import fs from "node:fs/promises" ;
22import path from "node:path" ;
3- import { NormalizedConfig } from "./normalizer" ;
43
54/**
65 * Checks whether the given file contains Git merge conflict markers.
@@ -23,9 +22,13 @@ const hasConflict = async (filePath: string): Promise<boolean> => {
2322export interface CollectFilesOptions {
2423 /** Root directory to start traversal (defaults to `process.cwd()`). */
2524 root ?: string ;
25+
26+ /** Function used to decide if a file should be considered at all. */
27+ fileFilter : ( filePath : string ) => boolean ;
28+
2629 /**
27- * Include files that match `fileFilter` even if they do not contain
28- * merge conflicts. Defaults to `false`.
30+ * Whether to include files even if they don’t contain conflicts.
31+ * Defaults to `false`.
2932 */
3033 includeNonConflicted ?: boolean ;
3134}
@@ -35,17 +38,14 @@ export interface CollectFilesOptions {
3538 *
3639 * - By default, only conflicted files are returned.
3740 * - If `includeNonConflicted` is enabled, matching files are always included
38- * (skipping conflict check).
41+ * (conflict check is skipped ).
3942 *
40- * @param config - Normalized configuration containing `fileFilter`.
41- * @param options - Behavior flags (e.g., `includeNonConflicted`).
43+ * @param options - Collection options, including `fileFilter` and traversal root.
4244 * @returns A promise that resolves with an array of matching file paths.
4345 */
44- export const collectFiles = async (
45- config : NormalizedConfig ,
46- options : CollectFilesOptions = { } ,
47- ) : Promise < string [ ] > => {
48- const { root = process . cwd ( ) , includeNonConflicted = false } = options ;
46+ export const collectFiles = async ( options : CollectFilesOptions ) : Promise < string [ ] > => {
47+ const { root = process . cwd ( ) , fileFilter, includeNonConflicted = false } = options ;
48+
4949 const allFiles : string [ ] = [ ] ;
5050
5151 /**
@@ -62,15 +62,13 @@ export const collectFiles = async (
6262
6363 if ( entry . isDirectory ( ) ) {
6464 await walk ( fullPath ) ;
65- } else if ( config . fileFilter ( fullPath ) ) {
65+ } else if ( fileFilter ( fullPath ) ) {
6666 if ( includeNonConflicted ) {
6767 allFiles . push ( fullPath ) ;
68+ } else if ( await hasConflict ( fullPath ) ) {
69+ allFiles . push ( fullPath ) ;
6870 } else {
69- if ( await hasConflict ( fullPath ) ) {
70- allFiles . push ( fullPath ) ;
71- } else {
72- console . info ( `Skipped (no conflicts): ${ fullPath } ` ) ;
73- }
71+ console . info ( `Skipped (no conflicts): ${ fullPath } ` ) ;
7472 }
7573 }
7674 }
0 commit comments