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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ npx lostconf --include "**/tsconfig.json"

### Filtering Options

- `--skip-ignore-files` - Skip .gitignore, .prettierignore, .eslintignore, and .dockerignore files. Reduces noise by 70-80% since these files contain many intentionally missing patterns.
- `--skip-ignore-files` - Skip all ignore files (.gitignore, .prettierignore, .eslintignore, .dockerignore, .stylelintignore, etc.). Reduces noise by 70-80% since these files contain many intentionally missing patterns.
- `--exclude-parsers <names...>` - Skip specific parsers by name (e.g., `--exclude-parsers gitignore prettierignore`)
- `--include <glob...>` - Only check config files matching these glob patterns (e.g., `--include "**/tsconfig.json"`)
- `--exclude <glob...>` - Skip config files matching these glob patterns (e.g., `--exclude "**/test/**"`)
Expand Down
12 changes: 7 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ async function run(paths: string[], options: CliOptions): Promise<void> {
let parsers = getBuiltinParsers();

// Filter parsers based on options
const ignoreParserNames = ['gitignore', 'dockerignore', 'prettierignore', 'eslintignore'];
const excludeParserSet = new Set([
...(skipIgnoreFiles ? ignoreParserNames : []),
...excludeParsers
]);
// If skipIgnoreFiles is enabled, find all parsers whose names end with 'ignore'
// Note: This filters parser names (e.g., 'gitignore', 'stylelintignore'), not file paths.
// Parser names are defined in code, so a directory named 'superignore' won't be affected.
const ignoreParserNames = skipIgnoreFiles
? parsers.filter((p) => p.name.endsWith('ignore')).map((p) => p.name)
: [];
const excludeParserSet = new Set([...ignoreParserNames, ...excludeParsers]);

if (excludeParserSet.size > 0) {
parsers = parsers.filter((p) => !excludeParserSet.has(p.name));
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,41 @@ describe('CLI Integration Tests', () => {
expect(stderr).toContain('[lostconf]');
expect(stderr).toContain('Discovering config files');
});

it('should skip ignore files with --skip-ignore-files', async () => {
await fs.writeFile(path.join(testDir, '.gitignore'), 'stale-git');
await fs.writeFile(path.join(testDir, '.prettierignore'), 'stale-prettier');
await fs.writeFile(path.join(testDir, '.eslintignore'), 'stale-eslint');
await fs.writeFile(path.join(testDir, '.stylelintignore'), 'stale-stylelint');
await fs.writeFile(path.join(testDir, '.dockerignore'), 'stale-docker');
await fs.writeFile(path.join(testDir, 'tsconfig.json'), '{"exclude": ["stale-ts"]}');

const { stdout } = await execAsync(
`node ${cliPath} ${testDir} --format json --skip-ignore-files --show-all`
);

const result = JSON.parse(stdout);
// Should only find the tsconfig.json stale pattern, not the ignore files
expect(result.findings).toHaveLength(1);
expect(result.findings[0].pattern).toBe('stale-ts');
});

it('should skip stylelintignore specifically with --skip-ignore-files', async () => {
await fs.writeFile(path.join(testDir, '.stylelintignore'), 'stale-stylelint-pattern');

// Without --skip-ignore-files, should find the stale pattern
const { stdout: withoutSkip } = await execAsync(
`node ${cliPath} ${testDir} --format json --show-all`
);
const resultWithout = JSON.parse(withoutSkip);
expect(resultWithout.findings.length).toBeGreaterThan(0);
expect(resultWithout.findings[0].pattern).toBe('stale-stylelint-pattern');

// With --skip-ignore-files, should skip .stylelintignore
const { stdout: withSkip } = await execAsync(
`node ${cliPath} ${testDir} --format json --skip-ignore-files --show-all`
);
const resultWith = JSON.parse(withSkip);
expect(resultWith.findings).toHaveLength(0);
});
});