Skip to content

Commit

Permalink
Merge pull request #1971 from snyk/fix/skip-empty-error-iac
Browse files Browse the repository at this point in the history
fix: Skip empty files on IaC scanning.
  • Loading branch information
ipapast authored May 28, 2021
2 parents ebe36cd + 0fd970f commit 5820119
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 1 addition & 5 deletions src/cli/commands/test/iac-local-execution/file-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function loadFiles(
if (filesToScan.length === 0) {
throw new NoFilesToScanError();
}
return filesToScan;
return filesToScan.filter((file) => file.fileContent !== '');
}

function getFilePathsFromDirectory(
Expand Down Expand Up @@ -71,10 +71,6 @@ export async function tryLoadFileData(
await fs.readFile(pathToScan, DEFAULT_ENCODING)
).toString();

if (fileContent === '') {
return null;
}

return {
filePath: pathToScan,
fileType: fileType as IacFileTypes,
Expand Down
7 changes: 3 additions & 4 deletions test/jest/unit/iac-unit-tests/file-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,13 @@ describe('loadFiles', () => {
});

describe('empty files', () => {
it('single empty file does not get scanned and throws an error', async () => {
it('single empty file gets scanned and returns no output', async () => {
mockFs({
[emptyFileStub.filePath]: emptyFileStub.fileContent,
});

await expect(loadFiles(emptyFileStub.filePath)).rejects.toThrow(
NoFilesToScanError,
);
const loadedFiles = await loadFiles(emptyFileStub.filePath);
expect(loadedFiles).toEqual([]);
});

it('empty file in directory is skipped', async () => {
Expand Down

0 comments on commit 5820119

Please sign in to comment.