Skip to content

Commit

Permalink
Update compiled outputs and version number
Browse files Browse the repository at this point in the history
  • Loading branch information
rwe committed Jul 23, 2020
1 parent 062b56d commit 439a0f8
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 66 deletions.
2 changes: 1 addition & 1 deletion dist/github/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getMatchLineRegexString(toolName) {
}
const MATCH_LINE_REGEX_GROUPS = (exports.MATCH_LINE_KEYS
.map((key, index) => ([key, index + 1]))
.reduce((obj, keyAndMatchGroup) => (Object.assign(Object.assign({}, obj), { [keyAndMatchGroup[0]]: keyAndMatchGroup[1] })), {}));
.reduce((obj, [key, matchGroup]) => (Object.assign(Object.assign({}, obj), { [key]: matchGroup })), {}));
function getMatcherPatternObj(toolName) {
return Object.assign({ regexp: getMatchLineRegexString(toolName) }, MATCH_LINE_REGEX_GROUPS);
}
Expand Down
47 changes: 27 additions & 20 deletions dist/hlint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,53 +29,60 @@ const HLINT_SEV_TO_GITHUB_SEV = {
Suggestion: 'warning',
Ignore: 'warning',
};
// Use JSON escaping to turn messages with newlines and such into a single line
/**
* Use JSON escaping to turn messages with newlines and such into a single line.
*/
function escapeString(str, quote) {
const jsonEscaped = JSON.stringify(str).replace(/\n/g, ' ');
// Possibly drop the surrounding quotes
return quote ? jsonEscaped : jsonEscaped.slice(1, jsonEscaped.length - 1);
}
function getNiceMessage(hint) {
/**
* Combine the non-"poblemMatcher" fields of an "idea" into
* a single line as a human-readable message.
*
* Fields are visually separated by a box character (' ▫︎ ').
*/
function getNiceMessage(idea) {
const prefixParts = [];
prefixParts.push(hint.severity);
if (hint.decl && hint.decl.length) {
prefixParts.push(`in ${hint.decl.join(', ')}`);
prefixParts.push(idea.severity);
if (idea.decl && idea.decl.length) {
prefixParts.push(`in ${idea.decl.join(', ')}`);
}
if (hint.module && hint.module.length) {
prefixParts.push(`in module ${hint.module.join('.')}`);
if (idea.module && idea.module.length) {
prefixParts.push(`in module ${idea.module.join('.')}`);
}
const prefix = prefixParts.join(' ');
const messageParts = [];
messageParts.push();
messageParts.push(hint.hint);
if (hint.from) {
messageParts.push(`Found: ${escapeString(hint.from, true)}`);
messageParts.push(idea.hint);
if (idea.from) {
messageParts.push(`Found: ${escapeString(idea.from, true)}`);
}
if (hint.to) {
messageParts.push(`Perhaps: ${escapeString(hint.to, true)}`);
if (idea.to) {
messageParts.push(`Perhaps: ${escapeString(idea.to, true)}`);
}
if (hint.note && hint.note.length) {
messageParts.push(`Note: ${hint.note.map(n => escapeString(n, false)).join(' ')}`);
if (idea.note && idea.note.length) {
messageParts.push(`Note: ${idea.note.map(n => escapeString(n, false)).join(' ')}`);
}
const message = messageParts.join(' ▫︎ ');
return [prefix, message].filter(Boolean).join(': ');
}
function toMatchableProblem(hint) {
const { file, startLine: line, startColumn: column, hint: code, severity: hlintSev } = hint;
function toMatchableProblem(idea) {
const { file, startLine: line, startColumn: column, hint: code, severity: hlintSev } = idea;
return {
file,
line,
column,
severity: HLINT_SEV_TO_GITHUB_SEV[hlintSev],
code,
message: getNiceMessage(hint),
message: getNiceMessage(idea),
};
}
exports.MATCHER = new github_1.SingleLineMatcherFormat('hlint');
// NOTE: Because ncc compiles all the files, take not to use __dirname here.
// This path is relative to the repo root. (Possibly meaning cwd, but not necessarily).
exports.MATCHER_DEF_PATH = path.join('.github', 'hlint.json');
function serializeProblem(hint) {
return exports.MATCHER.serialize(toMatchableProblem(hint));
function serializeProblem(idea) {
return exports.MATCHER.serialize(toMatchableProblem(idea));
}
exports.serializeProblem = serializeProblem;
71 changes: 39 additions & 32 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/outputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const OUTPUT_KEY_HLINT_HINTS = 'hints';
const OUTPUT_KEY_HLINT_IDEAS = 'ideas';
function setOutputs(result) {
const { ok, hints, statusCode, hintSummary } = result;
core.setOutput(OUTPUT_KEY_HLINT_HINTS, hints);
const { ok, ideas, statusCode, hintSummary } = result;
core.setOutput(OUTPUT_KEY_HLINT_IDEAS, ideas);
if (ok) {
if (hintSummary.length) {
core.info(`HLint finished with hints: ${hintSummary}`);
Expand Down
16 changes: 8 additions & 8 deletions dist/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ function runHLint(cmd, args) {
core.info(`Running ${cmd} ${args.join(' ')}`);
const { stdout: hlintOutputStr, statusCode } = yield bufferedExec_1.default(cmd, args);
core.info(`hlint completed with status code ${statusCode}`);
const hints = JSON.parse(hlintOutputStr);
hints.map(hlint_1.serializeProblem).forEach(line => console.log(line));
return { hints, statusCode };
const ideas = JSON.parse(hlintOutputStr);
ideas.map(hlint_1.serializeProblem).forEach(line => console.log(line));
return { ideas, statusCode };
});
}
function getOverallCheckResult(failOn, { hints, statusCode }) {
const hintsBySev = hlint_1.SEVERITY_LEVELS.map(sev => ([sev, hints.filter(hint => hint.severity === sev).length]));
function getOverallCheckResult(failOn, { ideas, statusCode }) {
const hintsBySev = hlint_1.SEVERITY_LEVELS.map(sev => ([sev, ideas.filter(hint => hint.severity === sev).length]));
const hintSummary = hintsBySev
.filter(([_sevName, numHints]) => numHints > 0)
.map(([sev, num]) => `${sev} (${num})`).join(', ');
Expand All @@ -75,9 +75,9 @@ function run({ baseDir, hlintCmd, pathList, failOn }) {
return __awaiter(this, void 0, void 0, function* () {
const hlintArgs = ['-j', '--json', '--', ...pathList];
const matcherDefPath = path.join(baseDir, hlint_1.MATCHER_DEF_PATH);
const { hints, statusCode } = yield withMatcherAtPath_1.default(matcherDefPath, () => runHLint(hlintCmd, hlintArgs));
const { ok, hintSummary } = getOverallCheckResult(failOn, { hints, statusCode });
return { ok, statusCode, hints, hintSummary };
const { ideas, statusCode } = yield withMatcherAtPath_1.default(matcherDefPath, () => runHLint(hlintCmd, hlintArgs));
const { ok, hintSummary } = getOverallCheckResult(failOn, { ideas, statusCode });
return { ok, statusCode, ideas, hintSummary };
});
}
exports.default = run;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rwe/actions-hlint",
"version": "1.0.0",
"version": "2.0.0",
"description": "GitHub Action: Run HLint",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 439a0f8

Please sign in to comment.