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: Emit correct endLine numbers #88

Merged
merged 7 commits into from
Jun 4, 2018

Conversation

plmrry
Copy link

@plmrry plmrry commented Mar 31, 2018

Fixes #87

This adds each blocks start.line to each message's endLine, if it exists on the message.

This PR also updates the eslint used in tests to version 4. The older version of eslint did not emit endLine numbers.

@jsf-clabot
Copy link

jsf-clabot commented Mar 31, 2018

CLA assistant check
All committers have signed the CLA.

@plmrry
Copy link
Author

plmrry commented Mar 31, 2018

Hmm, further testing shows something is weird with the way comment blocks are being used in the line number calculations...

@plmrry
Copy link
Author

plmrry commented Mar 31, 2018

Fixed! I wasn't actually adding the leadingCommentLines in my calcuation

@plmrry
Copy link
Author

plmrry commented Mar 31, 2018

It seems Node < 4.0 doesn't like eslint 4.0 😕

To get the build passing, I added a test to processor.js and skipped my tests in plugin.js (which require eslint 4.0 to pass, since before eslint 4.0, endLine was not a part of the message object)

@aladdin-add
Copy link
Member

aladdin-add commented Mar 31, 2018

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?

@plmrry
Copy link
Author

plmrry commented Apr 1, 2018

@aladdin-add I think we would just need to update .travis.yml to not build against those old Node versions?

@aladdin-add
Copy link
Member

I just created a PR #89 to do it. (maybe need update the docs).

@aladdin-add aladdin-add requested review from btmills and removed request for btmills April 1, 2018 22:15
@btmills
Copy link
Member

btmills commented Apr 8, 2018

@plmrry thanks for doing this! As you've figured out, and to clarify for anyone else reading, the endLine key wasn't added to messages until [email protected], but this plugin is currently tested all the way back to node 0.10, which means it's tested against eslint@^2, since [email protected] dropped support for node < 4. That prevents a full integration test, though this change can still be unit tested by manually supplying endLine in the processor tests.

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);
     };

Copy link
Member

@btmills btmills left a 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

@@ -45,6 +45,51 @@ describe("plugin", function() {
assert.equal(report.results[0].messages[0].line, 2);
});

it.skip("should emit correct line numbers", function() {
Copy link
Member

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!

@@ -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" },
Copy link
Member

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.

Copy link
Member

@btmills btmills left a 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.

@btmills btmills merged commit dff8e9c into eslint:master Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants