DEV Community

Cover image for We need Cheese! Gromit!
Ronald R
Ronald R

Posted on

We need Cheese! Gromit!

In this lab, we decided to work on making our code neat and tidy, prim and proper. And what's better than making it a story about cleanliness with our pals, Wallace and Gromit? Wallace is an inventor and entrepreneur, and at the end of the day, he finds himself dashing enough to make a were-rabbit fall in love.

So, we had a couple of things we needed to do. First of all, we needed to create a CONTRIBUTING.md file, which is for anyone who would like to make other enhancements, report issues, bugs, and other code-related matters. Next, we had to use a code formatter. Here is where it got interesting.

I used Python Black as my source formatter, and it was fairly easy since I had some idea of how it is used and how it works. I was able to set up a configuration for it as well.

Next, I needed a linter. Now, a linter, for those who have no idea what it is at first, is a way to display errors and warnings in a piece of code that you have, which may cause issues. In my case, it was the line

i = 0

, which I had hidden away in my code—literally present but not being used. Without it, I probably would have never figured it out.

I used Ruff, which is similar to Python Black but somehow entirely different in its own way. I know it's confusing, but regardless, I used both. Did I need both? I think so because, at least, Ruff will show me if there are things I missed. Unlike Black, which is just a source formatter, Ruff was pretty straightforward. I was also able to create a configuration file setup for it.

Now I needed to implement an IDE where, once saved, it automatically runs Black and Ruff. Automatically, this took quite a bit of research, and I was able to follow the guidelines. I created a .vscode folder and placed the files there to ensure a call on those two dependencies.

We had been asked to challenge ourselves and add a pre-commit, which I gladly did. I added a pre-commit file ensuring that Ruff and Black would run before being able to commit all the changes.

All in all, this was a very interesting lab to work on. As someone who is known for not being the tidiest coder, it was a nice piece of information and a set of tools to have.

Top comments (0)