Skip to content

Commit

Permalink
Include link to rule information with title of annotations (clickable…
Browse files Browse the repository at this point in the history
… in GitHub), add

endLine/endColumn data to annotations, use output formatter instead of parsing logError
(fixes #79).
  • Loading branch information
DavidAnson committed Apr 26, 2023
1 parent 4d12ee9 commit 62350ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 46 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"rules": {
"indent": ["error", 2],
"function-call-argument-newline": "off",
"max-statements": "off",
"multiline-ternary": "off",
"no-magic-numbers": "off",
"no-ternary": "off",
"one-var": "off",
"padded-blocks": "off",
"prefer-named-capture-group": "off",
Expand Down
61 changes: 38 additions & 23 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34808,31 +34808,44 @@ const core = __nccwpck_require__(2186);
const {"main": markdownlintCli2} = __nccwpck_require__(9247);

const logMessage = core.info;
const logError = (error) => {
// eslint-disable-next-line init-declarations
let annotation;
const match = error.match(/^([^:]+):(\d+)(?::(\d+))?\s(\S+)\s(.+)$/u);
if (match) {
const [
,
file,
startLineString,
startColumnString,
,
title
] = match;
const startLine = Number(startLineString);
annotation = {
title,
file,
startLine
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 =
// eslint-disable-next-line max-len
`${fileName}${line}${column} ${name} ${ruleDescription}${detail}${context}${information}`;
const annotation = {
"title": ruleDescription,
"file": fileName,
"startLine": lineNumber,
"endLine": lineNumber
};
if (startColumnString) {
// @ts-ignore
annotation.startColumn = Number(startColumnString);
if (errorRange) {
const [
errorColumn,
errorLength
] = errorRange;
annotation.startColumn = errorColumn;
annotation.endColumn = errorColumn + errorLength - 1;
}
core.error(message, annotation);
}
core.error(error, annotation);
};

const separator = core.getInput("separator") || "\n";
Expand All @@ -34844,7 +34857,9 @@ const argv =
const parameters = {
argv,
logMessage,
logError
"optionsOverride": {
"outputFormatters": [[outputFormatter]]
}
};
let invoke = true;
const command = core.getInput("command");
Expand Down
61 changes: 38 additions & 23 deletions markdownlint-cli2-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,44 @@ const core = require("@actions/core");
const {"main": markdownlintCli2} = require("markdownlint-cli2");

const logMessage = core.info;
const logError = (error) => {
// eslint-disable-next-line init-declarations
let annotation;
const match = error.match(/^([^:]+):(\d+)(?::(\d+))?\s(\S+)\s(.+)$/u);
if (match) {
const [
,
file,
startLineString,
startColumnString,
,
title
] = match;
const startLine = Number(startLineString);
annotation = {
title,
file,
startLine
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 =
// eslint-disable-next-line max-len
`${fileName}${line}${column} ${name} ${ruleDescription}${detail}${context}${information}`;
const annotation = {
"title": ruleDescription,
"file": fileName,
"startLine": lineNumber,
"endLine": lineNumber
};
if (startColumnString) {
// @ts-ignore
annotation.startColumn = Number(startColumnString);
if (errorRange) {
const [
errorColumn,
errorLength
] = errorRange;
annotation.startColumn = errorColumn;
annotation.endColumn = errorColumn + errorLength - 1;
}
core.error(message, annotation);
}
core.error(error, annotation);
};

const separator = core.getInput("separator") || "\n";
Expand All @@ -42,7 +55,9 @@ const argv =
const parameters = {
argv,
logMessage,
logError
"optionsOverride": {
"outputFormatters": [[outputFormatter]]
}
};
let invoke = true;
const command = core.getInput("command");
Expand Down

0 comments on commit 62350ad

Please sign in to comment.