in DevSkim-VSCode-Plugin/server/src/devskimCLI.ts [272:358]
private async analyze(directories : DirectoryInfo[] ) : Promise<void>
{
let FilesToLog : FileInfo[] = [];
let dir = require('node-dir');
dir.files(directories[0].directoryPath, async (err, files) => {
if (err)
{
console.log(err);
throw err;
}
if(files == undefined || files.length < 1)
{
console.log("No files found in directory %s", directories[0].directoryPath);
return;
}
let fs = require("fs");
const dsSuppression = new DevSkimSuppression(this.settings);
const logger : DebugLogger = new DebugLogger(this.settings);
var analysisEngine : DevSkimWorker = new DevSkimWorker(logger, dsSuppression, this.settings);
await analysisEngine.init();
let pathOp : PathOperations = new PathOperations();
var problems : DevSkimProblem[] = [];
for(let directory of directories)
{
for(let curFile of files)
{
if(!PathOperations.ignoreFile(curFile,this.settings.ignoreFiles))
{
//first check if this file is part of this run, by checking if it is under the longest path
//within the directory collection
let longestDir : string = "";
for(let searchDirectory of directories)
{
searchDirectory.directoryPath = pathOp.normalizeDirectoryPaths(searchDirectory.directoryPath);
if(curFile.indexOf(searchDirectory.directoryPath) != -1)
{
if (searchDirectory.directoryPath.length > longestDir.length)
{
longestDir = searchDirectory.directoryPath;
}
}
}
//now make sure that whatever directory the file was associated with is the current directory being analyzed
if(pathOp.normalizeDirectoryPaths(longestDir) == pathOp.normalizeDirectoryPaths(directory.directoryPath))
{
//give some indication of progress as files are analyzed
console.log("Analyzing \""+curFile.substr(directories[0].directoryPath.length) + "\"");
let documentContents : string = fs.readFileSync(curFile, "utf8");
let langID : string = pathOp.getLangFromPath(curFile);
problems = problems.concat(analysisEngine.analyzeText(documentContents,langID, curFile, false));
//if writing to a file, add the metadata for the file that is analyzed
if(this.outputFilePath.length > 0)
{
FilesToLog.push(this.createFileData(curFile,documentContents,directory.directoryPath));
}
}
}
}
if(problems.length > 0 || FilesToLog.length > 0)
{
(<DevSkimResultsWriter>this.outputObject).createRun(new Run(directory,
analysisEngine.retrieveLoadedRules(),
FilesToLog,
problems));
problems = [];
FilesToLog = [];
}
}
//just add a space at the end to make the final text more readable
console.log("\n-----------------------\n");
this.outputObject.writeOutput();
});
}