in DevSkim-VSCode-Plugin/server/src/utility_classes/ruleValidator.ts [57:119]
public async validateRules(readRules: Rule[], outputValidation: boolean): Promise<Rule[]>
{
let rules: Rule[] = [];
this.outputMessages = [];
this.writeoutNewRules = false;
if (!readRules) readRules = [];
//We intentionally throw exceptions when a rule catastrophically fails validation , but that will get logged in the output message
//so we don't actually need to handle the exception. The catch block is empty because we want to keep
//processing the rest of the rules
for (let loadedRule of readRules)
{
try
{
let newRule = (outputValidation) ? this.makeRule(loadedRule) : this.makeRuleNoValidation(loadedRule);
rules.push(newRule);
}
catch (err)
{
noop();
}
}
//if told to outputValidation, write out fixed rules (if any) and the output log
if (outputValidation)
{
if (this.outputMessages.length > 0)
{
this.logFilePath = path.join(this.errorDir, "rulesValidationLog.json1");
await this.fs.writeFile(this.logFilePath, JSON.stringify(this.outputMessages, null, 4),
(err: ErrnoException) =>
{
if (err)
{
this.logger.log(`RuleValidator - outputValidation err: ${err.message}`);
}
});
}
if (this.writeoutNewRules)
{
let newrulePath = path.join(this.errorDir, "..", "newrules");
this.logger.log(`RuleValidator - outputValidation: ${newrulePath}`);
for (let key in this.fixedRules)
{
let filePath: string = key.substr(key.indexOf("rules") + 5);
filePath = path.join(newrulePath, filePath);
try
{
mkdirp.sync(path.dirname(filePath));
this.logger.log(`RuleValidator - newRulePath - file: ${filePath}`);
await this.fs.writeFileSync(filePath, JSON.stringify(this.fixedRules[key], null, 4));
}
catch (err)
{
this.logger.log(`RuleValidator - validateRules err: >>${err.message}<<`);
}
}
}
}
return rules;
}