|
| 1 | +const path = require('path'); |
| 2 | + |
| 3 | +const SONARQUBE_SEVERITY = { |
| 4 | + '-1': 'INFO', // todo |
| 5 | + 1: 'MINOR', // warning |
| 6 | + 2: 'CRITICAL', // error |
| 7 | +}; |
| 8 | + |
| 9 | +const SONARQUBE_TYPE = { |
| 10 | + '-1': 'CODE_SMELL', // todo |
| 11 | + 1: 'CODE_SMELL', // warning |
| 12 | + 2: 'BUG', // error |
| 13 | +}; |
| 14 | + |
| 15 | +module.exports = class SonarQubeFormatter { |
| 16 | + constructor(options = {}) { |
| 17 | + this.options = options; |
| 18 | + this.console = options.console || console; |
| 19 | + } |
| 20 | + |
| 21 | + print(results) { |
| 22 | + const issues = []; |
| 23 | + for (const result of results) { |
| 24 | + let relativePath = path.relative( |
| 25 | + this.options.workingDir, |
| 26 | + result.filePath |
| 27 | + ); |
| 28 | + |
| 29 | + for (const message of result.messages) { |
| 30 | + issues.push({ |
| 31 | + engineId: 'ember-template-lint', |
| 32 | + ruleId: message.rule, |
| 33 | + severity: SONARQUBE_SEVERITY[message.severity], |
| 34 | + type: SONARQUBE_TYPE[message.severity], |
| 35 | + primaryLocation: { |
| 36 | + message: message.message, |
| 37 | + filePath: relativePath, |
| 38 | + textRange: { |
| 39 | + startLine: message.line, |
| 40 | + startColumn: message.column, |
| 41 | + endLine: message.endLine, |
| 42 | + endColumn: message.endColumn, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + // eslint-disable-next-line unicorn/no-null |
| 50 | + this.console.log(JSON.stringify({ issues }, null, 2)); |
| 51 | + } |
| 52 | +}; |
0 commit comments