reviewdog / reviewdog

🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

Home Page:https://medium.com/@haya14busa/reviewdog-a-code-review-dog-who-keeps-your-codebase-healthy-d957c471938b#.8xctbaw5u

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gitlab suggestions are wrong for eslint with `rdjson` format

MSDev201 opened this issue · comments

commented

Suggestions are wrong when using eslint with the rdjson format.
The Suggestions are ignoring the column info which is present in the rdjson format output.

Example:
Unexpected var, use let or const instead.

-    var someVariable = "HelloWorld";
+let

Part of eslint rdjson output:

{
    "message": "Unexpected var, use let or const instead.",
    "location": {
        "path": "somePath",
        "range": {
            "start": {
                "line": 14,
                "column": 1
            },
            "end": {
                "line": 14,
                "column": 33
            }
        }
    },
    "severity": "ERROR",
    "code": {
        "value": "no-var",
        "url": "https://eslint.org/docs/rules/no-var"
    },
    "original_output": "{\"ruleId\":\"no-var\",\"severity\":2,\"message\":\"Unexpected var, use let or const instead.\",\"line\":14,\"column\":1,\"nodeType\":\"VariableDeclaration\",\"messageId\":\"unexpectedVar\",\"endLine\":14,\"endColumn\":33,\"fix\":{\"range\":[468,471],\"text\":\"let\"}}",
    "suggestions": [
        {
            "range": {
                "start": {
                    "line": 14,
                    "column": 1 // This gets ignored
                },
                "end": {
                    "line": 14,
                    "column": 4 // This gets ignored
                }
            },
            "text": "let"
        }
    ]
}
commented

I found the same problem when working with Rubocop (a Ruby lint).
The gitlab-mr-discussion suggestion worked but it does not respect the column in the suggestion yet.
But with some modification, we can still make it work. We need to regenerate the text value of the suggestion from just the linted part to the whole line.
e.g. in your example, we need to add a step to regenerate the text field like that

"suggestions": [
        {
            "range": {
                "start": {
                    "line": 14,
                    "column": 1 // This gets ignored
                },
                "end": {
                    "line": 14,
                    "column": 4 // This gets ignored
                }
            },
-          "text": "let"
+          "text": "    var someVariable = \"HelloWorld\";"
        }
    ]

I did the same mod with Rubocop suggestion here in this repository and found it worked fine even when the suggestion spaned multi-line.
image
I'm not sure that eslint can do the same but I will try a bit when I have time.

+1, it will be great if someone can help fix this issue.