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

Issues with validateNewlineAfterArrayElements #2244

Closed
Arcanemagus opened this issue May 9, 2016 · 2 comments
Closed

Issues with validateNewlineAfterArrayElements #2244

Arcanemagus opened this issue May 9, 2016 · 2 comments
Labels

Comments

@Arcanemagus
Copy link

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.

@qfox qfox added the bug label May 10, 2016
@pascalpp
Copy link

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

For reference, a fix for one of the duplicates is up in #2252.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants