Skip to content

Commit 0d5f5e2

Browse files
committed
Exclude types annotated with attributes in UnusedType
1 parent ae21dc4 commit 0d5f5e2

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Exclude types annotated with attributes in `UnusedType`.
13+
1014
### Fixed
1115

1216
- Exceptions from empty structures (e.g., `if`) in `LoopExecutingAtMostOnce` and `RedundantJump`.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ private boolean isViolation(TypeDeclarationNode node) {
6969
return false;
7070
}
7171

72+
if (node.getAttributeList() != null) {
73+
return false;
74+
}
75+
7276
return node.getTypeNameNode().getUsages().stream()
7377
.allMatch(occurrence -> isWithinType(occurrence, type));
7478
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,17 @@ void testUnusedImplementationTypeWithExcludeApiShouldAddIssue() {
199199
.appendImpl("end;"))
200200
.verifyIssues();
201201
}
202+
203+
@Test
204+
void testUnusedTypeWithAttributeShouldNotAddIssue() {
205+
CheckVerifier.newVerifier()
206+
.withCheck(new UnusedTypeCheck())
207+
.onFile(
208+
new DelphiTestUnitBuilder()
209+
.appendDecl("type")
210+
.appendDecl(" [Bar]")
211+
.appendDecl(" TFoo = class")
212+
.appendDecl(" end;"))
213+
.verifyNoIssues();
214+
}
202215
}

0 commit comments

Comments
 (0)