Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

requireVarDeclFirst error when comment in function expression #2022

Closed
galvarez421 opened this issue Dec 15, 2015 · 4 comments
Closed

requireVarDeclFirst error when comment in function expression #2022

galvarez421 opened this issue Dec 15, 2015 · 4 comments

Comments

@galvarez421
Copy link

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
Copy link
Member

/cc @Oredi

@markelog markelog added the bug label Dec 18, 2015
@markelog
Copy link
Member

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

@kepta
Copy link
Contributor

kepta commented Jan 10, 2016

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
Copy link
Member

Don't know, it could be

kepta added a commit to kepta/node-jscs that referenced this issue Jan 10, 2016
In this  edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022 - issue
kepta added a commit to kepta/node-jscs that referenced this issue Jan 10, 2016
In this  edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022 - issue
kepta added a commit to kepta/node-jscs that referenced this issue Jan 10, 2016
In this edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022 - issue
kepta added a commit to kepta/node-jscs that referenced this issue Jan 10, 2016
In this edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022 - issue
hzoo pushed a commit to hzoo/node-jscs that referenced this issue Jan 27, 2016
In this edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022
Closes jscs-devgh-2061
hzoo pushed a commit to hzoo/node-jscs that referenced this issue Jan 27, 2016
In this edge case the comments from previous block scope were being taken and
a false positive error was thrown

Fixes jscs-dev#2022
Closes jscs-devgh-2061
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants