Handle jsdoc errors
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Spec, parse } from "comment-parser"
|
||||
import { Spec, parse, Problem } from "comment-parser"
|
||||
|
||||
export const getTags = (source?: string): Spec[] => {
|
||||
if (!source) return []
|
||||
@@ -8,4 +8,17 @@ export const getTags = (source?: string): Spec[] => {
|
||||
[] as Spec[]
|
||||
);
|
||||
return tags
|
||||
}
|
||||
|
||||
export const getErrors = (source?: string): Error | undefined => {
|
||||
if (!source) return undefined
|
||||
const blocks = parse(source)
|
||||
const probs = blocks.reduce(
|
||||
(acc, block) => acc.concat(block.problems),
|
||||
[] as Problem[]
|
||||
);
|
||||
if (!probs.length) return undefined
|
||||
const errors = probs.map(prob => `[${prob.code}] on line ${prob.line}: ${prob.message}`)
|
||||
const error = new Error(`The following error(s) occured while parsing JSDOC: \n${errors.join('\n')}`)
|
||||
return error
|
||||
}
|
||||
Reference in New Issue
Block a user