awelzel / flake8-gl-codeclimate

Flake8 formatter producing Gitlab Code Quality artifacts.
MIT License
25 stars 12 forks source link

File gets appended instead of overwritten? #13

Closed stdedos closed 2 years ago

stdedos commented 2 years ago

Hello there! I am using a pre-commit hook, like so:

  - repo: https://github.com/pycqa/flake8
    rev: 4.0.1
    hooks:
      - id: flake8
        additional_dependencies:
          - flake8-bugbear
          - flake8-type-checking
          - flake8-gl-codeclimate
        args: [
          --format, gl-codeclimate,
          --output-file, flake8-GitlabCodeClimateReporter.json
        ]

and, from time to time, I see that flake8-GitlabCodeClimateReporter.json looks like:

[]
[]
[]
[]
[]

instead of, at all times:

[]

which is a little weird for me.

Is it possible that, instead of opening the file to write, you open it to append? (... and that's something that falls within this repo?)

tevansuk commented 2 years ago

That's a flake8 "feature". https://github.com/PyCQA/flake8/issues/1491

You need to remove/empty the file yourself before running flake8.

[Although in this case, I'm not sure what you are attempting? Typically a pre-commit hook outputs to stdout so that errors can be alerted on to a real user, where as the gl-codeclimate is for a CI pipeline to read]

stdedos commented 2 years ago

[Although in this case, I'm not sure what you are attempting? Typically a pre-commit hook outputs to stdout so that errors can be alerted on to a real user, where as the gl-codeclimate is for a CI pipeline to read]

You can do both with a CI-action running pre-commit 😄

It's also "a good practice": the pre-commit is "a medium" to (a) enforce whatever checks we want, (b) in CI. It makes an SSOT (single source of truth) of whatever we enforce, instead of "spreading that around" or "maintaining two solutions" ... hopefully the idea is obvious

More "versatile", is what pylint is doing (--output-format=pylint_gitlab.GitlabCodeClimateReporter:pylint-GitlabCodeClimateReporter.json,text [or ,colorized 😄]) - which also makes my case "more correct/complete".

Thank you @tevansuk for digging through this 🎉