Skip to content

Commit

Permalink
Merge pull request #109 from snyk/fix/exludes-with-code-or-global
Browse files Browse the repository at this point in the history
  • Loading branch information
j-sp4 authored Sep 26, 2021
2 parents 0da8268 + 120bd07 commit 883fe7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ export function parseFileIgnores(path: string): string[] {
const f = fs.readFileSync(path, { encoding: 'utf8' });
if (path.includes(DOTSNYK_FILENAME)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const parsed: { exclude: { code: string[]; global: string[] } } = parseYaml(f);
const parsed: { exclude: { code?: string[]; global?: string[] } } = parseYaml(f);

const concatIgnorePath = (p: string) => `${nodePath.dirname(path)}/${p}`;
return [...parsed.exclude.code.map(concatIgnorePath), ...parsed.exclude.global.map(concatIgnorePath)];
const codeIgnoredPaths = parsed.exclude.code?.map(concatIgnorePath) || [];
const globalIgnoredPaths = parsed.exclude.global?.map(concatIgnorePath) || [];
return [...codeIgnoredPaths, ...globalIgnoredPaths];
}
rules = f
.split('\n')
Expand Down
5 changes: 5 additions & 0 deletions tests/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ describe('files', () => {
const patterns = parseFileIgnores(`${sampleProjectPath}/.snyk`);
expect(patterns).toEqual(bundleFileIgnores.slice(10));
});
it('parse dot snyk file with only one field', () => {
const patterns = parseFileIgnores(`${sampleProjectPath}/exclude/.snyk`);
console.log(patterns);
expect(patterns).toEqual(bundleFileIgnores.slice(11));
});

it('collect ignore rules', async () => {
const ignoreRules = await collectIgnoreRules([sampleProjectPath]);
Expand Down
3 changes: 3 additions & 0 deletions tests/sample-repo/exclude/.snyk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exclude:
global:
- excluded-folder/**

0 comments on commit 883fe7f

Please sign in to comment.