Metrics (e.g. a bunch of numbers and graphs that look cool (hopefully))

Ladies and gentleman, today I want to introduce you to our metrics system. We are using Sonarqube to analyse where our code lacks attention. Sonarqube is quickly set up inside a docker container (maphynn_sonarqube) and provides support for several languages. As such, typescript wich is used by our backend. But plugins can also provide metrics for other languages. We used this plugin for our frontend which uses flutter and dart. The sonar-scanners are run during the ci/ce pipline on gitlab for the dev branches. The analysis of the website is currently not working because we do not have any unittests and the sonar-scanner expects test and coverage outputs.

Now lets take a look at how metrics improved our code. I will take the app for an example. First there were approx. 900 code smells ?! What in the world have I done? … well maybe it isn’t entirely my fault… so I think the plugin for dart enables EVERY dartanalyzer rule. Some of the even are contradictory -> Use final modifier for variables that are only assigned once. OK did that, but hey don’t do it for variabels in methods… but you told me to … anyway. It also desn’t like JSON strings no idea why… Anyway after a bit of work we are down to 400ish. And I will from now on use final and write some comments.

Decreasing number of code smells (and bugs).
The use of the modifier final was probably the biggest concern

The following is an example where I decided not to change anything:

I don’t see why I wouldn’t want do that. Sure the name of the variable implies the type but it also doesn’t hurt.

For the Api there were security issues which turned out to be the ‘hardcoded’ passwords for the api documentation so nothing to worry about.

So this is our metrics system. Hope you find this interesting and see you guys next week!

P.S. if anybody also uses sonarqube and has sucessfully activated the authentification using their gitlab, please tell me how. Somehow gitlab appends a “/gitlab” to the end of the redirecion url and it doesn’t work.

P.S.P.S. I think it might be better to set up metrics earlier when you have less code. It might be a lot of set-up in the beginning, but you won’t be overrun by things you did wrong the last year.

2 Replies to “Metrics (e.g. a bunch of numbers and graphs that look cool (hopefully))”

  1. Hi Maphynn,

    Good work!

    Your Sonarqube set-up works well enough running during the CI/CE pipeline. You used Sonarqube to identify and fix some bugs.

    I did have a look at your Sonarqube link and the number of “final variable issues” you got admonished for is impressive.

    Some improvements to fulfill all the grading criteria:
    – Link to two refactorings, e.g. you might link to a commit where
    you changed a final declaration and one involving the use of
    async functions.
    – Add a link to the code you did not refactor.

    All this information is already available on your Sonarqube and your Gitlab. It would be helpful for the reader to have the links.

    Jan set up our Sonarqube. I will ask him about the authentication issue.
    I will mention your idea about setting-up a metrics system earlier to the professor. I agree.

    Best wishes

    Robin from SaSEp

    1. Two more tips (I did not check at your gitlab):
      Link the information from your blog post to your TEST plan and link to the test plan in this blog post.
      Add sonar-qube and sonar flutter to the tech stack info. Again: share the link

Leave a Reply