Skip to content

Commit

Permalink
A few docs + style cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rwe committed Jul 23, 2020
1 parent 41504ad commit 062b56d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/github/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type MatcherGroups = Record<keyof Problem, number>
const MATCH_LINE_REGEX_GROUPS: MatcherGroups = (
MATCH_LINE_KEYS
.map((key, index) => ([key, index + 1]))
.reduce((obj, keyAndMatchGroup) => ({...obj, [keyAndMatchGroup[0]]: keyAndMatchGroup[1]}), {} as MatcherGroups)
.reduce((obj, [key, matchGroup]) => ({...obj, [key]: matchGroup}), {} as MatcherGroups)
);

function getMatcherPatternObj(toolName: string): ProblemPattern {
Expand Down
55 changes: 53 additions & 2 deletions src/hlint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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);
Expand Down

0 comments on commit 062b56d

Please sign in to comment.