Skip to content

Commit bfe9ffd

Browse files
authored
fix(fmt): skip malformed ignore patterns (#303)
1 parent 9c54c03 commit bfe9ffd

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

crates/rstack-ignore/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ impl SourceMatcher {
6868
for line in source.patterns.split('\n') {
6969
let line = line.strip_suffix('\r').unwrap_or(line);
7070
let line = line.strip_prefix('\u{feff}').unwrap_or(line);
71-
builder.add_line(None, line)?;
71+
// Gitignore files and the previous JavaScript matcher treat malformed lines as
72+
// nonmatching, while continuing to apply the remaining valid rules.
73+
let _ = builder.add_line(None, line);
7274
}
7375

7476
Ok(Self {

packages/rstack/tests/fmt/ignore.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ test('matches gitignore patterns relative to the config root', async () => {
2929
expect(isIgnored(path.join(rootPath, 'src/index.js'))).toBe(false);
3030
});
3131

32+
test('skips malformed patterns without discarding valid patterns', async () => {
33+
const isIgnored = await createMatcher(['ignored.js', 'malformed\\']);
34+
35+
expect(isIgnored(path.join(rootPath, 'ignored.js'))).toBe(true);
36+
expect(isIgnored(path.join(rootPath, 'other.js'))).toBe(false);
37+
});
38+
3239
test('distinguishes directory-only patterns from files', async () => {
3340
const isIgnored = await createMatcher(['dist/']);
3441
const directoryPath = path.join(rootPath, 'dist');

0 commit comments

Comments
 (0)