@@ -9,7 +9,7 @@ import type { ResolvedFmtConfig } from './types.ts';
99 * Prettier already skips other generated lock files when it cannot infer a parser, so this list
1010 * contains only the additional defaults owned by `rs fmt`.
1111 */
12- const defaultIgnorePatterns = [ 'package-lock.json' , 'pnpm-lock.yaml' ] ;
12+ const defaultIgnoreNames = new Set ( [ 'package-lock.json' , 'pnpm-lock.yaml' ] ) ;
1313
1414type IgnoreMatcher = ( filePath : string , isDirectory ?: boolean ) => boolean ;
1515
@@ -20,6 +20,21 @@ interface CreateIgnoreMatcherOptions {
2020 ignorePaths ?: string [ ] ;
2121}
2222
23+ const createDefaultIgnoreMatcher = ( rootPath : string ) : IgnoreMatcher => {
24+ const rootPrefix = rootPath . endsWith ( path . sep ) ? rootPath : `${ rootPath } ${ path . sep } ` ;
25+
26+ return ( filePath ) => {
27+ const relativePath = filePath . startsWith ( rootPrefix )
28+ ? filePath . slice ( rootPrefix . length )
29+ : path . relative ( rootPath , filePath ) ;
30+
31+ return (
32+ relativePath !== '' &&
33+ relativePath . split ( path . sep ) . some ( ( segment ) => defaultIgnoreNames . has ( segment ) )
34+ ) ;
35+ } ;
36+ } ;
37+
2338const createPatternMatcher = ( rootPath : string , patterns : string ) : IgnoreMatcher => {
2439 const matcher = createIgnore ( { allowRelativePaths : true } ) . add ( patterns ) ;
2540 const rootPrefix = rootPath . endsWith ( path . sep ) ? rootPath : `${ rootPath } ${ path . sep } ` ;
@@ -58,10 +73,12 @@ const createIgnoreMatcher = async ({
5873 cwd,
5974 ignorePaths = [ ] ,
6075} : CreateIgnoreMatcherOptions ) : Promise < IgnoreMatcher > => {
61- const configMatcher = createPatternMatcher (
62- config . rootPath ,
63- [ ...defaultIgnorePatterns , ...config . ignorePatterns ] . join ( '\n' ) ,
64- ) ;
76+ const configMatcher = config . ignorePatterns . length
77+ ? createPatternMatcher (
78+ config . rootPath ,
79+ [ ...defaultIgnoreNames , ...config . ignorePatterns ] . join ( '\n' ) ,
80+ )
81+ : createDefaultIgnoreMatcher ( config . rootPath ) ;
6582 if ( ignorePaths . length === 0 ) {
6683 return configMatcher ;
6784 }
0 commit comments