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

Issues with validateNewlineAfterArrayElements #2244

Closed Arcanemagus closed 8 years ago

Arcanemagus commented 8 years ago

When running jscs v3.0.3 against this file:

foo.js:

var bar = [1, 2, 3, 4, 5, 6]

With this configuration:

.jshintrc:

{
    "validateNewlineAfterArrayElements": {
        "maximum": 4
    }
}

I get the following error in the output:

TypeError: Cannot read property 'replace' of undefined
    at renderLine (C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\errors.js:266:16)
    at Object.Errors.explainError (C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\errors.js:197:13)
    at C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\reporters\console.js:16:36
    at Array.forEach (native)
    at C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\reporters\console.js:14:35
    at Array.forEach (native)
    at Object.module.exports [as writer] (C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\reporters\console.js:9:22)
    at C:\Temp\github\linter-jscs_GH239\node_modules\jscs\lib\cli.js:149:18
    at Array.<anonymous> (C:\Temp\github\linter-jscs_GH239\node_modules\vow\lib\vow.js:712:56)
    at Immediate.callFns [as _onImmediate] (C:\Temp\github\linter-jscs_GH239\node_modules\vow\lib\vow.js:23:35)

If the reporter is changed to JSON, it seems to be incrementing the line value for every element?

{".\\foo.js":[{"line":1,"column":12,"message":"validateNewlineAfterArrayElements: First element should be placed on new line"},{"line":2,"column":3,"message":"validateNewlineAfterArrayElements: Multiple elements at a single line in multiline array"},{"line":3,"column":4,"message":"validateNewlineAfterArrayElements: Multiple elements at a single line in multiline array"},{"line":4,"column":4,"message":"validateNewlineAfterArrayElements: Multiple elements at a single line in multiline array"},{"line":5,"column":4,"message":"validateNewlineAfterArrayElements: Multiple elements at a single line in multiline array"},{"line":6,"column":4,"message":"validateNewlineAfterArrayElements: Multiple elements at a single line in multiline array"},{"line":7,"column":3,"message":"validateNewlineAfterArrayElements: Closing bracket should be placed on new line"}]}

Using the Node API (Inside the linter-jscs Atom package) returns results similar to the JSON output. Note that this was initially filed here

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

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

pascalpp commented 8 years ago

I'm new to this codebase, but I've been digging into it, trying to figure this out. I'm not exactly sure what's going on. At the moment, I think it has something to do with TokenIndex._buildIndex which is where the __loc gets assigned to each token. (Those __loc values are the first time I can see erroneous line numbers show up in the output.) I'm just dropping console.logs in the source, not sure if there's a better way to track this down.

Arcanemagus commented 8 years ago

For reference, a fix for one of the duplicates is up in https://github.com/jscs-dev/node-jscs/pull/2252.