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

Commit

Permalink
Addresses issue #16
Browse files Browse the repository at this point in the history
This was a nested async callstack issue, see:

  - See: caolan/async#1265
  • Loading branch information
Stono committed Oct 24, 2017
1 parent ad07c2b commit 39a8468
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
17 changes: 10 additions & 7 deletions lib/modules/content/index.js
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);
};
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
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
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 => {
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
Expand Up @@ -38,4 +38,5 @@ describe('Scan', () => {
done();
});
});

});

0 comments on commit 39a8468

Please sign in to comment.