Code Review at compilation time

Asked

Viewed 384 times

3

I need to do an automatic Code Review on my codes. We used the Jenkins that triggers the compilation with some other validations every day, but at non-commercial times.

As the project is very extensive and undergoes constant changes during the day, it is impossible to fire the Job of Jenkins for commit.

I would therefore like to know if it is possible to develop a code analysis component that validates the code during the build of the Delphi.

I did some research on how to make these validations at compile time. One of the options I found would be to extend the compiler Delphi. I found this guy but I saw he’s been down for a year.

I don’t know if that’s the only option, so I wonder if it’s possible to do it in other ways.

PS: What I need to do are some validations similar to CodeSmells of Sonar in the code during the compilation.

Ex.: Prevent manufacturers from being declared without inherited.

  • Zanella, give an example of the validation you need to do during the compilation, because we could solve it differently.

  • 1

    @David, the validations I need would be the ones that Sonar identifies as Code Smells, I just edited the question with one of them.

  • 1

    Ahhh understood, be more proactive than reactive ! Good, but do not know, let’s wait :)

  • Which version of Delphi ?

  • 1

    @David, 10 Seattle

2 answers

3

I will put as an answer because it did not fit in the comment.

Usually in java use Jenkins + Sonarqube (known as Sonar) for code evaluation in general.

A quick google search on Jenkins + Delphi can find 2 or 3 different plugins, all apparently stopped in their respective repositories ...

https://github.com/ahausladen/DLangExtensions

https://github.com/fabriciocolombo/sonar-delphi

we have a plugin also not continued that is mentioned in an old sonar documentation:

http://docs.sonarqube.org/display/SONARQUBE45/Delphi+Plugin

If you have your preferred code assessment tool, you could create a pre-build or post build task on Jenkins and call this your tool by command line. After evaluation, make an assertion of a certain metric to your liking (e.g., search in a text file generated by the tool for some variable).

Another alternative would be for you to write a sonar plugin.

  • The problem is that I wanted something that was triggered in the compilation of Delphi, and not an external plugin, where I pass to it my project, and it validates (Sonarqube).

2


You can use a static code analysis tool such as Pascal Expert/Pascal Analyzer of Peganza or the Fixinsight from TMS for example, to review your code before committing.

These tools can also be integrated via command line, into a Jenkins job, or into a build event in Delphi project settings, to review code after each commit or build respectively.

  • Hello, this TMS Fixinsight seems to do what I need, but only the Pro version. I’ll see if I can test it to see, but my intention is to create a tool of my own to do what TMS Fixinsight Pro does.

  • TMS Fixinsight Pro worked cool. Interestingly enough, it can perform a Unit validation. With this I can put a validation in the "before-commit". I’m going to test other free tools, even Sonar to see if I can do the same thing. If I can’t, I use that answer as valid.

  • It wasn’t quite what I wanted, but it was an alternative solution to my case. Thanks

  • @Victorzanella pays more to do the validation in the after build, because the compiler will always be faster to evaluate the code than any parser and, if there is an error in the source, it will do no good to analyze the code.

  • and can do this validation along with the build of the project?

  • Yes, just call put a command line, to run the tool, in the after build of the project settings.

  • Doing the revision by command, the result is spit into a file. Do you know if you can do this validation, and play the result in the "Messages" of Delphi ? (As if I were in: Project > Run Fixinsight)

  • Only to complement. There is no way to do internal validation with it, at compile-time per command line.

  • @Victorzanella has how to do before the compilation and I believe even after the compilation using OTA (Open Tools Api) of Delphi. Take a look at this http Autosave plugin://www.dummzeuch.de/Delphi/autosave/English.html on it we have the implementation using Onbeforecompile so you can run the parser before the compilation and depending on the resources that Fixinsight provides for reading its analysis output you can even show this in a custom dialog in the IDE.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.