Skip to content

Commit 0b9c1b8

Browse files
authored
Add Gitlab code quality reporter (#335)
1 parent 82556d2 commit 0b9c1b8

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/cli/leasot.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ program
3939
)
4040
.option('-i, --ignore <patterns>', 'add ignore patterns', list, [])
4141
.option('-I, --inline-files', 'parse possible inline files', false)
42-
.option('-r, --reporter [reporter]', 'use reporter (table|json|xml|markdown|vscode|raw) (default: table)', 'table')
42+
.option(
43+
'-r, --reporter [reporter]',
44+
'use reporter (table|json|xml|markdown|vscode|gitlab|raw) (default: table)',
45+
'table'
46+
)
4347
.option('-S, --skip-unsupported', 'skip unsupported filetypes', false)
4448
.option('-t, --filetype [filetype]', 'force the filetype to parse. Useful for streams (default: .js)')
4549
.option('-T, --tags <tags>', 'add additional comment types to find (alongside todo & fixme)', list, [])

src/definitions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ export enum BuiltinReporters {
170170
* @hidden
171171
*/
172172
custom = 'custom',
173+
/**
174+
* Return a Gitlab code quality formatted json string of the todos
175+
*/
176+
gitlab = 'gitlab',
173177
/**
174178
* Return a json string of the todos
175179
*/

src/lib/reporters/gitlab.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import crypto from 'crypto';
2+
3+
import { ReportItems, TodoComment } from '../../definitions.js';
4+
import { JsonReporterConfig } from './json.js';
5+
6+
export const reporter: ReportItems = (todos: TodoComment[], config: JsonReporterConfig = { spacing: 2 }): string =>
7+
JSON.stringify(
8+
todos.map((todo: TodoComment) => {
9+
return {
10+
description: `${todo.tag} ${todo.text}`,
11+
check_name: 'leasot',
12+
fingerprint: crypto
13+
.createHash('md5')
14+
.update(`${todo.tag}${todo.text}${todo.file}${todo.line}`)
15+
.digest('hex'),
16+
severity: 'info',
17+
location: {
18+
path: todo.file,
19+
lines: {
20+
begin: todo.line,
21+
},
22+
},
23+
};
24+
}),
25+
null,
26+
config.spacing
27+
);

0 commit comments

Comments
 (0)