-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Receiving plenty of errors while parsing code #20
Comments
Can you supply a sample file? Ideally a small one. And does the unit contain conditional code like |
Below you would find some code to reproduce the issue. There are no conditionals in that file, however, there are "old-style" comments in the file. {*******************************************************************************
* Class validates the XML against the XSD. You should ensure that CoInitialize
* is called in your app before you access the methods below.
* @path \trunc\00_CommonGlobal\02_Functions\uXMLValidator.pas
* @author XYZ
* @author Copyright © 2021 by ...
* @date 27/03/13 19:12:04
* @remarks
*******************************************************************************}
unit uXMLValidator;
interface
uses
System.Classes;
type
XMLValidator = class
public
class function IsValidXML(AXML: String; ASchemaDir: String): Boolean; overload; static;
class function IsValidXML(AXMLFile: String): Boolean; overload; static;
class function IsValidXML(AStream: TStream; ASchemaDir: String): Boolean; overload; static;
end;
implementation
uses
System.SysUtils, Xml.xmldom, Xml.Win.msxmldom, uFunctions.Files;
function IsValidXMLInternal(AStream: TStream; AText: String; ASchemaDir: String): Boolean;
var
doc: IDOMPersist;
ParseOpt: IDOMParseOptions;
OldDir: String;
begin
if ASchemaDir <> '' then
begin
OldDir := GetCurrentDir;
ChDir(ASchemaDir);
end
else
OldDir := '';
Result := False;
try
doc := MSXML_DOM.DOMImplementation.createDocument('', '', nil) as IDOMPersist;
if doc.QueryInterface(IDOMParseOptions, ParseOpt) = 0 then
begin
ParseOpt.async := False;
ParseOpt.resolveExternals := True;
ParseOpt.validate := True;
if AStream = nil then
Result := doc.loadxml(AText)
else
Result := doc.loadFromStream(AStream);
end
finally
if ASchemaDir <> '' then
ChDir(OldDir);
end;
end;
class function XMLValidator.IsValidXML(AXML: String; ASchemaDir: String): Boolean;
begin
Result := IsValidXMLInternal(nil, AXML, ASchemaDir)
end;
class function XMLValidator.IsValidXML(AStream: TStream; ASchemaDir: String): Boolean;
begin
Result := IsValidXMLInternal(AStream, '', ASchemaDir)
end;
class function XMLValidator.IsValidXML(AXMLFile: String): Boolean;
var
s: String;
begin
FileUtils.FileToString(s, AXMLFile);
Result := IsValidXMLInternal(nil, s, ExtractFilePath(AXMLFile));
end;
end.
|
Test.zip
I don't think they are a problem, but does the problem disappear if you remove those comments? |
Thank you for your answer. Then maybe it is about the integration of the plugin with Azure DevOps and the SonarScanner used to perform the analysis. Which part is actually generating the error-messages on the DevOps console log? |
I'm not sure, I forked the project to fix some issues in the Antlr grammar definiton of Obejct Pascal. And I don't use Azure DevOps. What is the exact error message that is generated for this sample file on your system? |
I did now update our Azure DevOps Server to 2020.1 and also updated SonarQube to 9.1 with a new SonarScanner version for DevOps - now the task "Run Code Analysis" is in version 5.0.0. Analysis goes through smooth, however still showing the same issues in the output.
Not sure if it is about the grammar or some other issues are triggering these messages. It basically still is fine, we just get a lot of false-positives on the analysis, which kinda sucks. |
Well, it seems that some part of SonarQube has issues with the backslashes in the comments on top of the file. Just to be sure: Do the errors disappear if you remove the line with backslashes?
Do you mean, SonarDelphi rules apply when they shouldn't? Do you have an example? |
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):
The text was updated successfully, but these errors were encountered: