MCPcopy Create free account
hub / github.com/SAP/ui5-project / getSourceExtract

Method getSourceExtract

lib/validation/ValidationError.js:247–270  ·  view source on GitHub ↗
(yamlSource, line, column)

Source from the content-addressed store, hash-verified

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});

Callers 2

getYamlExtractMethod · 0.80
ValidationError.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected