Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add json-file option #57

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ so hints are displayed as GitHub annotations.
* `- path: '["src/", "test/"]'`
* `- path: ${{ toJSON(steps.whatever.changed_dirs) }}` (see: docs on [toJSON](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#tojson))
* `hlint-bin` (optional): The `hlint` binary path, if not already in `PATH`.
* `json-file` (optional): If given, the action reads JSON hint output from this
file instead of running `hlint` directly. Can be useful for integration with
alternate build systems.

## Outputs

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
description: 'Path or JSON array of paths to check with hlint'
required: false
default: '.'
json-file:
description: 'Existing hlint JSON output file to use instead of running hlint'
required: false
outputs:
ideas:
description: 'A JSON array of HLint output ideas (errors, warnings, suggestions, and so on)'
Expand Down
8 changes: 4 additions & 4 deletions dist/hlint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ const HLINT_SEV_TO_GITHUB_SEV = {
Ignore: 'warning',
};
/**
* Use JSON escaping to turn messages with newlines and such into a single line.
* Use JSON escaping to turn convert literal newlines to Github Action-supported newlines.
*/
function escapeString(str, quote) {
const jsonEscaped = JSON.stringify(str).replace(/\n/g, ' ');
const jsonEscaped = JSON.stringify(str).replace(/\n/g, '%0A');
// Possibly drop the surrounding quotes
return quote ? jsonEscaped : jsonEscaped.slice(1, jsonEscaped.length - 1);
}
/**
* 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 (' ▫︎ ').
* Fields are visually separated by newlines.
*/
function getNiceMessage(idea) {
const prefixParts = [];
Expand All @@ -68,7 +68,7 @@ function getNiceMessage(idea) {
if (idea.note && idea.note.length) {
messageParts.push(`Note: ${idea.note.map(n => escapeString(n, false)).join(' ')}`);
}
const message = messageParts.join(' ▫︎ ');
const message = messageParts.join('%0A');
return [prefix, message].filter(Boolean).join(': ');
}
function toMatchableProblem(idea) {
Expand Down
Loading