From 9e9642fc6f11a2effdf0296e9943ce58e0f28246 Mon Sep 17 00:00:00 2001 From: Vadim Demedes Date: Mon, 30 Jan 2017 21:58:24 +0200 Subject: [PATCH] adjust code excerpt line trimming --- lib/code-excerpt.js | 2 +- test/code-excerpt.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/code-excerpt.js b/lib/code-excerpt.js index 322c79546..f17f061ba 100644 --- a/lib/code-excerpt.js +++ b/lib/code-excerpt.js @@ -19,7 +19,7 @@ module.exports = (file, line, options) => { const lines = excerpt.map(item => ({ line: item.line, - value: truncate(item.value, maxWidth - String(line).length - 1) + value: truncate(item.value, maxWidth - String(line).length - 5) })); const joinedLines = lines.map(line => line.value).join('\n'); diff --git a/test/code-excerpt.js b/test/code-excerpt.js index 508ce5eda..4608a9a39 100644 --- a/test/code-excerpt.js +++ b/test/code-excerpt.js @@ -33,9 +33,9 @@ test('truncate lines', t => { const excerpt = codeExcerpt(path, 2, {maxWidth: 14}); const expected = [ - ` ${chalk.grey('1:')} function a(…`, - chalk.bgRed(` 2: alert(); `), - ` ${chalk.grey('3:')} } ` + ` ${chalk.grey('1:')} functio…`, + chalk.bgRed(` 2: alert…`), + ` ${chalk.grey('3:')} } ` ].join('\n'); t.is(excerpt, expected);