Saturday 14 November 2020

Formatting and Linting my Life

 


Hello my fellow followers (professor).
I hope you are all doing well, despite Toronto being in the red zone. 

So, this week was an interesting one for my open source ventures. Lab 7 was released and we were tasked with implementing a code formatter and linter for our, you guessed it, link checker.

To be honest, I've grown fond of working on this little program because I enjoy building on top of it. It's awesome, it started as a POS horrid bandaged looking program but has since turned into something gorgeous, something like a rose if you will.

Anyways, I will get right into it because I have to finish 2 more blogs for this week and do my Game Dev lab #ThankGeorge. 

The first task was to choose a code formatter that would format code according to some standards. I chose the google-java-format that professor Humphrey suggested.

So this tool was actually pretty easy to use. I read the manual and just ran the jar file with the options on the CLI and it worked like a charm.

Low key,
I kind of don't like the way it formatted some of the files and in some instances it became even harder to read... Google standards are weird.

I actually took the extra challenge and made a git hook that will do this automatically every time on any file you commit. (I had some help from a couple of google searches on how to set this up properly)

So I made a little script that would download the formatter to a temp directory, if you don't already have it. The rest is self explanatory but I will throw the script anyways.

I actually installed this as a plugin for my IDE because... why not.

So the next thing we were tasked with was to pick a linter for our code that would improve our code and spot bugs automatically, professors lectures were actually really neat on this. I won't get into details though.

Once again, I chose to go with the professor's recommendations and chose the SpotBugs linter for java.
This was a big harder to use as the documentation was not that explanatory. As the standalone version I chose to use the GUI to see how it was. It was pretty cool so I recommend using that. It spot a couple of "bugs" in my code but not that many. I would say the major one it found was in my Load Ignore files, java file.
I was not closing the BufferedReader and it told me that (see below)

This is actually the same linter but the plugin version on my IntelliJ IDE. The fix it suggested was to either close the reader manually or encapsulate it in a try and catch block, like so.

You can read the full documentation on the CONTRIBUTING.md on my repo.

The final step was to squash all of my commits and push it to github.

Alright, that is all from me for this week's lab.

Till next time, 
XOXO, 
Gossip Plamen

No comments:

Post a Comment

Release 0.4.3 - The End of Something Great

  Hello my wonderful followers! It is here... It is finally here. The end of this nightmarish semester is finally here. I have to say the pa...