Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

black-codeclimate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

black-codeclimate

Convert black --diff output to a Code Climate report

  • 1.0.2
  • PyPI
  • Socket score

Maintainers
1

black-codeclimate

PyPI version

Convert the output of black --diff to a report conforming to the Code Climate spec. It is made to be used in GitLab CI to generate a Code Quality report, which will show a nice widget in merge requests listing the file and the lines affected by the reformatting.

black-codeclimate uses unidiff to parse a diff file and detect changes, and outputs a JSON array of Code Climate issue objects reporting the filename and line range of the change. In theory it could be used on any unified diff data, but I only tested it with black --diff's output. Hit me up in the issues if you use it for anything else :)

Usage

Pipe the output of black --diff into black-codeclimate:

black --diff src/ | black-codeclimate > black_report.json

Or specify a file to use as input:

black-codeclimate black.diff > black_report.json

You can also change the severity, description and check_name of the issues in the resulting report by specifying command line flags:

black-codeclimate --severity blocker --description "would reformat [black]" --check-name "black" black.diff > black_report.json

Run black-codeclimate -h to see a list of the available flags.

Adding it to GitLab

Add this step to your .gitlab-ci.yml file:

lint:black:
  stage: lint
  before_script:
    - # Install black and black-codeclimate...
  script:
    # --check fails the job if any inconsistent formatting is detected.
    - black --diff --check src/ > black.diff
  after_script:
    - black-codeclimate black.diff > black_report.json
  artifacts:
    reports:
      codequality: black_report.json
    when: always

This will upload the black_report.json as a GitLab Code Quality artifact. The lines that would be reformatted by black will show up as a merge request widget.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc