Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

CodeClimate JSON Formatter Update Causing Getting Error [Linter] Error running Code Climate TypeError: Cannot convert undefined or null to object #76

Closed
@a-ali

Description

@a-ali

I'm using CodeClimate version 0.70.3

When running the linter on a ruby file, I got this error on the console
[Linter] Error running Code Climate TypeError: Cannot convert undefined or null to object

After some investigation, the root cause was this line in index.js file.
It's trying to access issue.location, but the issue object has no location key.

That's the output of running codeclimate -f json /path/to/file.rb

[
  {
    "name":"ruby.parse.succeeded",
    "type":"measurement",
    "value":1,
    "engine_name":"structure"
  },
  {
    "type":"Issue",
    "check_name":"sql_injection",
    "description":"Possible SQL injection",
    "fingerprint":"...",
    "categories":[
      "Security"
    ],
    "severity":"minor",
    "remediation_points":300000,
    "location":{
      "path":"/path/to/file.rb",
      "lines":{
        "begin":23,
        "end":23
      }
    },
    "content":{
      "body":"..."
    },
    "engine_name":"brakeman"
  },
  {
    "type":"Issue",
    "check_name":"Rubocop/Metrics/CyclomaticComplexity",
    "description":"Cyclomatic complexity for load_resources is too high. [8/6]",
    "categories":[
      "Complexity"
    ],
    "remediation_points":1140000,
    "location":{
      "path":"/path/to/file.rb",
      "positions":{
        "begin":{
          "column":3,
          "line":107
        },
        "end":{
          "column":6,
          "line":114
        }
      }
    },
    "content":{
      "body":"..."
    },
    "fingerprint":"...",
    "engine_name":"rubocop",
    "severity":"minor"
  }
]

You can notice that the first element in the output is of type measurments not Issue, this has been recently introduced in codeclimate json formatter.

So as a quick solution, I just added this condition inside the forEach block

if (issue.type !== 'Issue') {
  return;
}

We may also filter the messages before calling forEach.

Do you have a specific guide to create a pull request with this fix?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions