jscs-dev / node-jscs

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

internalError: Error running rule requirePaddingNewLineAfterVariableDeclaration #2250

Closed Arcanemagus closed 8 years ago

Arcanemagus commented 8 years ago

When running jscs v3.0.3 against this file:

foo.js:

let foo = false;
function bar($foobar) {}

With this configuration:

.jshintrc:

{
  "disallowUnusedParams": true,
  "requirePaddingNewLineAfterVariableDeclaration": true
}

I get the following error in the output:

internalError: Error running rule requirePaddingNewLineAfterVariableDeclaration: This is an issue with JSCS and not your codebase.
Please file an issue (with the stack trace below) at: https://github.com/jscs-dev/node-jscs/issues/new
TypeError: elements.map is not a function
    at Array.<anonymous> (C:\Temp\github\linter-jscs_GH249\node_modules\cst\src\plugins\scopes\ScopesApi.js:56:22)
    at Program._emit (C:\Temp\github\linter-jscs_GH249\node_modules\cst\src\elements\types\Program.js:107:17)
    at Program._addElementsToProgram (C:\Temp\github\linter-jscs_GH249\node_modules\cst\src\elements\types\Program.js:79:14)
    at Program.replaceChildren (C:\Temp\github\linter-jscs_GH249\node_modules\cst\src\elements\Element.js:518:26)
    at Program.replaceChild (C:\Temp\github\linter-jscs_GH249\node_modules\cst\src\elements\Element.js:571:14)
    at Object.JsFile.setWhitespaceBefore (C:\Temp\github\linter-jscs_GH249\node_modules\jscs\lib\js-file.js:110:37)
    at TokenAssert._updateWhitespaceByLine (C:\Temp\github\linter-jscs_GH249\node_modules\jscs\lib\token-assert.js:174:16)
    at TokenAssert._augmentLineCount (C:\Temp\github\linter-jscs_GH249\node_modules\jscs\lib\token-assert.js:364:10)
    at TokenAssert.<anonymous> (C:\Temp\github\linter-jscs_GH249\node_modules\jscs\lib\token-assert.js:284:18)
    at TokenAssert.linesBetween (C:\Temp\github\linter-jscs_GH249\node_modules\jscs\lib\token-assert.js:296:9)

It seems the issue with requirePaddingNewLineAfterVariableDeclaration is causing the code issue reported by disallowUnusedParams to be reported on the wrong line: image

A folder with a minimal reproduction case is included here: linter-jscs_GH249-1.zip

If there is any further information you need just let me know.

Note that this was initially filed here.

Arcanemagus commented 8 years ago

There is also a bug with the following: .jscsrc:

{
  "disallowPaddingNewlinesInBlocks": true,
  "requirePaddingNewLineAfterVariableDeclaration": true
}

foo.js:

let foo = 42;
function bar() {

  let foobar = 42;
}

I'm assuming that the root cause is the same as this one since it requires the requirePaddingNewLineAfterVariableDeclaration rule as well, but if you want this filed as a separate bug just let me know.

markelog commented 8 years ago

Duplicate of https://github.com/jscs-dev/node-jscs/issues/2244