jam-software / sonardelphi Goto Github PK
View Code? Open in Web Editor NEWThis project forked from mendrix/sonardelphi
This repository contains the source code to the Sonar-Delphi plugin. Can be used to analyse Delphi projects with SonarQube.
This project forked from mendrix/sonardelphi
This repository contains the source code to the Sonar-Delphi plugin. Can be used to analyse Delphi projects with SonarQube.
The plugin is producing two warnings regarding the rule set in the console output, which should be easily fixable.
17:22:37.582 INFO: Done
17:22:37.582 INFO: Sensor Combined LCOV and LOC sensor [delphi] (done) | time=9981ms
17:22:37.582 INFO: Sensor Delphi SurefireSensor [delphi]
17:22:37.582 INFO: Delphi sensor execute...
17:22:37.582 WARN: No Surefire reports directory found! Using default directory: target/surefire-reports
17:22:37.582 WARN: surefire report path not found F:\workspace\SB_trunk\target\surefire-reports
17:22:37.582 INFO: Sensor Delphi SurefireSensor [delphi] (done) | time=0ms
17:22:37.582 INFO: Sensor PMD sensor [delphi]
17:22:37.582 INFO: PMD sensor.execute
17:22:37.736 INFO: PMD configuration: F:\workspace\SB_trunk\.scannerwork\delph.xml
Nov 16, 2021 5:22:37 PM net.sourceforge.pmd.RuleSetFactory parseRuleSetNode
WARNING: RuleSet name is missing. Future versions of PMD will require it.
Nov 16, 2021 5:22:37 PM net.sourceforge.pmd.RuleSetFactory parseRuleSetNode
WARNING: RuleSet description is missing. Future versions of PMD will require it.
17:22:37.796 INFO: No include directories found in project configuration.
17:22:37.797 INFO: PMD Parsing project Default Project
17:22:37.797 INFO: 0% done...
17:22:38.227 INFO: 10% done...
I have a Code Smell "Unused argument: AMyUnusedParam at TFormTest.MyComponentMyEventImplementation" for the example below
procedure TFormTest.MyComponentMyEventImplementation(AMyUnusedParam: TSomeRandomType);
begin
inherited;
{*
Some code that doesn't use "AMyUnusedParam"
*}
end;
I think this rule should check if the method is a implementation of an event before mark the params as code smells.
Generally the code in events not necessarly need to use all the parameters as they exists only to comply with the event declaration.
Sonar 8.2
Scanner 4.2
Plugin 1.0.7
I Catch an error when I parse a unit that has undeclared CustomAttributes on it.
When the declaration and usage are in the same file the error does not occur.
Error details:
07:02:58.203 DEBUG: >> PARSING C:\Fontes\Delphi\SonarQube\DelphiProjectForSonar\CustonAtrib.View.SonarQube.pas
07:02:58.534 DEBUG: Error analyzing file: Analyzing class parents for no active class C:\Fontes\Delphi\SonarQube\DelphiProjectForSonar\CustonAtrib.View.SonarQube.pas
java.lang.IllegalStateException: Analyzing class parents for no active class
at org.sonar.plugins.delphi.antlr.analyzer.impl.TypeInheritanceAnalyzer.doAnalyze(TypeInheritanceAnalyzer.java:43)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:51)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:54)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:54)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:54)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:54)
at org.sonar.plugins.delphi.antlr.analyzer.CodeAnalyzer.analyze(CodeAnalyzer.java:54)
at org.sonar.plugins.delphi.antlr.analyzer.DelphiASTAnalyzer.analyze(DelphiASTAnalyzer.java:57)
at org.sonar.plugins.delphi.DelphiSensor.analyseSourceFile(DelphiSensor.java:308)
at org.sonar.plugins.delphi.DelphiSensor.parseSourceFile(DelphiSensor.java:278)
at org.sonar.plugins.delphi.DelphiSensor.parseFiles(DelphiSensor.java:257)
at org.sonar.plugins.delphi.DelphiSensor.execute(DelphiSensor.java:117)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Example project:
DelphiProjectForSonar
The CatchingGeneralExceptionRule
does not currently detect this situation
try
SomeMethode();
except
HandleException();
end;
http://docwiki.embarcadero.com/RADStudio/Sydney/en/Exceptions_(Delphi)
Currently it does not apply to published, but to public members and below.
Units that are flagged as deprecated or experimental should not be regarded and automatically excluded from analysis.
Grammar requires semicolon between member type and deprecated directive, but compiler not.
Covered by unit test in KeyWordsAsIdentifier.pas
.
TLockscreenVisibility = (Public, Private, Secret);
Very similar to #10.
Can you please upload the plugin in .jar format for download? I need to install it in Sonarqube helm chart which supports plugins in .jar format. Thanks in advance.
Often an empty method body is justified by a comment. In this case the EmptyBeginStatementRule
should not match.
The parser fails on this line of code:
s := {$ifdef CPUx64}'64'{$else}'32'{$endif};
Adding spaces serves as a workaround:
s := {$ifdef CPUx64} '64' {$else} '32' {$endif};
When running the plugin with Java > 8, it reports this warning:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/C:/Users/CIUser/.sonar/cache/a4ec2f3af08969606e86a41958fd4a7a/sonar-delphi-plugin.jar_unzip/META-INF/lib/xstream-1.4.11.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
By default, only the first access is printed. Therefore, there could be more problems.
With Java >= 16 the access is denied by default and the code probably fails.
It should be possible to suppress warnings in source code, like this can be done in C# using SuppressMessage
or #pragma warning
.
This code cannot be parsed:
for var i: Integer := 0 to 10 do
WriteLn(i);
When we use compilation directive it is understood that the block is empty.
procedure TFormPrincipal.FormCreate(Sender: TObject);
begin
{$IFDEF ANDROID}
PermissionsService.RequestPermissions([`
JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE),
JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE)],
nil, nil);
{$ENDIF}
end;
Currently, the plugin builds against the 7.9 API. SonarQube 8.0 removed some deprecated code, which is still used. This causes that the unit tests can no longer be build.
inherited class constructors are called anyway as part of the initialization section of their unit.
In case there are overloaded constructors it is common that one may call another which then calls inherited.
The same applies for the DestructorWithoutInheritedStatementRule
rule.
The type TTopBottom in this example causes parsing problems:
TVerticalAlignment = (taAlignTop, taAlignBottom, taVerticalCenter);
TTopBottom = TVerticalAlignment.taAlignTop..TVerticalAlignment.taAlignBottom;
Scan the following code with SonarDelphi:
unit RecordHelperTest;
interface
type
// This works
TSomeClass = class(TObject)
class var fSomeClassVar: ISomeInterface;
end;
// This doesn't
TSomeRecordHelper = record helper for xzy
class var fSomeClassVar: ISomeInterface;
end;
implementation
end.
Every Unit flagged as deprecated matches the "UnitNameRule"
Sample:
unit My.Test.Unit deprecated 'Should no longer be used!';
...
-> UnitNameRule matches, which is not reasonable in my opinion (False positive)
Currently all code in an $if statement is being removed. Propsed chnage: Inlcude code in $if but remove code in $else part, that would make code like this work:
const
cLength =
{$if CompilerVersion >= 22}
500;
{$else}
250;
{$ifend}
For example:
EEditionInsufficient = class(ENotSupportedException);
TStringList = class(TList<string>);
Hi,
More than a year ago I revitalized the SonarDelphi
project that had been inactive for too long and was not compatible anymore with the newest SonarQube. Now I see that you (JAM-Software / @joachimmarder) do a lot of development and that is really great to see!
I would like to invite you to combine efforts and move this project to a dedicated 'Organization' (eg. SonarDelphi
) so that we can centralize all effort. What do you think of this idea?
Best regards, Laurens
I have installed this plugin on my SonarQube Server and I am trying to analyze my Delphi code, but the SonarQube server not even detecting it. Is there some setting which I need to do in my ADO pipeline go get this working
I am using SonarQube 9.1 with the latest plugin version 1.0.7
When running the Code Analysis from Azure DevOps, I receive lots of errors on the console (see below).
Is there a way to get around these issues?
Kind regards, Harald
Output (extract):
##[error]$SOME-PATH$\uFunctions.IPC.pas line 47:2 mismatched input 'TIPCAsyncDataServer' expecting IMPLEMENTATION
$SOME-PATH$\uFunctions.IPC.pas line 47:2 mismatched input 'TIPCAsyncDataServer' expecting IMPLEMENTATION
##[error]$SOME-PATH$\uFunctions.IPC.pas line 78:5 mismatched input ';' expecting DOT
$SOME-PATH$\uFunctions.IPC.pas line 78:5 mismatched input ';' expecting DOT
##[error]ERROR: Error while parsing $SOME-PATH$\uFunctions.IPC.pas
INFO: 20% done...
INFO: 30% done...
INFO: 40% done...
##[error]$SOME-PATH$\Web.Win.Sockets.pas line 857:0 no viable alternative at input 'begin'
$SOME-PATH$\Web.Win.Sockets.pas line 857:0 no viable alternative at input 'begin'
##[error]$SOME-PATH$\Web.Win.Sockets.pas line 858:2 no viable alternative at input 'Result'
##[error]ERROR: Error while parsing $SOME-PATH$\Web.Win.Sockets.pas
ERROR: Error while parsing $SOME-PATH$\Web.Win.Sockets.pas
INFO: 50% done...
INFO: 60% done...
##[error]$SOME-PATH$\uConnection.Provider.pas line 196:2 no viable alternative at input 'TConnectionProviderSingleton'
$SOME-PATH$\uConnection.Provider.pas line 196:2 no viable alternative at input 'TConnectionProviderSingleton'
##[error]ERROR: Error while parsing $SOME-PATH$\uConnection.Provider.pas
ERROR: Error while parsing $SOME-PATH$\uConnection.Provider.pas
INFO: 70% done...
INFO: 80% done...
INFO: 90% done...
INFO: Done
INFO: Processing metrics...
INFO: 0% done...
##[error]$SOME-PATH$/uMessagesConst.pas line 4:20 no viable alternative at character '\'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.