<div dir="auto">Hi Michael, <div dir="auto"><br></div><div dir="auto">Link please? I'd love to try it out.</div><div dir="auto"><br></div><div dir="auto">Tim</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, 9 July 2026, 6:22 am Michael Van Canneyt via fpc-pascal, <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
I've finished something I have been brooding on for some months now:<br>
<br>
FPSonar - a Object Pascal linter, written in Object Pascal<br>
<br>
What does it do?<br>
<br>
It has roughly 140-150 rules on how pascal code should be written to be<br>
readable. It parses your code (using fcl-passrc) and will check all these<br>
rules. It will then generate a report.<br>
<br>
Examples of checks:<br>
<br>
RoutineTooLarge - too long routines are flagged.<br>
<br>
TooManyParameters - Procedure takes too many parameters.<br>
<br>
TooManyNestedRoutines - too many local nested routines.<br>
<br>
RemoveUnusedConstant - there is a constant that is never used.<br>
<br>
FileNotTooManyClasses - too many classes in a file.<br>
<br>
FormatArgumentType - wrong type for Format() argument.<br>
<br>
LowercaseKeywords - keywords should be lowercase.<br>
<br>
Some of these the compiler will flag (or the IDE code observer), <br>
but most are not. There are many of them.<br>
<br>
You can configure these checks (how long is too long, what is too many<br>
parameters etc.) or disable checks altogether. The configuration file is a<br>
JSON file.<br>
<br>
You can also mark a line in code so it will not be checked:<br>
  SomeCommand; // NOSONAR<br>
The NOSONAR comment will suppress any warnings about that line.<br>
<br>
The basic rule is: if the linter cannot determine with certainty that<br>
something is wrong, it will not report it. For example, if it cannot with<br>
certainty determine the type of a format argument, then no error/warning <br>
will be reported about a type mismatch.<br>
<br>
In order to do its job properly, it sometimes needs to know what the FPC units<br>
contain, and it automatically runs FPC's ppudump tool to find out - so it<br>
does not need to parse the FPC code (although it can also do the latter). <br>
In case you don't want that, you can let it simply use some built-in basic <br>
copies of some essential FPC units (system, sysutils, classes).<br>
<br>
To start using this tool on an old codebase can prove daunting - you can<br>
start out with many 1000's of 'errors'. In order to help with that you can<br>
make a baseline, a snapshot which you can compare against in subsequent runs<br>
so you at least don't make things worse. This gives you time to slowly fix<br>
the existing issues while ensuring you don't add new ones.<br>
<br>
I'm still working on a Lazarus IDE plugin.<br>
<br>
In case you were wondering about the name: it's a reference to SonarQube,<br>
a Java tool which does something similar (even for Pascal), <br>
but is 1000 times harder to use than fpSonar.<br>
<br>
If you find you're missing checks or have ideas for additional checks, <br>
feel free to contact me. if they can be implemented, I will look at it.<br>
<br>
Enjoy,<br>
<br>
Michael.<br>
_______________________________________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a><br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer noreferrer" target="_blank">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div>