Sorry, I should have been more clear. This is part of fpc.

So it's in gitlab:

https://gitlab.com/freepascal.org/fpc/source/-/tree/main/utils/fpsonar

The code compiles with FPC 3.2.2, though, I made sure of that. I'll see about making a zip with just the fcl-passrc/sonar units, and report back.

Michael.

On Thu, 9 Jul 2026, Tim Coates via fpc-pascal wrote:

Hi Michael,

Link please? I'd love to try it out.

Tim

On Thu, 9 July 2026, 6:22 am Michael Van Canneyt via fpc-pascal, <
[email protected]> wrote:


Hi,

I've finished something I have been brooding on for some months now:

FPSonar - a Object Pascal linter, written in Object Pascal

What does it do?

It has roughly 140-150 rules on how pascal code should be written to be
readable. It parses your code (using fcl-passrc) and will check all these
rules. It will then generate a report.

Examples of checks:

RoutineTooLarge - too long routines are flagged.

TooManyParameters - Procedure takes too many parameters.

TooManyNestedRoutines - too many local nested routines.

RemoveUnusedConstant - there is a constant that is never used.

FileNotTooManyClasses - too many classes in a file.

FormatArgumentType - wrong type for Format() argument.

LowercaseKeywords - keywords should be lowercase.

Some of these the compiler will flag (or the IDE code observer),
but most are not. There are many of them.

You can configure these checks (how long is too long, what is too many
parameters etc.) or disable checks altogether. The configuration file is a
JSON file.

You can also mark a line in code so it will not be checked:
  SomeCommand; // NOSONAR
The NOSONAR comment will suppress any warnings about that line.

The basic rule is: if the linter cannot determine with certainty that
something is wrong, it will not report it. For example, if it cannot with
certainty determine the type of a format argument, then no error/warning
will be reported about a type mismatch.

In order to do its job properly, it sometimes needs to know what the FPC
units
contain, and it automatically runs FPC's ppudump tool to find out - so it
does not need to parse the FPC code (although it can also do the latter).
In case you don't want that, you can let it simply use some built-in basic
copies of some essential FPC units (system, sysutils, classes).

To start using this tool on an old codebase can prove daunting - you can
start out with many 1000's of 'errors'. In order to help with that you can
make a baseline, a snapshot which you can compare against in subsequent
runs
so you at least don't make things worse. This gives you time to slowly fix
the existing issues while ensuring you don't add new ones.

I'm still working on a Lazarus IDE plugin.

In case you were wondering about the name: it's a reference to SonarQube,
a Java tool which does something similar (even for Pascal),
but is 1000 times harder to use than fpSonar.

If you find you're missing checks or have ideas for additional checks,
feel free to contact me. if they can be implemented, I will look at it.

Enjoy,

Michael.
_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to