DEV Community

Michael Brackett
Michael Brackett

Posted on

OSD Lab-7

This week for our Lab 7 we were tasked with adding a Formatter & Linter into our Link Checker program (you can find mine here)

Since my program is made with Python I decided on using Python Black and Flake8 Python black is a formatting tool that when you run it, will format the code to the configurations that you or another contributor chose for the project. Flake8 is a linter which will go through you code and tell you if you have any small mistakes in the code, i.e. unused import statements.

Setting the code up in my project was pretty easy, all I had to do was run

pip install black
pip install flake8
Enter fullscreen mode Exit fullscreen mode

And just like that I had both the tools ready to be used. Afterwords I created a small shell script that the user could run with the command bash format.sh, inside is the code:

black link-check.py
Enter fullscreen mode Exit fullscreen mode

All this would do is just run the black formatter on my link-check.py file with the configurations that I set up. I also excluded all other files in my repository from black using a configuration file just incase something went wrong and the user tried to format other files.

I did the same thing with the linter.

I didn't have any issues other than the linter found that instead of having two blank lines before a function I had one which was a very quick fix. A complication arose when the linter was telling me that the lines were too long but the linter was adding in the whitespace before the lines.

Basically how I fixed this was just set up the configuration file to ignore that linter error because since the formatter was formatting properly, it wouldn't matter what the linter says. (The formatter and the linter were set to the same line length but I guess the linter accounts for whitespace before the characters while the formatter doesnt)

I chose to integrate my tools using Visual Studio Code, it was fairly easy following this guide from Visual Studio (To find formatting help click on "Editing Code" and to find Linter help click on "Linter")

Pretty much all I had to do was just write a couple of lines in a settings.json file that I put in a .vscode folder that was in the root of my file system. After that vscode did everything for me.

I found this lab incredibly useful as not to long ago with my Release 2.0 I was amazed by one of the project using a linter (They were using pylint). I spoke with my professor about it and we had a little talk about the usefulness of a linter. I will for sure be using it with my open source projects in the future. You can find my blog about when I first encountered a linter here

Top comments (0)