-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatter-sonar.js
36 lines (34 loc) · 1.37 KB
/
formatter-sonar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// References:
// https://medium.com/@jose_82797/how-to-import-eslint-issues-into-sonarqube-overview-analysis-in-a-frontend-application-b8e8946b8104
// https://eslint.org/docs/latest/developer-guide/working-with-custom-formatters#working-with-custom-formatters
module.exports = function (results) {
var summary = { issues: [] };
results.forEach(function (result) {
result.messages.forEach(function (msg) {
var logMessage = {
engineId: "eslint",
ruleId: msg.ruleId,
primaryLocation: {
message: msg.message,
filePath: result.filePath,
textRange: {
startLine: msg.line,
endLine: msg.endLine,
endColumn: msg.endColumn
}
}
};
// The log message type and severity is up to you but you need to take in consideration SonarQube properties
if (msg.severity === 1) {
logMessage.type = "CODE_SMELL";
logMessage.severity = "INFO";
}
if (msg.severity === 2) {
logMessage.type = "BUG";
logMessage.severity = "MAJOR";
}
summary.issues.push(logMessage);
});
});
return JSON.stringify(summary, null, 2);
};