2021-01-13 07:10:33 +01:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const core = require("@actions/core");
|
2021-01-16 05:35:50 +01:00
|
|
|
const {"main": markdownlintCli2} = require("markdownlint-cli2");
|
2021-01-13 07:10:33 +01:00
|
|
|
|
|
|
|
const logMessage = core.info;
|
2023-04-08 05:20:52 +02:00
|
|
|
const outputFormatter = (options) => {
|
|
|
|
const {results} = options;
|
|
|
|
for (const lintError of results) {
|
|
|
|
const {
|
|
|
|
errorContext,
|
|
|
|
errorDetail,
|
|
|
|
errorRange,
|
|
|
|
fileName,
|
|
|
|
lineNumber,
|
|
|
|
ruleDescription,
|
|
|
|
ruleInformation,
|
|
|
|
ruleNames
|
|
|
|
} = lintError;
|
|
|
|
const line = `:${lineNumber}`;
|
|
|
|
const column = errorRange ? `:${errorRange[0]}` : "";
|
|
|
|
const name = ruleNames.join("/");
|
|
|
|
const detail = errorDetail ? ` [${errorDetail}]` : "";
|
|
|
|
const context = errorContext ? ` [Context: "${errorContext}"]` : "";
|
|
|
|
const information = ruleInformation ? ` ${ruleInformation}` : "";
|
|
|
|
const message =
|
|
|
|
`${fileName}${line}${column} ${name} ${ruleDescription}${detail}${context}${information}`;
|
|
|
|
const annotation = {
|
|
|
|
"title": ruleDescription,
|
|
|
|
"file": fileName,
|
|
|
|
"startLine": lineNumber,
|
|
|
|
"endLine": lineNumber
|
2022-02-05 21:57:47 +01:00
|
|
|
};
|
2023-04-08 05:20:52 +02:00
|
|
|
if (errorRange) {
|
|
|
|
const [
|
|
|
|
errorColumn,
|
|
|
|
errorLength
|
|
|
|
] = errorRange;
|
|
|
|
annotation.startColumn = errorColumn;
|
|
|
|
annotation.endColumn = errorColumn + errorLength - 1;
|
2022-02-06 02:09:56 +01:00
|
|
|
}
|
2023-04-08 05:20:52 +02:00
|
|
|
core.error(message, annotation);
|
2022-02-05 21:57:47 +01:00
|
|
|
}
|
|
|
|
};
|
2022-11-30 04:29:42 +01:00
|
|
|
|
|
|
|
const separator = core.getInput("separator") || "\n";
|
2021-01-16 05:35:50 +01:00
|
|
|
const argv =
|
|
|
|
core.getInput("globs").
|
2022-11-30 04:29:42 +01:00
|
|
|
split(separator).
|
2022-07-20 05:54:12 +02:00
|
|
|
filter(String);
|
2021-01-13 07:25:46 +01:00
|
|
|
|
2023-06-11 05:35:20 +02:00
|
|
|
const config = core.getInput("config");
|
|
|
|
if (config) {
|
|
|
|
argv.push("--config", config);
|
|
|
|
}
|
|
|
|
const fix = Boolean(core.getInput("fix"));
|
|
|
|
if (fix) {
|
|
|
|
argv.push("--fix");
|
|
|
|
}
|
|
|
|
|
2023-11-21 23:22:00 +01:00
|
|
|
const parameters = {
|
|
|
|
argv,
|
|
|
|
logMessage,
|
|
|
|
"optionsOverride": {
|
|
|
|
"outputFormatters": [[outputFormatter]]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlintCli2(parameters).then(
|
|
|
|
(code) => code && core.setFailed(`Failed with exit code: ${code}`),
|
|
|
|
(error) => core.setFailed(`Failed due to error: ${error}`)
|
|
|
|
);
|