From 7aff28f0912c7a2af8f9a8faf939e2ea1644ace9 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 11 Aug 2026 10:48:54 +0800 Subject: [PATCH] fix(fmt): skip malformed ignore patterns --- crates/rstack-ignore/src/lib.rs | 4 +++- packages/rstack/tests/fmt/ignore.test.ts | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/rstack-ignore/src/lib.rs b/crates/rstack-ignore/src/lib.rs index 842db51f..965307ef 100644 --- a/crates/rstack-ignore/src/lib.rs +++ b/crates/rstack-ignore/src/lib.rs @@ -68,7 +68,9 @@ impl SourceMatcher { for line in source.patterns.split('\n') { let line = line.strip_suffix('\r').unwrap_or(line); let line = line.strip_prefix('\u{feff}').unwrap_or(line); - builder.add_line(None, line)?; + // Gitignore files and the previous JavaScript matcher treat malformed lines as + // nonmatching, while continuing to apply the remaining valid rules. + let _ = builder.add_line(None, line); } Ok(Self { diff --git a/packages/rstack/tests/fmt/ignore.test.ts b/packages/rstack/tests/fmt/ignore.test.ts index 1d033618..68220775 100644 --- a/packages/rstack/tests/fmt/ignore.test.ts +++ b/packages/rstack/tests/fmt/ignore.test.ts @@ -29,6 +29,13 @@ test('matches gitignore patterns relative to the config root', async () => { expect(isIgnored(path.join(rootPath, 'src/index.js'))).toBe(false); }); +test('skips malformed patterns without discarding valid patterns', async () => { + const isIgnored = await createMatcher(['ignored.js', 'malformed\\']); + + expect(isIgnored(path.join(rootPath, 'ignored.js'))).toBe(true); + expect(isIgnored(path.join(rootPath, 'other.js'))).toBe(false); +}); + test('distinguishes directory-only patterns from files', async () => { const isIgnored = await createMatcher(['dist/']); const directoryPath = path.join(rootPath, 'dist');