-
Notifications
You must be signed in to change notification settings - Fork 1
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
Change lines to 1based. #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,16 @@ module.exports = Warnie; | |
* @name Warnie | ||
* @param {string} message - text message of error | ||
* @param {string} filename - name of file the error belongs | ||
* @param {number} [line=0] - errored line | ||
* @param {number} [column=0] - errored column | ||
* @param {number} [severity=0] - severity of the error, one of [-1, 0, 1, 2] | ||
* @param {number} [line=1] - errored line | ||
* @param {number} [column=1] - errored column | ||
* @param {number} [severity=0] - severity of the error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let it be another issue, please? |
||
* @param {Object} [data] - variable data of the error | ||
*/ | ||
function Warnie(message, filename, line, column, severity, data) { | ||
this.message = message + ''; | ||
this.filename = filename + ''; | ||
this.line = line|0; | ||
this.column = column|0; | ||
this.line = line||1; | ||
this.column = column||1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.severity = severity|0; | ||
this.data = data; | ||
} | ||
|
@@ -43,28 +43,29 @@ Warnie.linesAround = 2; | |
* @returns {string} - pretty message with pointer and lines around | ||
*/ | ||
Warnie.prototype.explain = function(lines) { | ||
var humanLine = this.line - 1; | ||
var pointer = Warnie.renderPointer(Warnie.renderLineNumber(0).length + this.column); | ||
var result = [ | ||
renderLine(this.line, lines[this.line]), | ||
renderLine(humanLine, lines[humanLine]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. humanLine is one-based now. Here you need zero-based-line. |
||
Warnie.shadowDye(pointer.slice(0, -1)) + Warnie.pointerDye(pointer.slice(-1)) | ||
]; | ||
|
||
// Prepend lines before the current one | ||
var i = this.line - 1; | ||
while (i >= 0 && i >= (this.line - Warnie.linesAround)) { | ||
var i = humanLine - 1; | ||
while (i >= 0 && i >= (humanLine - Warnie.linesAround)) { | ||
result.unshift(renderLine(i, lines[i])); | ||
i--; | ||
} | ||
|
||
// Append lines after the current one | ||
i = this.line + 1; | ||
while (i < lines.length && i <= (this.line + Warnie.linesAround)) { | ||
i = humanLine + 1; | ||
while (i < lines.length && i <= (humanLine + Warnie.linesAround)) { | ||
result.push(renderLine(i, lines[i])); | ||
i++; | ||
} | ||
|
||
// Prepend error info | ||
var loc = this.line ? (':' + this.line + (this.column ? ':' + this.column : '')) : ''; | ||
var loc = humanLine ? (':' + humanLine + (this.column ? ':' + this.column : '')) : ''; | ||
result.unshift(Warnie.messageDye(this.message) + ' at ' | ||
+ Warnie.filenameDye(this.filename) + loc + ' :'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It can be 0:0 by default (as undefined)