Fix tests and severity display
This commit is contained in:
parent
a27c13bb58
commit
b44ed7cc7f
@ -847,6 +847,61 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"code"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"impacts"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"MAINTAINABILITY"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"attribute"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"CLEAR"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"severity"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
,
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -939,19 +994,6 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
<span
|
|
||||||
class="hljs-attr"
|
|
||||||
>
|
|
||||||
"defaultSeverity"
|
|
||||||
</span>
|
|
||||||
:
|
|
||||||
<span
|
|
||||||
class="hljs-string"
|
|
||||||
>
|
|
||||||
"Major"
|
|
||||||
</span>
|
|
||||||
,
|
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -1887,6 +1929,48 @@ exports[`renders cfamily version of S1000 1`] = `
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"code"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"impacts"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"MAINTAINABILITY"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"attribute"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"CLEAR"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -1987,19 +2071,6 @@ exports[`renders cfamily version of S1000 1`] = `
|
|||||||
: []
|
: []
|
||||||
},
|
},
|
||||||
|
|
||||||
<span
|
|
||||||
class="hljs-attr"
|
|
||||||
>
|
|
||||||
"defaultSeverity"
|
|
||||||
</span>
|
|
||||||
:
|
|
||||||
<span
|
|
||||||
class="hljs-string"
|
|
||||||
>
|
|
||||||
"Major"
|
|
||||||
</span>
|
|
||||||
,
|
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -2026,6 +2097,19 @@ exports[`renders cfamily version of S1000 1`] = `
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"severity"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
,
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -3561,6 +3645,61 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"code"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"impacts"
|
||||||
|
</span>
|
||||||
|
: {
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"MAINTAINABILITY"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"attribute"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"CLEAR"
|
||||||
|
</span>
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
<span
|
||||||
|
class="hljs-attr"
|
||||||
|
>
|
||||||
|
"severity"
|
||||||
|
</span>
|
||||||
|
:
|
||||||
|
<span
|
||||||
|
class="hljs-string"
|
||||||
|
>
|
||||||
|
"MEDIUM"
|
||||||
|
</span>
|
||||||
|
,
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
@ -3653,19 +3792,6 @@ var res = string.Format("{0} {1}", array); // Compliant we don't know the size o
|
|||||||
</span>
|
</span>
|
||||||
,
|
,
|
||||||
|
|
||||||
<span
|
|
||||||
class="hljs-attr"
|
|
||||||
>
|
|
||||||
"defaultSeverity"
|
|
||||||
</span>
|
|
||||||
:
|
|
||||||
<span
|
|
||||||
class="hljs-string"
|
|
||||||
>
|
|
||||||
"Major"
|
|
||||||
</span>
|
|
||||||
,
|
|
||||||
|
|
||||||
<span
|
<span
|
||||||
class="hljs-attr"
|
class="hljs-attr"
|
||||||
>
|
>
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
"quickfix": "unknown",
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant/Issue",
|
"func": "Constant/Issue",
|
||||||
"constantCost": "1h"
|
"constantCost": "1h"
|
||||||
@ -21,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"ruleSpecification": "RSPEC-1000",
|
"ruleSpecification": "RSPEC-1000",
|
||||||
"sqKey": "UnnamedNamespaceInHeader",
|
"sqKey": "UnnamedNamespaceInHeader",
|
||||||
|
"severity": "MEDIUM",
|
||||||
"scope": "Main",
|
"scope": "Main",
|
||||||
"securityStandards": {
|
"securityStandards": {
|
||||||
"CERT": [
|
"CERT": [
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
"func": "Constant/Issue",
|
"func": "Constant/Issue",
|
||||||
"constantCost": "1h"
|
"constantCost": "1h"
|
||||||
},
|
},
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
"cert",
|
"cert",
|
||||||
"misra-c++2008",
|
"misra-c++2008",
|
||||||
@ -20,6 +26,7 @@
|
|||||||
},
|
},
|
||||||
"ruleSpecification": "RSPEC-1000",
|
"ruleSpecification": "RSPEC-1000",
|
||||||
"sqKey": "UnnamedNamespaceInHeader",
|
"sqKey": "UnnamedNamespaceInHeader",
|
||||||
|
"severity": "MEDIUM",
|
||||||
"scope": "Main",
|
"scope": "Main",
|
||||||
"securityStandards": {
|
"securityStandards": {
|
||||||
"CERT": [
|
"CERT": [
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
"title": "Printf-style format strings should be used correctly",
|
"title": "Printf-style format strings should be used correctly",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "10min"
|
"constantCost": "10min"
|
||||||
@ -31,6 +37,7 @@
|
|||||||
"FIO47-C."
|
"FIO47-C."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"languagesSupport": [
|
"languagesSupport": [
|
||||||
{
|
{
|
||||||
"name": "cfamily",
|
"name": "cfamily",
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "Composite format strings should be used correctly",
|
"title": "Composite format strings should be used correctly",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "10min"
|
"constantCost": "10min"
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "Printf-style format strings should be used correctly",
|
"title": "Printf-style format strings should be used correctly",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant/Issue",
|
"func": "Constant/Issue",
|
||||||
"constantCost": "10min"
|
"constantCost": "10min"
|
||||||
|
@ -26,7 +26,15 @@
|
|||||||
"CERT": [
|
"CERT": [
|
||||||
"FIO47-C."
|
"FIO47-C."
|
||||||
]
|
]
|
||||||
}, "ruleSpecification": "RSPEC-3457",
|
},
|
||||||
|
"code": {
|
||||||
|
"attribute": "CLEAR",
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
|
"ruleSpecification": "RSPEC-3457",
|
||||||
"sqKey": "S3457",
|
"sqKey": "S3457",
|
||||||
"scope": "All",
|
"scope": "All",
|
||||||
"languagesSupport": [
|
"languagesSupport": [
|
||||||
|
@ -12,6 +12,13 @@
|
|||||||
"allKeys": [
|
"allKeys": [
|
||||||
"S3457"
|
"S3457"
|
||||||
],
|
],
|
||||||
|
"code": {
|
||||||
|
"attribute": "CLEAR",
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"ruleSpecification": "RSPEC-3457",
|
"ruleSpecification": "RSPEC-3457",
|
||||||
"sqKey": "S3457",
|
"sqKey": "S3457",
|
||||||
"scope": "All",
|
"scope": "All",
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "Database queries should not be vulnerable to injection attacks",
|
"title": "Database queries should not be vulnerable to injection attacks",
|
||||||
"type": "VULNERABILITY",
|
"type": "VULNERABILITY",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "30min"
|
"constantCost": "30min"
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "Database queries should not be vulnerable to injection attacks",
|
"title": "Database queries should not be vulnerable to injection attacks",
|
||||||
"type": "VULNERABILITY",
|
"type": "VULNERABILITY",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "30min"
|
"constantCost": "30min"
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "\"<signal.h>\" should not be used",
|
"title": "\"<signal.h>\" should not be used",
|
||||||
"type": "BUG",
|
"type": "BUG",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "4h"
|
"constantCost": "4h"
|
||||||
|
@ -2,6 +2,13 @@
|
|||||||
"title": "\"<signal.h>\" should not be used",
|
"title": "\"<signal.h>\" should not be used",
|
||||||
"type": "BUG",
|
"type": "BUG",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
|
"severity": "MEDIUM",
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant/Issue",
|
"func": "Constant/Issue",
|
||||||
"constantCost": "4h"
|
"constantCost": "4h"
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
"title": "Header files should not contain unnamed namespaces",
|
"title": "Header files should not contain unnamed namespaces",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "1h"
|
"constantCost": "1h"
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
"title": "Composite format strings should be used correctly",
|
"title": "Composite format strings should be used correctly",
|
||||||
"type": "CODE_SMELL",
|
"type": "CODE_SMELL",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "10min"
|
"constantCost": "10min"
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
"title": "Database queries should not be vulnerable to injection attacks",
|
"title": "Database queries should not be vulnerable to injection attacks",
|
||||||
"type": "VULNERABILITY",
|
"type": "VULNERABILITY",
|
||||||
"status": "ready",
|
"status": "ready",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
},
|
||||||
|
"attribute": "CLEAR"
|
||||||
|
},
|
||||||
"remediation": {
|
"remediation": {
|
||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "30min"
|
"constantCost": "30min"
|
||||||
|
@ -6,6 +6,12 @@
|
|||||||
"func": "Constant\/Issue",
|
"func": "Constant\/Issue",
|
||||||
"constantCost": "4h"
|
"constantCost": "4h"
|
||||||
},
|
},
|
||||||
|
"code": {
|
||||||
|
"attribute": "CLEAR",
|
||||||
|
"impacts": {
|
||||||
|
"MAINTAINABILITY": "MEDIUM"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
"based-on-misra",
|
"based-on-misra",
|
||||||
"lock-in"
|
"lock-in"
|
||||||
|
@ -26,7 +26,7 @@ describe('index store generation', () => {
|
|||||||
{ "name": "python", "status": "deprecated", }
|
{ "name": "python", "status": "deprecated", }
|
||||||
],
|
],
|
||||||
tags: ['cert', 'clumsy', 'confusing'],
|
tags: ['cert', 'clumsy', 'confusing'],
|
||||||
severities: ['Major', 'Minor'],
|
severities: ['MEDIUM'],
|
||||||
qualityProfiles: ['Sonar way'],
|
qualityProfiles: ['Sonar way'],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import { maxSeverity } from '../types/Severities';
|
import { Severity, maxSeverity } from '../types/Severities';
|
||||||
import { LanguageSupport } from '../types/RuleMetadata';
|
import { LanguageSupport } from '../types/RuleMetadata';
|
||||||
import { getRulesDirectories, listSupportedLanguages } from './utils';
|
import { getRulesDirectories, listSupportedLanguages } from './utils';
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ function getRuleMetadata(srcDir: string, language?: string) {
|
|||||||
const genericJson = fs.existsSync(genericFile) ? JSON.parse(fs.readFileSync(genericFile, 'utf8')) : {};
|
const genericJson = fs.existsSync(genericFile) ? JSON.parse(fs.readFileSync(genericFile, 'utf8')) : {};
|
||||||
const merged = { ...genericJson, ...languageSpecificJson };
|
const merged = { ...genericJson, ...languageSpecificJson };
|
||||||
if (merged.hasOwnProperty('code') && merged.code.hasOwnProperty('impacts')) {
|
if (merged.hasOwnProperty('code') && merged.code.hasOwnProperty('impacts')) {
|
||||||
merged['severity'] = maxSeverity(merged.code.impacts);
|
merged['severity'] = Severity[maxSeverity(merged.code.impacts)];
|
||||||
}
|
}
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import path from 'path';
|
|||||||
import { stripHtml } from 'string-strip-html';
|
import { stripHtml } from 'string-strip-html';
|
||||||
import lunr, { Token } from 'lunr';
|
import lunr, { Token } from 'lunr';
|
||||||
|
|
||||||
import { Severity, maxSeverity } from '../types/Severities';
|
import { Severity, compareSeverities, maxSeverity } from '../types/Severities';
|
||||||
import { IndexedRule, IndexStore, Type, IndexAggregates } from '../types/IndexStore';
|
import { IndexedRule, IndexStore, Type, IndexAggregates } from '../types/IndexStore';
|
||||||
import { logger as rootLogger } from './deploymentLogger';
|
import { logger as rootLogger } from './deploymentLogger';
|
||||||
import { LanguageSupport } from '../types/RuleMetadata';
|
import { LanguageSupport } from '../types/RuleMetadata';
|
||||||
@ -22,7 +22,7 @@ export interface IndexedRuleWithDescription extends IndexedRule {
|
|||||||
function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir: string) {
|
function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir: string) {
|
||||||
|
|
||||||
const types = new Set<Type>();
|
const types = new Set<Type>();
|
||||||
const severities = new Set<Severity>();
|
const severities = new Set<string>();
|
||||||
const allKeys = new Set<string>([ruleDir]);
|
const allKeys = new Set<string>([ruleDir]);
|
||||||
const titles = new Set<string>();
|
const titles = new Set<string>();
|
||||||
const tags = new Set<string>();
|
const tags = new Set<string>();
|
||||||
@ -54,9 +54,9 @@ function buildOneRuleRecord(allLanguages: string[], rulesPath: string, ruleDir:
|
|||||||
titles.add(metadata.title);
|
titles.add(metadata.title);
|
||||||
types.add(metadata.type);
|
types.add(metadata.type);
|
||||||
if (!metadata.hasOwnProperty('code')) {
|
if (!metadata.hasOwnProperty('code')) {
|
||||||
severities.add(Severity.INFO);
|
severities.add(Severity[Severity.INFO]);
|
||||||
} else {
|
} else {
|
||||||
severities.add(maxSeverity(metadata.code.impacts));
|
severities.add(Severity[maxSeverity(metadata.code.impacts)]);
|
||||||
}
|
}
|
||||||
supportedLanguages.push({ name: lang, status: metadata.status });
|
supportedLanguages.push({ name: lang, status: metadata.status });
|
||||||
if (metadata.tags) {
|
if (metadata.tags) {
|
||||||
@ -110,7 +110,7 @@ function buildOneRuleIndexedRecord(rulesPath: string, ruleDir: string)
|
|||||||
id: ruleDir,
|
id: ruleDir,
|
||||||
supportedLanguages: Array.from(record.supportedLanguages).sort((a, b) => a.name.localeCompare(b.name)),
|
supportedLanguages: Array.from(record.supportedLanguages).sort((a, b) => a.name.localeCompare(b.name)),
|
||||||
types: Array.from(record.types).sort((a, b) => a.localeCompare(b)),
|
types: Array.from(record.types).sort((a, b) => a.localeCompare(b)),
|
||||||
severities: Array.from(record.severities).sort((a, b) => b - a),
|
severities: Array.from(record.severities).sort((a, b) => compareSeverities(b, a)),
|
||||||
all_keys: Array.from(record.allKeys).sort((a, b) => a.localeCompare(b)),
|
all_keys: Array.from(record.allKeys).sort((a, b) => a.localeCompare(b)),
|
||||||
titles: Array.from(record.titles).sort((a, b) => a.localeCompare(b)),
|
titles: Array.from(record.titles).sort((a, b) => a.localeCompare(b)),
|
||||||
tags: Array.from(record.tags).sort((a, b) => a.localeCompare(b)),
|
tags: Array.from(record.tags).sort((a, b) => a.localeCompare(b)),
|
||||||
|
@ -7,7 +7,7 @@ export interface IndexedRule {
|
|||||||
supportedLanguages: LanguageSupport[];
|
supportedLanguages: LanguageSupport[];
|
||||||
// FIXME: type, defaultSeverity should never be null but the index generation has a bug
|
// FIXME: type, defaultSeverity should never be null but the index generation has a bug
|
||||||
types: Type[];
|
types: Type[];
|
||||||
severities: Severity[];
|
severities: string[];
|
||||||
all_keys: string[];
|
all_keys: string[];
|
||||||
titles: string[];
|
titles: string[];
|
||||||
tags: string[];
|
tags: string[];
|
||||||
|
@ -17,4 +17,10 @@ export function maxSeverity(impacts: any): Severity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return maxSeverity;
|
return maxSeverity;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareSeverities(a: string, b:string): number {
|
||||||
|
const seva: Severity = Severity[a as keyof typeof Severity];
|
||||||
|
const sevb: Severity = Severity[b as keyof typeof Severity];
|
||||||
|
return seva - sevb;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user