From michael at freepascal.org  Wed Jul  8 22:14:06 2026
From: michael at freepascal.org (Michael Van Canneyt)
Date: Wed, 8 Jul 2026 22:14:06 +0200 (CEST)
Subject: [fpc-pascal] FpSonar - a pascal linter
Message-ID: <d98f2234-9fc3-e483-8333-c7872aa28061@freepascal.org>


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.

From timcoates.solutions at gmail.com  Thu Jul  9 00:52:20 2026
From: timcoates.solutions at gmail.com (Tim Coates)
Date: Thu, 9 Jul 2026 08:52:20 +1000
Subject: [fpc-pascal] FpSonar - a pascal linter
In-Reply-To: <d98f2234-9fc3-e483-8333-c7872aa28061@freepascal.org>
References: <d98f2234-9fc3-e483-8333-c7872aa28061@freepascal.org>
Message-ID: <CAPGcr89VTY-zM2nGopmKiKmc9WW8TEgUBRc5ziGa21dBACXtmg@mail.gmail.com>

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, <
fpc-pascal at lists.freepascal.org> 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  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20260709/9a7f7729/attachment.htm>

From michael at freepascal.org  Thu Jul  9 08:41:24 2026
From: michael at freepascal.org (Michael Van Canneyt)
Date: Thu, 9 Jul 2026 08:41:24 +0200 (CEST)
Subject: [fpc-pascal] FpSonar - a pascal linter
In-Reply-To: <CAPGcr89VTY-zM2nGopmKiKmc9WW8TEgUBRc5ziGa21dBACXtmg@mail.gmail.com>
References: <d98f2234-9fc3-e483-8333-c7872aa28061@freepascal.org>
 <CAPGcr89VTY-zM2nGopmKiKmc9WW8TEgUBRc5ziGa21dBACXtmg@mail.gmail.com>
Message-ID: <418d90af-1005-528f-fff0-07edf9417678@freepascal.org>


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, <
> fpc-pascal at lists.freepascal.org> 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  -  fpc-pascal at lists.freepascal.org
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>>
>

