Member-only story

Create checkstyle report for python

And how to integrate that report in you CI pipeline

Thomas Poignant
2 min readSep 20, 2020
Photo by Luca Bravo on Unsplash

I will not explain to you how cool it is to have a linter on your project, it helps you to fail fast and to learn how to write better code.

To lint the project I use flake8 , which is a wrapper around PyFlakes , pycodestyle and Ned Batchelder’s McCabe script. So it does a lot of things!

To install it, it’s easy with pip

pip install flake8

To run it you can just use

flake8 $(shell git ls-files '*.py')

As you can see here we are checking every py files in git.

Now that I have a way to have feedback on my code, I want to run it by my continuous integration and also report it to the central system of my company for quality gates.

The format of export in my company should be a checkstyle format (TL;DR this a standard XML format to display checkstyle errors). flak8 natively support this format so you can run.

flake8 $(shell git ls-files '*.py') --format=checkstyle

It output something that looks like

<?xml version='1.0' encoding='utf-8'?>
<checkstyle>
<file name="infra/bastion.py">
<error severity="error" line="16"…

--

--

Thomas Poignant
Thomas Poignant

Written by Thomas Poignant

Engineering Manager! I build apps and deploy them in the ☁️. #GO #AWS #CICD. https://thomaspoignant.medium.com/subscribe

No responses yet