RULEAPI-626 Fix the crash when choosing terraform, rust, solidity, html - any non covered language

This commit is contained in:
Arseniy Zaostrovnykh 2021-06-01 16:50:15 +02:00 committed by GitHub
parent 8a2a77321f
commit a228658b91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

1
frontend/.gitignore vendored
View File

@ -23,3 +23,4 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
.eslintcache .eslintcache
incomplete-rules-repo/

View File

@ -70,6 +70,8 @@ const languageToJiraProject = new Map(Object.entries({
"TSQL": "SONARTSQL", "TSQL": "SONARTSQL",
"VB6": "SONARVBSIX", "VB6": "SONARVBSIX",
"XML": "SONARXML", "XML": "SONARXML",
"CLOUDFORMATION": "SONARIAC",
"TERRAFORM": "SONARIAC",
})); }));
const languageToGithubProject = new Map(Object.entries({ const languageToGithubProject = new Map(Object.entries({
@ -91,13 +93,15 @@ const languageToGithubProject = new Map(Object.entries({
"PLI": "sonar-pli", "PLI": "sonar-pli",
"CFAMILY": "sonar-cpp", "CFAMILY": "sonar-cpp",
"CSS": "sonar-css", "CSS": "sonar-css",
"FLEX": "sonar-flex",
"PHP": "sonar-php", "PHP": "sonar-php",
"PL/SQL": "sonar-plsql", "PLSQL": "sonar-plsql",
"Python": "sonar-python", "PYTHON": "sonar-python",
"RPG": "sonar-rpg", "RPG": "sonar-rpg",
"Swift": "sonar-swift", "TSQL": "sonar-tsql",
"T-SQL": "sonar-tsql",
"XML": "sonar-xml", "XML": "sonar-xml",
"CLOUDFORMATION": "sonar-iac",
"TERRAFORM": "sonar-iac",
})); }));

View File

@ -30,7 +30,10 @@ export function useRuleCoverage() {
'tsql': ['TSQL'], 'tsql': ['TSQL'],
'vb6': ['VB'], 'vb6': ['VB'],
'WEB': ['WEB'], 'WEB': ['WEB'],
'xml': ['XML'] 'xml': ['XML'],
'html': ['HTML'],
'cloudformation': ['CLOUDFORMATION'],
'terraform': ['TERRAFORM']
})); }));
function ruleCoverage(language: string, ruleKeys: string[], mapper: any) { function ruleCoverage(language: string, ruleKeys: string[], mapper: any) {
if (coveredRulesError) { if (coveredRulesError) {
@ -47,11 +50,12 @@ export function useRuleCoverage() {
// const keys = coveredRules.keys; // const keys = coveredRules.keys;
const languageKeys = languageToSonarpedia.get(language); const languageKeys = languageToSonarpedia.get(language);
if (!languageKeys) { if (!languageKeys) {
throw new Error(`Unknown key ${language}`) return 'Nonsupported language';
} }
languageKeys.forEach(sonarpediaKey => { languageKeys.forEach(sonarpediaKey => {
ruleKeys.forEach(ruleKey => { ruleKeys.forEach(ruleKey => {
if (ruleKey in coveredRules[sonarpediaKey]) { if (sonarpediaKey in coveredRules &&
ruleKey in coveredRules[sonarpediaKey]) {
result.push(mapper(sonarpediaKey, coveredRules[sonarpediaKey][ruleKey])) result.push(mapper(sonarpediaKey, coveredRules[sonarpediaKey][ruleKey]))
} }
}); });