mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
6474dd49e5
Co-authored-by: Rhys Arkins <rhys@arkins.net>
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { relative } from 'path';
|
|
import { error } from '@actions/core';
|
|
import { issueCommand } from '@actions/core/lib/command';
|
|
import { CLIEngine, Linter } from 'eslint';
|
|
import stripAnsi from 'strip-ansi';
|
|
|
|
const ROOT = process.cwd();
|
|
|
|
type Level = 'debug' | 'warning' | 'error';
|
|
|
|
function getCmd(severity: Linter.Severity): Level {
|
|
switch (severity) {
|
|
case 2:
|
|
return 'error';
|
|
case 1:
|
|
return 'warning';
|
|
default:
|
|
return 'debug';
|
|
}
|
|
}
|
|
|
|
function getPath(path: string): string {
|
|
return relative(ROOT, path).replace(/\\/g, '/');
|
|
}
|
|
|
|
const formatter: CLIEngine.Formatter = (results) => {
|
|
try {
|
|
for (const { filePath, messages } of results) {
|
|
const file = getPath(filePath);
|
|
for (const { severity, line, column, ruleId, message } of messages) {
|
|
const cmd = getCmd(severity);
|
|
const pos = { line: line.toString(), col: column.toString() };
|
|
issueCommand(
|
|
cmd,
|
|
{ file, ...pos },
|
|
stripAnsi(`[${ruleId}] ${message}`)
|
|
);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
error(`Unexpected error: ${(e as Error).toString()}`);
|
|
}
|
|
return '';
|
|
};
|
|
|
|
export = formatter;
|