jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 513 forks source link

requireVarDeclFirst error when comment in function expression #2022

Closed galvarez421 closed 8 years ago

galvarez421 commented 8 years ago

Rule that has issue: "requireVarDeclFirst: true" Code that will make jscs exhibit the issue: .jscsrc file:

{
  "requireVarDeclFirst": true
}

test.js

var test = function() {
  var color = "grey";
  // This is a comment
};
var test2 = "string";

node command:

jscs test.js

The task will report an error for the line with the second assignment, but if I remove the comment in the function expression, the error goes away.

Using jscs 2.7.0 Operating system: Windows 7 64-bit

markelog commented 8 years ago

/cc @oredi

markelog commented 8 years ago

btw, @galvarez421 you are welcome to try to fix it yourself, might be faster that way

kepta commented 8 years ago

Hello, I was trying to fix this bug, I found the following code to be of particular interest

        if (comment.range[0] > currentNode.range[0] &&
            comment.range[1] < currentNode.range[1]) {
            // Stop processing comments that are within multiple declarators in a single variable declaration
            break;
        }

I believe we should also have a similar check for the previousNode, @markelog ?

markelog commented 8 years ago

Don't know, it could be