Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = (diag) => {
if (!diag || typeof diag.source !== 'string')
return null
if (!diag.source || !diag.at || !diag.at.line || !diag.at.file)
return diag.source
const source = diag.source
const at = diag.at
try {
const lines = highlightFileSync(at.file, {
jsx: true,
theme,
}).split('\n')
const ctx = 3
const startLine = Math.max(at.line - ctx, 0)
const endLine = Math.min(at.line + ctx, lines.length)
const numLen = endLine.toString().length + 1
const caret = at.column
? [
` ${new Array(numLen).join(' ')
} ` + hex('#777')('| ') +
red(`${new Array(at.column).join('-')}${bold('^')}`)
] : []