-
Notifications
You must be signed in to change notification settings - Fork 63
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: Emit correct endLine numbers #88
Conversation
Hmm, further testing shows something is weird with the way comment blocks are being used in the line number calculations... |
Fixed! I wasn't actually adding the |
It seems Node < 4.0 doesn't like eslint 4.0 😕 To get the build passing, I added a test to |
yes, eslint v4 does not support Node < 4. and the up-coming eslint v5 will drop supporting Node < 6. So we might need to do something to drop the older Node? |
@aladdin-add I think we would just need to update .travis.yml to not build against those old Node versions? |
I just created a PR #89 to do it. (maybe need update the docs). |
@plmrry thanks for doing this! As you've figured out, and to clarify for anyone else reading, the I left #89 (comment) trying to figure out what to do with this, and I'd like to hear your thoughts as well. If we do decide against dropping support for eslint < 4, it's possible with a small tweak to implement this change in a way that's fully backwards-compatible with eslint prior to 3.1.0: diff --git a/lib/processor.js b/lib/processor.js
index 113b289..a13b795 100644
--- a/lib/processor.js
+++ b/lib/processor.js
@@ -129,16 +129,17 @@ function adjustBlock(block) {
return function adjustMessage(message) {
var lineInCode = message.line - leadingCommentLines;
- var endLine = message.endLine - leadingCommentLines;
if (lineInCode < 1) {
return null;
}
var out = {
line: lineInCode + blockStart,
- endLine: endLine ? endLine + blockStart : endLine,
column: message.column + block.position.indent[lineInCode - 1] - 1
};
+ if (message.endLine >= 0) {
+ out.endLine = message.endLine + blockStart;
+ }
return assign({}, message, out);
}; |
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.
Sorry about the delay - I just merged #89, which means this PR can now assume a minimum of ESLint v4! I commented in two places where the tests will now work, so just those two tweaks and then LGTM
tests/lib/plugin.js
Outdated
@@ -45,6 +45,51 @@ describe("plugin", function() { | |||
assert.equal(report.results[0].messages[0].line, 2); | |||
}); | |||
|
|||
it.skip("should emit correct line numbers", function() { |
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.
These two tests should now pass with ESLint 4!
tests/lib/processor.js
Outdated
@@ -514,13 +514,13 @@ describe("processor", function() { | |||
].join("\n"); | |||
var messages = [ | |||
[ | |||
{ line: 1, column: 1, message: "Use the global form of \"use strict\".", ruleId: "strict" }, | |||
{ line: 3, column: 5, message: "Unexpected console statement.", ruleId: "no-console" } | |||
{ line: 1, endLine: NaN, column: 1, message: "Use the global form of \"use strict\".", ruleId: "strict" }, |
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.
Now that #89 dropped support for ESLint < v4, we should be able to test without any NaN
here, so this would be 1, and the assertion below would become 4.
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.
Just pushed some changes to the fork to re-enable the endLine
tests. Leaving this open for a couple days in case anyone else has comments.
Fixes #87
This adds each blocks
start.line
to each message'sendLine
, if it exists on the message.This PR also updates theeslint
used in tests to version 4. The older version of eslint did not emitendLine
numbers.