-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,65 @@ export type Severity | |
| 'Ignore' | ||
; | ||
|
||
|
||
export const SEVERITY_LEVELS = ['Error', 'Warning', 'Suggestion', 'Ignore'] as const; | ||
|
||
/** | ||
* An idea suggested by an hlint 'Hint'. | ||
* | ||
* Derived from `src/Idea.hs` in the hlint source code: ndmitchell/[email protected] | ||
*/ | ||
export interface Idea { | ||
/** | ||
* The modules the idea is for, usually a singleton. | ||
*/ | ||
module: string[], | ||
/** | ||
* The declarations the idea is for, usually a singleton, typically the function name, but may be a type name. | ||
*/ | ||
decl: string[], | ||
/** | ||
* The severity of the idea, e.g. 'Warning'. | ||
*/ | ||
severity: Severity, | ||
/** | ||
* The name of the hint that generated the idea, e.g. @\"Use reverse\"@. | ||
*/ | ||
hint: string, | ||
/** | ||
* The source code filename the idea relates to. | ||
*/ | ||
file: string, | ||
/** | ||
* The start line in the source code the idea relates to. | ||
*/ | ||
startLine: number, | ||
/** | ||
* The start column of the source code the idea relates to. | ||
*/ | ||
startColumn: number, | ||
/** | ||
* The end line in the source code the idea relates to. | ||
*/ | ||
endLine: number, | ||
/** | ||
* The end column of the source code the idea relates to. | ||
*/ | ||
endColumn: number, | ||
/** | ||
* The contents of the source code the idea relates to. | ||
*/ | ||
from: string, | ||
/** | ||
* The suggested replacement, or 'Nothing' for no replacement (e.g. on parse errors). | ||
*/ | ||
to?: string, | ||
/** | ||
* Notes about the effect of applying the replacement. | ||
*/ | ||
note: string[], | ||
/** | ||
* How to perform this idea. | ||
*/ | ||
refactorings: string, | ||
} | ||
|
||
|
@@ -38,13 +81,21 @@ const HLINT_SEV_TO_GITHUB_SEV: Record<Severity, GitHubSeverity> = { | |
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: string, quote: boolean): string { | ||
const jsonEscaped = JSON.stringify(str).replace(/\n/g, ' '); | ||
// 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 (' ▫︎ '). | ||
*/ | ||
function getNiceMessage(idea: Idea): string { | ||
const prefixParts = []; | ||
prefixParts.push(idea.severity); | ||
|