Skip to content

Commit

Permalink
Remove dependency on equal-length
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Wubben <mark@novemberborn.net>
  • Loading branch information
lightmare and novemberborn committed Dec 31, 2021
1 parent d4ec097 commit bedd1d0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
10 changes: 2 additions & 8 deletions lib/code-excerpt.js
Expand Up @@ -2,7 +2,6 @@ import fs from 'node:fs';

import truncate from 'cli-truncate';
import codeExcerpt from 'code-excerpt';
import equalLength from 'equal-length';

import {chalk} from './chalk.js';

Expand Down Expand Up @@ -34,20 +33,15 @@ export default function exceptCode(source, options = {}) {
value: truncate(item.value, maxWidth - String(line).length - 5),
}));

const joinedLines = lines.map(line => line.value).join('\n');
const extendedLines = equalLength(joinedLines).split('\n');
const extendedWidth = Math.max(...lines.map(item => item.value.length));

return lines
.map((item, index) => ({
line: item.line,
value: extendedLines[index],
}))
.map(item => {
const isErrorSource = item.line === line;

const lineNumber = formatLineNumber(item.line, line) + ':';
const coloredLineNumber = isErrorSource ? lineNumber : chalk.grey(lineNumber);
const result = ` ${coloredLineNumber} ${item.value}`;
const result = ` ${coloredLineNumber} ${item.value.padEnd(extendedWidth)}`;

return isErrorSource ? chalk.bgRed(result) : result;
})
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -91,7 +91,6 @@
"debug": "^4.3.2",
"del": "^6.0.0",
"emittery": "^0.10.0",
"equal-length": "^1.0.1",
"figures": "^4.0.0",
"globby": "^12.0.2",
"ignore-by-default": "^2.0.0",
Expand Down

0 comments on commit bedd1d0

Please sign in to comment.