diff --git a/src/cli/leasot.ts b/src/cli/leasot.ts index 9828789f..0e485f64 100755 --- a/src/cli/leasot.ts +++ b/src/cli/leasot.ts @@ -39,7 +39,11 @@ program ) .option('-i, --ignore ', 'add ignore patterns', list, []) .option('-I, --inline-files', 'parse possible inline files', false) - .option('-r, --reporter [reporter]', 'use reporter (table|json|xml|markdown|vscode|raw) (default: table)', 'table') + .option( + '-r, --reporter [reporter]', + 'use reporter (table|json|xml|markdown|vscode|gitlab|raw) (default: table)', + 'table' + ) .option('-S, --skip-unsupported', 'skip unsupported filetypes', false) .option('-t, --filetype [filetype]', 'force the filetype to parse. Useful for streams (default: .js)') .option('-T, --tags ', 'add additional comment types to find (alongside todo & fixme)', list, []) diff --git a/src/definitions.ts b/src/definitions.ts index 06606835..59bb2314 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -170,6 +170,10 @@ export enum BuiltinReporters { * @hidden */ custom = 'custom', + /** + * Return a Gitlab code quality formatted json string of the todos + */ + gitlab = 'gitlab', /** * Return a json string of the todos */ diff --git a/src/lib/reporters/gitlab.ts b/src/lib/reporters/gitlab.ts new file mode 100644 index 00000000..3b234e91 --- /dev/null +++ b/src/lib/reporters/gitlab.ts @@ -0,0 +1,27 @@ +import crypto from 'crypto'; + +import { ReportItems, TodoComment } from '../../definitions.js'; +import { JsonReporterConfig } from './json.js'; + +export const reporter: ReportItems = (todos: TodoComment[], config: JsonReporterConfig = { spacing: 2 }): string => + JSON.stringify( + todos.map((todo: TodoComment) => { + return { + description: `${todo.tag} ${todo.text}`, + check_name: 'leasot', + fingerprint: crypto + .createHash('md5') + .update(`${todo.tag}${todo.text}${todo.file}${todo.line}`) + .digest('hex'), + severity: 'info', + location: { + path: todo.file, + lines: { + begin: todo.line, + }, + }, + }; + }), + null, + config.spacing + );