Colobot Forum - International Colobot Community
Introducing colobot-lint - Printable Version

+- Colobot Forum - International Colobot Community (https://colobot.info/forum)
+-- Forum: [Archive] New forum (2015-2019) (https://colobot.info/forum/forumdisplay.php?fid=76)
+--- Forum: Colobot: Gold Edition Development (https://colobot.info/forum/forumdisplay.php?fid=62)
+---- Forum: Game Engine & General Talk (https://colobot.info/forum/forumdisplay.php?fid=63)
+---- Thread: Introducing colobot-lint (/showthread.php?tid=643)



Introducing colobot-lint - piotrdz - 08-27-2015

For the last two weeks, I've been working on a static analysis tool based on Clang's libtooling that would help us in refactoring Colobot code. The project, which I named colobot-lint, is now pretty much complete in how I envisioned it, and stable enough, so the time has come to officially introduce it.

Colobot-lint uses Clang's extensive API to perform a range of checks on C++ code, compiled to AST (abstract syntax tree). Based on information contained in AST and associated contextual data, it can detect things such as:
 - uninitialized local variables
 - uninitialized fields in structs/classes
 - uses of new/delete operators
 - functions written in legacy C style (variable declarations only at the beginning of function)
 - occurences of TODO comments
 - style checks (variable/function/class naming, etc.)

Project repository is here: https://github.com/piotrdz/colobot-lint
Full list of checks performed is documented here: https://github.com/piotrdz/colobot-lint/blob/master/RULES.md

For the time being, I have set up my own Jenkins CI server at http://piotrdz.pl:9000/ with jobs running colobot-lint on current Colobot code (dev branch). Later, we can move these jobs to our main Jenkins server.

There are two jobs listed in Main page:
 - colobot-lint-build builds colobot-lint tool itself
 - colobot-lint-run runs colobot-lint on latest dev branch of Colobot

The results are visualized using cppcheck plugin in a form of graph (http://piotrdz.pl:9000/job/colobot-lint-run/) and list of issues (http://piotrdz.pl:9000/job/colobot-lint-run/15/cppcheckResult/). You can click on link in "Line" column to see source code location, for example: http://piotrdz.pl:9000/job/colobot-lint-run/15/cppcheckResult/source.1030/#48

As you can see, there is currently quite a lot of detected issues, but the point is not to fix them all at once. Instead, as in every refactoring effort, we should try to lower the number of issues step by step, and not introduce new issues. Each issue is also marked with category like error, warning or style, based on what I felt are most important issues.

Some improvements are still needed, for example better way to display results, as the Jenkins cppcheck plugin is quite limited. I've listed some ideas for improvement as issues here: https://github.com/piotrdz/colobot-lint/issues. You are welcome to report any bugs or your propositions for improvements.

Update:
Now I think the tool can be safely described as finished, at least unless we find more rules to add to it.

For some time now, the tool has been running on our main Jenkins server: http://compiled.colobot.info/jenkins/job/colobot-lint-run/. My old server now serves as slave to run the colobot-lint jobs.

I also moved the repository on github from my account to our organization: https://github.com/colobot/colobot-lint, as I think it should be included there along with other tools that we have developed.