Skip to content

Commit f4b2b0e

Browse files
cirrasfourls
authored andcommitted
Ignore empty anonymous methods in EmptyBlock
1 parent af9e715 commit f4b2b0e

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Library path (`DelphiLibraryPath`/`DelphiTranslatedLibraryPath`)
1919
- Browsing path (`DelphiBrowsingPath`)
2020
- Standard library
21+
- Empty anonymous methods are now ignored in `EmptyBlock`.
2122
- Empty anonymous methods are now flagged in `EmptyRoutine`.
2223
- **API:** `AnonymousMethodNode::getStatementBlock` method.
2324
- **API:** `AnonymousMethodNode::isEmpty` method.

delphi-checks/src/main/java/au/com/integradev/delphi/checks/EmptyBlockCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package au.com.integradev.delphi.checks;
2020

2121
import org.sonar.check.Rule;
22+
import org.sonar.plugins.communitydelphi.api.ast.AnonymousMethodNode;
2223
import org.sonar.plugins.communitydelphi.api.ast.CaseItemStatementNode;
2324
import org.sonar.plugins.communitydelphi.api.ast.CaseStatementNode;
2425
import org.sonar.plugins.communitydelphi.api.ast.CompoundStatementNode;
@@ -49,7 +50,7 @@ public DelphiCheckContext visit(CompoundStatementNode block, DelphiCheckContext
4950
private static boolean shouldAddViolation(CompoundStatementNode block) {
5051
DelphiNode parent = block.getParent();
5152

52-
if (parent instanceof RoutineBodyNode) {
53+
if (parent instanceof RoutineBodyNode || parent instanceof AnonymousMethodNode) {
5354
// Handled by EmptyRoutineRule
5455
return false;
5556
}

delphi-checks/src/test/java/au/com/integradev/delphi/checks/EmptyBlockCheckTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,24 @@ void testEmptyRoutineShouldNotAddIssue() {
157157
.appendImpl("end;"))
158158
.verifyNoIssues();
159159
}
160+
161+
@Test
162+
void testEmptyAnonymousMethodShouldNotAddIssue() {
163+
CheckVerifier.newVerifier()
164+
.withCheck(new EmptyBlockCheck())
165+
.onFile(
166+
new DelphiTestUnitBuilder()
167+
.appendDecl("type")
168+
.appendDecl(" TProc = reference to procedure;")
169+
.appendImpl("procedure Foo;")
170+
.appendImpl("var")
171+
.appendImpl(" Bar: TProc;")
172+
.appendImpl("begin")
173+
.appendImpl(" Bar :=")
174+
.appendImpl(" procedure")
175+
.appendImpl(" begin")
176+
.appendImpl(" end;")
177+
.appendImpl("end;"))
178+
.verifyNoIssues();
179+
}
160180
}

0 commit comments

Comments
 (0)