forked from IBM/openapi-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: feat(codeclimate): outputFormat for CodeClimate (IBM#512)
Signed-off-by: Matthias Blümel <[email protected]>
- Loading branch information
Showing
6 changed files
with
73 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/validator/src/cli-validator/utils/codeclimate-results.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Copyright 2023 IBM Corporation, Matthias Blümel. | ||
* SPDX-License-Identifier: Apache2.0 | ||
*/ | ||
|
||
const each = require('lodash/each'); | ||
|
||
function printCCJson(validFile, results) { | ||
const types = ['error', 'warning', 'info', 'hint']; | ||
const ccTypeMap = { | ||
error: 'critical', | ||
warning: 'major', | ||
info: 'minor', | ||
hint: 'info', | ||
}; | ||
|
||
types.forEach(type => { | ||
each(results[type].results, result => { | ||
let content; | ||
if (result.path.length !== 0) { | ||
let markdown = ''; | ||
each(result.path, pathItem => { | ||
markdown += '* ' + pathItem + '\n'; | ||
}); | ||
content = { body: markdown }; | ||
} | ||
const ccResult = { | ||
type: 'issue', | ||
check_name: result.rule, | ||
description: result.message, | ||
content: content, | ||
categories: ['Style'], // required by codeclimate, ignored by gitlab; has to be defined by the rule. | ||
location: { | ||
path: validFile, | ||
lines: { | ||
begin: result.line, | ||
end: result.line, | ||
}, | ||
}, | ||
severity: ccTypeMap[type], | ||
}; | ||
console.log(JSON.stringify(ccResult) + '\0\n'); | ||
}); | ||
}); | ||
} | ||
|
||
module.exports.printCCJson = printCCJson; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ properties: | |
type: string | ||
enum: | ||
- json | ||
- codeclimate | ||
- text | ||
default: text | ||
ruleset: | ||
|