Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fullReporter): Fix off-by-one display issue #620

Merged
merged 1 commit into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix line and character display in fullReporter
  • Loading branch information
elliot-nelson committed Jul 1, 2019
commit 4023a973d51650ef9b10f5eba15cd08ebfedbbc6
6 changes: 3 additions & 3 deletions lib/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function fullReporter(fullFilename: boolean = false): Reporter {
const logLine = (lineIndex: number, errorStart: number, errorEnd?: number) => {
const line = lines[lineIndex];
if (errorEnd === undefined) errorEnd = line.length;
console.log('> ' + colors.gray('[' + lineIndex + '] ')
console.log('> ' + colors.gray('[' + (lineIndex + 1) + '] ')
+ line.substring(0, errorStart)
+ colors.red(line.substring(errorStart, errorEnd))
+ line.substring(errorEnd)
Expand All @@ -141,8 +141,8 @@ export function fullReporter(fullFilename: boolean = false): Reporter {

for (let i = error.startPosition.line; i <= error.endPosition.line; i++) {
logLine(i,
i === error.startPosition.line ? error.startPosition.character - 1 : 0,
i === error.endPosition.line ? error.endPosition.character - 1 : undefined
i === error.startPosition.line ? error.startPosition.character : 0,
i === error.endPosition.line ? error.endPosition.character : undefined
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions release/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ function fullReporter(fullFilename = false) {
const line = lines[lineIndex];
if (errorEnd === undefined)
errorEnd = line.length;
console.log('> ' + colors.gray('[' + lineIndex + '] ')
console.log('> ' + colors.gray('[' + (lineIndex + 1) + '] ')
+ line.substring(0, errorStart)
+ colors.red(line.substring(errorStart, errorEnd))
+ line.substring(errorEnd));
};
for (let i = error.startPosition.line; i <= error.endPosition.line; i++) {
logLine(i, i === error.startPosition.line ? error.startPosition.character - 1 : 0, i === error.endPosition.line ? error.endPosition.character - 1 : undefined);
logLine(i, i === error.startPosition.line ? error.startPosition.character : 0, i === error.endPosition.line ? error.endPosition.character : undefined);
}
}
},
Expand Down