Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Addresses issue #16 #18

Merged
merged 1 commit into from
Oct 27, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/modules/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ module.exports = function FileContent(options) {
})();

(function executeChecksAgainstFiles() {
async.eachSeries(patterns, (pattern, nextPattern) => {
async.eachSeries(fileManager.languageFiles, (file, nextFile) => {
fileManager.readFile(file, (err, contents) => {
const checkPatternAgainstFiles = (pattern, nextPattern) => {
const checkPatternAgainstLanguageFile = (file, nextFile) => {
const validateFileContents = (err, contents) => {
if(err) { return nextFile(); }
pattern.check(file, contents);
nextFile();
});
}, nextPattern);
}, done);
async.setImmediate(nextFile);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

};
fileManager.readFile(file, validateFileContents);
};
async.eachSeries(fileManager.languageFiles, checkPatternAgainstLanguageFile, nextPattern);
};
async.eachSeries(patterns, checkPatternAgainstFiles, done);
})();

};
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/entropy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = function Entropy(options) {
}
}
} while (m);
nextFile();
async.setImmediate(nextFile);
};

(function executeChecksAgainstFiles() {
Expand Down
18 changes: 13 additions & 5 deletions test/modules/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ const should = require('should');
const FileManager = require('../../lib/fileManager');

describe('Contents', () => {
let contents, mockResults;
let contents, mockResults, fileManager;
beforeEach(() => {
mockResults = deride.stub(['low', 'medium', 'high', 'critical']);
const nullLogger = deride.stub(['log', 'debug', 'error']);
const fileManager = new FileManager({
target: path.join(__dirname, '../samples/nodejs'),
logger: nullLogger
});

contents = new Contents({
patterns: path.join(__dirname, '../samples/contents.js')
});
fileManager = deride.wrap(new FileManager({
target: path.join(__dirname, '../samples/nodejs'),
logger: nullLogger
}));

should(contents.handles(fileManager)).eql(true);
});

Expand All @@ -27,4 +28,11 @@ describe('Contents', () => {
});
contents.run(mockResults, done);
});

it('should not explode when there are more than 115 files', done => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does actually fail if you remove the fix! So I'm confident this sorted it.

for(var x = 0; x < 3000; x++) {
fileManager.languageFiles.push(fileManager.languageFiles[1]);
}
contents.run(mockResults, done);
});
});
1 change: 1 addition & 0 deletions test/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ describe('Scan', () => {
done();
});
});

});