Skip to content

Commit

Permalink
feat(annotations): group lint output by file path
Browse files Browse the repository at this point in the history
  • Loading branch information
a-b-r-o-w-n committed Apr 20, 2021
1 parent 5f39ea0 commit 777df90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ESLint } from "eslint";
import { formatMessage } from "./formatMessage";
import { wrapInGroup } from "./wrapInGroup";

function getRelativePath(path: string) {
const { GITHUB_WORKSPACE } = process.env;
Expand All @@ -16,7 +17,7 @@ export default function report(results: ESLint.LintResult[]) {
const { filePath, messages } = result;
const relFilePath = getRelativePath(filePath);

for (const message of messages) {
wrapInGroup(relFilePath, messages, (message) => {
if (!message.ruleId) {
return;
}
Expand All @@ -33,7 +34,7 @@ export default function report(results: ESLint.LintResult[]) {
default:
break;
}
}
});
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/wrapInGroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Linter } from "eslint";

const groupSet = new Set<string>();

const startGroupOnce = (groupName: string) => {
if (!groupSet.has(groupName)) {
console.log(`::group::${groupName}`);
groupSet.add(groupName);
}
};

export function wrapInGroup(
groupName: string,
messages: Linter.LintMessage[],
cb: (message: Linter.LintMessage) => void
) {
for (const message of messages) {
startGroupOnce(groupName);
cb(message);
}

if (groupSet.has(groupName)) {
console.log("::endgroup::");
}
}

0 comments on commit 777df90

Please sign in to comment.