diff --git a/src/files.ts b/src/files.ts index b76d6905..b96759e4 100644 --- a/src/files.ts +++ b/src/files.ts @@ -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') diff --git a/tests/files.spec.ts b/tests/files.spec.ts index 605e5768..bf88bbfb 100644 --- a/tests/files.spec.ts +++ b/tests/files.spec.ts @@ -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]); diff --git a/tests/sample-repo/exclude/.snyk b/tests/sample-repo/exclude/.snyk new file mode 100644 index 00000000..b81bbeac --- /dev/null +++ b/tests/sample-repo/exclude/.snyk @@ -0,0 +1,3 @@ +exclude: + global: + - excluded-folder/** \ No newline at end of file