Re: FpSonar - a pascal linter

Tim Coates via fpc-pascal <[email protected]> Thu, 9 Jul 2026 08:52:20 +1000
Newsgroups gmane.comp.compilers.free-pascal.general,gmane.comp.compilers.free-pascal.devel,gmane.comp.ide.lazarus.general
Message-ID <CAPGcr89VTY-zM2nGopmKiKmc9WW8TEgUBRc5ziGa21dBACXtmg@mail.gmail.com>
--===============0103361936013486969==
Content-Type: multipart/alternative; boundary="000000000000e203010656215c56"

--000000000000e203010656215c56
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Michael,

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

Tim

On Thu, 9 July 2026, 6:22=E2=80=AFam 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 basi=
c
> 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 ca=
n
> 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 fi=
x
> 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
>

--000000000000e203010656215c56
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Hi Michael,=C2=A0<div dir=3D"auto"><br></div><div dir=3D"=
auto">Link please? I&#39;d love to try it out.</div><div dir=3D"auto"><br><=
/div><div dir=3D"auto">Tim</div></div><br><div class=3D"gmail_quote gmail_q=
uote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, 9 July 2026, =
6:22=E2=80=AFam Michael Van Canneyt via fpc-pascal, &lt;<a href=3D"mailto:f=
[email protected]">[email protected]</a>&gt; wro=
te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><br>
Hi,<br>
<br>
I&#39;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<b=
r>
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>
=C2=A0 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<b=
r>
certainty determine the type of a format argument, then no error/warning <b=
r>
will be reported about a type mismatch.<br>
<br>
In order to do its job properly, it sometimes needs to know what the FPC un=
its<br>
contain, and it automatically runs FPC&#39;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&#39;t want that, you can let it simply use some built-in ba=
sic <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&#39;s of &#39;errors&#39;. In order to help with t=
hat you can<br>
make a baseline, a snapshot which you can compare against in subsequent run=
s<br>
so you at least don&#39;t make things worse. This gives you time to slowly =
fix<br>
the existing issues while ensuring you don&#39;t add new ones.<br>
<br>
I&#39;m still working on a Lazarus IDE plugin.<br>
<br>
In case you were wondering about the name: it&#39;s a reference to SonarQub=
e,<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&#39;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=C2=A0 -=C2=A0 <a href=3D"mailto:[email protected]=
scal.org" target=3D"_blank" rel=3D"noreferrer">fpc-pascal-PD4FTy7X32k2wBtHl531yeG/[email protected]=
org</a><br>
<a href=3D"https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal=
" rel=3D"noreferrer noreferrer" target=3D"_blank">https://lists.freepascal.=
org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</blockquote></div>

--000000000000e203010656215c56--

--===============0103361936013486969==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============0103361936013486969==--