Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json-Output #243

Closed
strowi opened this issue Mar 30, 2020 · 6 comments
Closed

Json-Output #243

strowi opened this issue Mar 30, 2020 · 6 comments

Comments

@strowi
Copy link

strowi commented Mar 30, 2020

Hi,

since we are using gitlab and its codeclimate integration, we really would like json-formatted output.
Would you be willing to accept an MR adding json-output adhering to the codeclimate spec ?

-> https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#output

{
  "type": "issue",
  "check_name": "yamllint",
  "description": "wrong indentation: expected 2 but found 4 (indentation)",
  "categories": "Complexity",
  "severity": "critical",
  "location": {
    "path": "/home/x/y/z/test.yml",
    "positions": {
      "begin": {
        "lines": "12",
        "column": "5"
      }
    }
  }
}

Ideally this would include the severity:

severity -- Optional. A Severity string (info, minor, major, critical, or blocker) describing the potential impact of the issue found.

But this would be a breaking change i guess? Since it's optional it could be left out..

regards,
strowi

@adrienverge
Copy link
Owner

Hello @strowi, have you searched similar issues before opening this one?

@strowi
Copy link
Author

strowi commented Mar 31, 2020

Hi @adrienverge,

i only found this ~3y old one regarding json?
#68

After reading the codeclimate-specs again, it seems, they require every issue to be json, but separate issues by "\0", which is not json-compliant. So i guess this would require a separate codeclimate-format?

@adrienverge
Copy link
Owner

Hi @strowi,

A codeclimate-specific (or any software-specific) format won't be accepted here. For JSON output, I propose to continue in #68.

Thanks

@bluikko
Copy link

bluikko commented Oct 29, 2021

A codeclimate-specific (or any software-specific) format won't be accepted here. For JSON output, I propose to continue in #68.

yamllint has support for GitHub. Similarly to GitHub, the cloud service GitLab supports reading output in the "codeclimate" format.

Wouldn't this be comparable to the GitHub support?

@adrienverge
Copy link
Owner

Many could be comparable to the GitHub support. Similarly, we could accept dozens of formats with the same argument. For this reason, there won't be new third-party formats added.

@gardar
Copy link
Contributor

gardar commented Jan 5, 2024

In case someone else comes across this issue when searching for gitlab codeclimate/codequality output, I found this project: https://github.com/ProfessorManhattan/codeclimate-yamllint
Which contains the following script to generate codeclimate output

yamllint $CONFIG -f parsable . | awk 'BEGIN {FS = ":" } ;{gsub(/^[ \t]+|[ \t]+$|"/, "",$4); match($4,/^\[(warning|error)\](.*)\((.*)\)$/,a); if(a[1]=="error") {sev="major"} else { sev="minor"}}; {printf("{\42location\42:{\42path\42:\42%s\42,\42lines\42:{\42begin\42:%s,\42end\42:%s}},\42severity\42:\42%s\42,\42check_name\42:\42%s\42,\42categories\42:[\42Style\42],\42type\42:\42issue\42,\42description\42:\42%s\42}\0",$1,$2,$3,sev,a[3],a[2]);}'

I had to change it a bit to get valid json from it but I ended up with this:

lint:
  stage: lint
  script:
    - mkdir reports
    - >
      yamllint -f parsable . | tee >(awk '
      BEGIN {FS = ":"; ORS="\n"; first=1}
      {
          gsub(/^[ \t]+|[ \t]+$|"/, "", $4);
          match($4, /^\[(warning|error)\](.*)\((.*)\)$/, a);
          sev = (a[1] == "error" ? "major" : "minor");
          if (first) {
              first=0;
              printf("[");
          } else {
              printf(",");
          }
          printf("{\"location\":{\"path\":\"%s\",\"lines\":{\"begin\":%s,\"end\":%s}}," \
                 "\"severity\":\"%s\",\"check_name\":\"%s\",\"categories\":[\"Style\"]," \
                 "\"type\":\"issue\",\"description\":\"%s\"}",
                 $1, $2, $3, sev, a[3], a[2]);
      }
      END { if (!first) printf("]\n"); }' > reports/codequality.json)
  artifacts:
    when: always
    paths:
      - reports
    expire_in: 1 week
    reports:
      codequality: reports/codequality.json

Many could be comparable to the GitHub support. Similarly, we could accept dozens of formats with the same argument. For this reason, there won't be new third-party formats added.

How about going the same route as flake8 and offloading the formatters to plugins?
for example: https://github.com/awelzel/flake8-gl-codeclimate

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

No branches or pull requests

4 participants