Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
[Issue #183] CWE Report - added tool column
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDRC committed Aug 8, 2016
1 parent 7a8df8d commit 7d10429
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 122 deletions.
20 changes: 16 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ module.exports = function(grunt) {
return contribRules.concat(baseRules);
}

function hash(input) {
// initialized with a prime number
let hash = 31;
let i = 0;
for (i = 0; i < input.length; i++) {
// multiply by prime so to get the better distribution of the values
hash = 31 * hash + input.charCodeAt(i); // run the hash function on all chars
hash = hash | 0; // convert to 32 bit signed integer
}
return Math.abs(hash).toString(32).toUpperCase();
}

function getMetadataFromFile(ruleFile) {
const moduleName = './' + ruleFile.replace(/\.js$/, '');
const module = require(moduleName);
Expand Down Expand Up @@ -290,10 +302,9 @@ module.exports = function(grunt) {

const rows = [];
const resolution = 'See description on the tslint or tslint-microsoft-contrib website';
const path = 'teams/SecDev/Support/Lists/WarningCentral';
const procedure = 'TSLint Procedure';
const header = 'SDL Version,Title,Description,ErrorID,Tool,IssueClass,IssueType,SDL Bug Bar Severity,' +
'SDL Level,Resolution,SDL Procedure,Item Type,Path,CWE,CWE Description';
const header = 'Title,Description,ErrorID,Tool,IssueClass,IssueType,SDL Bug Bar Severity,' +
'SDL Level,Resolution,SDL Procedure,CWE,CWE Description';
getAllRules().forEach(function(ruleFile) {
const metadata = getMetadataFromFile(ruleFile);

Expand All @@ -302,14 +313,15 @@ module.exports = function(grunt) {
return;
}
const ruleName = getMetadataValue(metadata, 'ruleName');
const tool = 'TSLINT' + hash(ruleName)
const issueType = getMetadataValue(metadata, 'issueType');
const severity = getMetadataValue(metadata, 'severity');
const level = getMetadataValue(metadata, 'level');
const description = getMetadataValue(metadata, 'description');
const cwe = getMetadataValue(metadata, 'commonWeaknessEnumeration', true, false);
const cweDescription = createCweDescription(metadata);

const row = `7,${ruleName},${description},,tslint,${issueClass},${issueType},${severity},${level},${resolution},${procedure},Item,${path},${cwe},${cweDescription}`;
const row = `${ruleName},${description},,${tool},${issueClass},${issueType},${severity},${level},${resolution},${procedure},${cwe},${cweDescription}`;
rows.push(row);
});
rows.sort();
Expand Down
Loading

0 comments on commit 7d10429

Please sign in to comment.