-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
291 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
delphi-checks/src/main/java/au/com/integradev/delphi/checks/FormFmxCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Sonar Delphi Plugin | ||
* Copyright (C) 2024 Integrated Application Development | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package au.com.integradev.delphi.checks; | ||
|
||
import org.sonar.check.Rule; | ||
|
||
@Rule(key = "FormFmx") | ||
public class FormFmxCheck extends AbstractFormResourceCheck { | ||
@Override | ||
protected String getFrameworkName() { | ||
return "FireMonkey"; | ||
} | ||
|
||
@Override | ||
protected String getFormTypeImage() { | ||
return "FMX.Forms.TForm"; | ||
} | ||
|
||
@Override | ||
protected String getFrameTypeImage() { | ||
return "FMX.Forms.TFrame"; | ||
} | ||
|
||
@Override | ||
protected String getResourceFileExtension() { | ||
return "fmx"; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
delphi-checks/src/main/resources/org/sonar/l10n/delphi/rules/community-delphi/FormFmx.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p> | ||
Omitting the corresponding <code>.fmx</code> resource for a FireMonkey form or frame is typically | ||
a programming error. While there are some cases that won't cause problems at runtime, it remains | ||
unintuitive and confusing. | ||
</p> | ||
<p> | ||
Additionally, a unit that doesn't contain a <code>.fmx</code> resource will lack design-time form | ||
editing functionality. | ||
</p> | ||
<p> | ||
This rule flags any <code>TForm</code> or <code>TFrame</code> descendant in a unit that doesn't | ||
include a <code>.fmx</code> resource. | ||
</p> | ||
<h2>How to fix it</h2> | ||
<p>Add a <code>.fmx</code> resource to the unit:</p> | ||
<pre data-diff-id="1" data-diff-type="noncompliant"> | ||
unit Foo; | ||
|
||
interface | ||
|
||
uses | ||
FMX.Forms; | ||
|
||
type | ||
TFoo = class(TForm) | ||
// ... | ||
end; | ||
|
||
implementation | ||
|
||
end. | ||
</pre> | ||
<pre data-diff-id="1" data-diff-type="compliant"> | ||
unit Foo; | ||
|
||
interface | ||
|
||
uses | ||
FMX.Forms; | ||
|
||
type | ||
TFoo = class(TForm) | ||
// ... | ||
end; | ||
|
||
implementation | ||
|
||
{$R *.fmx} | ||
|
||
end. | ||
</pre> |
19 changes: 19 additions & 0 deletions
19
delphi-checks/src/main/resources/org/sonar/l10n/delphi/rules/community-delphi/FormFmx.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"title": "FireMonkey forms and frames should have a corresponding .fmx form file", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"code": { | ||
"attribute": "COMPLETE", | ||
"impacts": { | ||
"MAINTAINABILITY": "MEDIUM" | ||
} | ||
}, | ||
"tags": ["bad-practice", "confusing"], | ||
"defaultSeverity": "Major", | ||
"scope": "ALL", | ||
"quickfix": "unknown" | ||
} |
174 changes: 174 additions & 0 deletions
174
delphi-checks/src/test/java/au/com/integradev/delphi/checks/FormFmxCheckTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Sonar Delphi Plugin | ||
* Copyright (C) 2024 Integrated Application Development | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 | ||
*/ | ||
package au.com.integradev.delphi.checks; | ||
|
||
import au.com.integradev.delphi.builders.DelphiTestUnitBuilder; | ||
import au.com.integradev.delphi.checks.verifier.CheckVerifier; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FormFmxCheckTest { | ||
@Test | ||
void testNormalClassWithoutFmxShouldNotAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TObject)") | ||
.appendDecl(" end;")) | ||
.verifyNoIssues(); | ||
} | ||
|
||
@Test | ||
void testAliasesWithoutFmxShouldNotAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFormWeakAlias = TForm;") | ||
.appendDecl(" TFrameWeakAlias = TFrame;") | ||
.appendDecl(" TFormStrongAlias = type TForm;") | ||
.appendDecl(" TFrameStrongAlias = type TFrame;")) | ||
.verifyNoIssues(); | ||
} | ||
|
||
@Test | ||
void testFormWithFmxShouldNotAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TForm)") | ||
.appendDecl(" end;") | ||
.appendImpl("{$R Foo.fmx}")) | ||
.verifyNoIssues(); | ||
} | ||
|
||
@Test | ||
void testFrameWithFmxShouldNotAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TFrame)") | ||
.appendDecl(" end;") | ||
.appendImpl("{$R Foo.fmx}")) | ||
.verifyNoIssues(); | ||
} | ||
|
||
@Test | ||
void testFormWithoutFmxShouldAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TForm) // Noncompliant") | ||
.appendDecl(" end;")) | ||
.verifyIssues(); | ||
} | ||
|
||
@Test | ||
void testFrameWithoutFmxShouldAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TFrame) // Noncompliant") | ||
.appendDecl(" end;")) | ||
.verifyIssues(); | ||
} | ||
|
||
@Test | ||
void testNonFmxResourceShouldAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TForm) // Noncompliant") | ||
.appendDecl(" end;") | ||
.appendImpl("{$R Foo.bar}")) | ||
.verifyIssues(); | ||
} | ||
|
||
@Test | ||
void testNonFmxResourceContainingDotFmxShouldAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TForm) // Noncompliant") | ||
.appendDecl(" end;") | ||
.appendImpl("{$R Foo.fmx.bar}")) | ||
.verifyIssues(); | ||
} | ||
|
||
@Test | ||
void testIncludeFmxShouldAddIssue() { | ||
CheckVerifier.newVerifier() | ||
.withCheck(new FormFmxCheck()) | ||
.withSearchPathUnit(createFmxForms()) | ||
.onFile( | ||
new DelphiTestUnitBuilder() | ||
.appendDecl("uses") | ||
.appendDecl(" FMX.Forms;") | ||
.appendDecl("type") | ||
.appendDecl(" TFoo = class(TForm) // Noncompliant") | ||
.appendDecl(" end;") | ||
.appendImpl("{$I Foo.fmx}")) | ||
.verifyIssues(); | ||
} | ||
|
||
private static DelphiTestUnitBuilder createFmxForms() { | ||
return new DelphiTestUnitBuilder() | ||
.unitName("FMX.Forms") | ||
.appendDecl("type") | ||
.appendDecl(" TForm = class") | ||
.appendDecl(" end;") | ||
.appendDecl(" TFrame = class") | ||
.appendDecl(" end;"); | ||
} | ||
} |