(yamlSource, line, column)
| 245 | } |
| 246 | |
| 247 | static getSourceExtract(yamlSource, line, column) { |
| 248 | let source = ""; |
| 249 | const lines = yamlSource.split(/\r?\n/); |
| 250 | |
| 251 | // Using line numbers instead of array indices |
| 252 | const startLine = Math.max(line - 2, 1); |
| 253 | const endLine = Math.min(line, lines.length); |
| 254 | const padLength = String(endLine).length; |
| 255 | |
| 256 | for (let currentLine = startLine; currentLine <= endLine; currentLine++) { |
| 257 | const currentLineContent = lines[currentLine - 1]; |
| 258 | let string = chalk.gray( |
| 259 | String(currentLine).padStart(padLength, " ") + ":" |
| 260 | ) + " " + currentLineContent + "\n"; |
| 261 | if (currentLine === line) { |
| 262 | string = chalk.bgRed(string); |
| 263 | } |
| 264 | source += string; |
| 265 | } |
| 266 | |
| 267 | source += " ".repeat(column + padLength + 1) + chalk.red("^"); |
| 268 | |
| 269 | return source; |
| 270 | } |
| 271 | |
| 272 | static getYamlExtract({error, yaml}) { |
| 273 | const {line, column} = ValidationError.analyzeYamlError({error, yaml}); |
no outgoing calls
no test coverage detected