-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate annotations on the same line
- Loading branch information
Showing
7 changed files
with
278 additions
and
130 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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { Annotation } from "./types"; | ||
|
||
type AnnotationType = "statement" | "function" | "branch"; | ||
|
||
type PartialAnnotation = { | ||
line: number; | ||
message: string[]; | ||
}; | ||
|
||
/** | ||
* Collect annotations for a single file | ||
*/ | ||
export class FileAnnotations { | ||
filepath: string; | ||
annotations: Record<number, PartialAnnotation>; | ||
|
||
constructor(filepath: string, filePrefix: string) { | ||
this.annotations = {}; | ||
|
||
// Strip path prefix off filepath for annotation | ||
if (filePrefix.length) { | ||
if (filepath.startsWith(filePrefix)) { | ||
filepath = filepath.substring(filePrefix.length); | ||
} else { | ||
console.warn( | ||
`The coverage working directory '${filePrefix}' does not exist on coverage file entry: ${filepath}.` | ||
); | ||
} | ||
} | ||
this.filepath = filepath; | ||
} | ||
|
||
/** | ||
* Get existing partial annotation for a line | ||
*/ | ||
getAnnotation(line: number): PartialAnnotation { | ||
let annotation = this.annotations[line]; | ||
if (!annotation) { | ||
annotation = { | ||
line, | ||
message: [], | ||
}; | ||
this.annotations[line] = annotation; | ||
} | ||
return annotation; | ||
} | ||
|
||
/** | ||
* Define an annotation type for a line | ||
*/ | ||
addAnnotation(type: AnnotationType, line: number, column: number) { | ||
const annotation = this.getAnnotation(line); | ||
annotation.message.push(`${type} starting at column ${column}`); | ||
} | ||
|
||
/** | ||
* Get all full annotations | ||
*/ | ||
getAnnotations() { | ||
return Object.values(this.annotations).map( | ||
({ line, message }: PartialAnnotation): Annotation => ({ | ||
title: "Line missing test coverage", | ||
start_line: line, | ||
end_line: line, | ||
start_column: 0, | ||
path: this.filepath, | ||
annotation_level: "warning", | ||
message: message.join("\n").trim(), | ||
}) | ||
); | ||
} | ||
} |
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
Oops, something went wrong.