Package: black-gl-code-quality
Black GitLab Code QualityThis project aim to convertBlackreport toCodeClimateformat that can be ingest by GitLab.→ poetry run black-gl-cq src/black_gl_code_quality | jq
[
  {
    "type": "issue",
    "description": "Black would reformat",
    "location": {
      "lines": {
        "begin": 1,
        "end": 1
      },
      "path": "src/black_gl_code_quality/__main__.py"
    },
    "severity": "major"
  },
  {
    "type": "issue",
    "description": "Black would reformat",
    "location": {
      "lines": {
        "begin": 1,
        "end": 1
      },
      "path": "src/black_gl_code_quality/error.py"
    },
    "severity": "major"
  }
]MotivationFor security concerns, Docker-in-Docker has been disabled in all GitLab runners that I
have access/manage. Because the Code Quality template shipped with GitLab instances use
CodeClimate CLI that requires a Docker environment, we can't use it and an alternative
solution was required to obtain Black errors in our Code Quality reports.How to installSimply run the following command:pip install black-gl-code-qualityIf you use Poetry, you can add it to your dev-dependencies:poetry add --group dev black-gl-code-qualityUsageThere is two ways to use this tool:by piping Blackby callingblack-gl-code-quality(or by it's aliasblack-gl-cq) directlyPiping with BlackPiping with Black requires to forwardstderrtostdout. You can use the following
command in the.gitlab-ci.yml:black --check src/ 2>&1 | black-gl-cq > black-code-quality-report.jsonHere's an example for a GitLab-CI job:lint:black:stage:testscript:-source .venv/bin/activate-black --check src/ 2>&1 | black-gl-cq > black-code-quality-report.jsonartifacts:when:alwaysreports:codequality:black-code-quality-report.jsonCallingblack-gl-code-qualitydirectlyCallingblack-gl-code-quality(or it's aliasblack-gl-cq) execute Black with the--checkargument. It forwards all arguments you pass if you need to configure Black
via the CLI.Specifying source folders isMANDATORY.Here's an example for a GitLab-CI job:lint:black:stage:testscript:-source .venv/bin/activate-black-gl-cq src/ > black-code-quality-report.jsonartifacts:when:alwaysreports:codequality:black-code-quality-report.jsonAdmit we want to skip string normalization:lint:black:stage:testscript:-source .venv/bin/activate-black-gl-cq -S src/ > black-code-quality-report.jsonartifacts:when:alwaysreports:codequality:black-code-quality-report.jsonChange severityBy default, all errors have the severitymajor. Depending how you consider Black issues
important, you can change the severity for all errors returned by the report by using
one of the followingvalueswith theBLACK_GL_SEVERITYenvironment variable:info,minor,major,critical,blocker.Here's an example for a GitLab-CI job:lint:black:stage:testvariables:BLACK_GL_SEVERITY:minorscript:-source .venv/bin/activate-black-gl-cq src/ > black-code-quality-report.jsonartifacts:when:alwaysreports:codequality:black-code-quality-report.jsonContributionsIn case you have a suggestion or want a new feature, feel free to open adiscussion.If you found a bug, you canopen an issue.In order to maintain an overall good code quality, this project use the following tools:BlackIsortFlake8Linting and formatting tools are configured to match thecurrent default rules of Black.Please ensure to run these tools before commiting and submiting a Pull request. In case one of
these mentionned tools report an error, the CI will automatically fail.In case you are able to fix by yourself a bug, enhance the code or implement a new
feature, feel free to send aPull request.LicenseThis project is released under theBSD-3 Clause. Feel free to use,
contribute, fork and do what you want with it. Please keep all licenses, copyright
notices and mentions in case you use, re-use, steal, fork code from this repository.