Handle jsdoc errors

This commit is contained in:
muzam1l
2022-07-05 19:38:26 +05:30
parent 175b6266e8
commit 6a0aabdeda
2 changed files with 42 additions and 28 deletions

View File

@@ -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
}