Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 13 additions & 39 deletions packages/rstack/src/fmt/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ResolvedFmtConfig } from './types.ts';
* Prettier already skips other generated lock files when it cannot infer a parser, so this list
* contains only the additional defaults owned by `rs fmt`.
*/
const defaultIgnoreNames = [
const defaultIgnorePatterns = [
'package-lock.json',
'pnpm-lock.yaml',
'skills-lock.json',
Expand Down Expand Up @@ -44,20 +44,6 @@ interface CreateIgnoreMatcherOptions {
precheck?: IgnorePredicate;
}

const createDefaultMatcher = (): IgnoreMatcher => {
const suffixes = defaultIgnoreNames.map((name) => `${path.sep}${name}`);

return (filePath) => suffixes.some((suffix) => filePath.endsWith(suffix));
};

const combineIgnorePredicates = (
first: IgnorePredicate,
second: IgnorePredicate,
): IgnorePredicate => {
return (filePath, isDirectory = false) =>
first(filePath, isDirectory) || second(filePath, isDirectory);
};

const createSourceMatcher = (
sources: IgnoreSource[],
precheck?: IgnorePredicate,
Expand Down Expand Up @@ -107,30 +93,18 @@ const createIgnoreMatcher = async ({
const ignoreFileSources = await Promise.all(
ignorePaths.map((ignorePath) => loadIgnoreSource(cwd, ignorePath)),
);
if (config.ignorePatterns.length) {
return createSourceMatcher(
[
{
rootPath: config.rootPath,
patterns: [...defaultIgnoreNames, ...config.ignorePatterns].join(
'\n',
),
},
...ignoreFileSources,
],
precheck,
);
}

const defaultMatcher = createDefaultMatcher();
const matcher = precheck
? combineIgnorePredicates(precheck, defaultMatcher)
: defaultMatcher;
if (ignoreFileSources.length === 0) {
return matcher;
}

return createSourceMatcher(ignoreFileSources, matcher);
return createSourceMatcher(
[
{
rootPath: config.rootPath,
patterns: [...defaultIgnorePatterns, ...config.ignorePatterns].join(
'\n',
),
},
...ignoreFileSources,
],
precheck,
);
};

export { createIgnoreMatcher };
Expand Down
2 changes: 1 addition & 1 deletion packages/rstack/tests/fmt/discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ test('excludes .rstack from discovery', async () => {
});

const customCacheCases: { config?: FmtConfig; name: string }[] = [
{ name: 'with scalar matching' },
{ name: 'without configured ignore patterns' },
{
name: 'before native matching',
config: { ignorePatterns: ['generated/'] },
Expand Down
2 changes: 1 addition & 1 deletion packages/rstack/tests/fmt/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test('ignores common lock files by default and allows explicit negation', async
true,
);
expect(isIgnored(path.join(rootPath, 'packages/app/PNPM-LOCK.YAML'))).toBe(
false,
true,
);
expect(isIgnored(path.join(rootPath, '../shared/pnpm-lock.yaml'))).toBe(true);
expect(isIgnored(path.join(rootPath, 'pnpm-lock.yaml.backup'))).toBe(false);
Expand Down
Loading