Skip to content

Commit 11dedbe

Browse files
committed
Exclude property call with object initializer r-value from DB quality query
1 parent b3896df commit 11dedbe

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

csharp/ql/src/Telemetry/DatabaseQuality.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ module CallTargetStats implements StatsSig {
6868
)
6969
}
7070

71-
private predicate isInitializedWithCollectionInitializer(PropertyCall c) {
71+
private predicate isInitializedWithObjectOrCollectionInitializer(PropertyCall c) {
7272
exists(Property p, AssignExpr assign |
7373
p = c.getProperty() and
7474
assign = c.getParent() and
7575
assign.getLValue() = c and
76-
assign.getRValue() instanceof CollectionInitializer
76+
assign.getRValue() instanceof ObjectOrCollectionInitializer
7777
)
7878
}
7979

@@ -94,7 +94,7 @@ module CallTargetStats implements StatsSig {
9494
not isNoSetterPropertyCallInConstructor(c) and
9595
not isNoSetterPropertyInitialization(c) and
9696
not isAnonymousObjectMemberDeclaration(c) and
97-
not isInitializedWithCollectionInitializer(c) and
97+
not isInitializedWithObjectOrCollectionInitializer(c) and
9898
not c.getParent+() instanceof NameOfExpr and
9999
not isEventFieldAccess(c) and
100100
not isTypeParameterInstantiation(c)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| Quality.cs:25:19:25:26 | access to indexer | Call without target $@. | Quality.cs:25:19:25:26 | access to indexer | access to indexer |
2-
| Quality.cs:28:21:28:27 | access to indexer | Call without target $@. | Quality.cs:28:21:28:27 | access to indexer | access to indexer |
3-
| Quality.cs:31:9:31:21 | access to indexer | Call without target $@. | Quality.cs:31:9:31:21 | access to indexer | access to indexer |
1+
| Quality.cs:26:19:26:26 | access to indexer | Call without target $@. | Quality.cs:26:19:26:26 | access to indexer | access to indexer |
2+
| Quality.cs:29:21:29:27 | access to indexer | Call without target $@. | Quality.cs:29:21:29:27 | access to indexer | access to indexer |
3+
| Quality.cs:32:9:32:21 | access to indexer | Call without target $@. | Quality.cs:32:9:32:21 | access to indexer | access to indexer |

csharp/ql/test/query-tests/Telemetry/DatabaseQuality/NoTarget.expected

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
| Quality.cs:15:24:15:34 | access to property MyProperty3 | Call without target $@. | Quality.cs:15:24:15:34 | access to property MyProperty3 | access to property MyProperty3 |
55
| Quality.cs:15:24:15:46 | access to property MyProperty2 | Call without target $@. | Quality.cs:15:24:15:46 | access to property MyProperty2 | access to property MyProperty2 |
66
| Quality.cs:19:13:19:23 | access to property MyProperty4 | Call without target $@. | Quality.cs:19:13:19:23 | access to property MyProperty4 | access to property MyProperty4 |
7-
| Quality.cs:22:9:22:14 | access to event Event1 | Call without target $@. | Quality.cs:22:9:22:14 | access to event Event1 | access to event Event1 |
8-
| Quality.cs:22:9:22:30 | delegate call | Call without target $@. | Quality.cs:22:9:22:30 | delegate call | delegate call |
9-
| Quality.cs:25:19:25:26 | access to indexer | Call without target $@. | Quality.cs:25:19:25:26 | access to indexer | access to indexer |
10-
| Quality.cs:28:21:28:27 | access to indexer | Call without target $@. | Quality.cs:28:21:28:27 | access to indexer | access to indexer |
11-
| Quality.cs:31:9:31:21 | access to indexer | Call without target $@. | Quality.cs:31:9:31:21 | access to indexer | access to indexer |
12-
| Quality.cs:35:16:35:26 | access to property MyProperty2 | Call without target $@. | Quality.cs:35:16:35:26 | access to property MyProperty2 | access to property MyProperty2 |
13-
| Quality.cs:46:20:46:26 | object creation of type T | Call without target $@. | Quality.cs:46:20:46:26 | object creation of type T | object creation of type T |
7+
| Quality.cs:20:13:20:23 | access to property MyProperty6 | Call without target $@. | Quality.cs:20:13:20:23 | access to property MyProperty6 | access to property MyProperty6 |
8+
| Quality.cs:23:9:23:14 | access to event Event1 | Call without target $@. | Quality.cs:23:9:23:14 | access to event Event1 | access to event Event1 |
9+
| Quality.cs:23:9:23:30 | delegate call | Call without target $@. | Quality.cs:23:9:23:30 | delegate call | delegate call |
10+
| Quality.cs:26:19:26:26 | access to indexer | Call without target $@. | Quality.cs:26:19:26:26 | access to indexer | access to indexer |
11+
| Quality.cs:29:21:29:27 | access to indexer | Call without target $@. | Quality.cs:29:21:29:27 | access to indexer | access to indexer |
12+
| Quality.cs:32:9:32:21 | access to indexer | Call without target $@. | Quality.cs:32:9:32:21 | access to indexer | access to indexer |
13+
| Quality.cs:36:16:36:26 | access to property MyProperty2 | Call without target $@. | Quality.cs:36:16:36:26 | access to property MyProperty2 | access to property MyProperty2 |
14+
| Quality.cs:48:20:48:26 | object creation of type T | Call without target $@. | Quality.cs:48:20:48:26 | object creation of type T | object creation of type T |

csharp/ql/test/query-tests/Telemetry/DatabaseQuality/Quality.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public Test()
1616

1717
new Test()
1818
{
19-
MyProperty4 = { 1, 2, 3 }
19+
MyProperty4 = { 1, 2, 3 },
20+
MyProperty6 = { [1] = "" }
2021
};
2122

2223
Event1.Invoke(this, 5);
@@ -36,6 +37,7 @@ public Test()
3637
public Test MyProperty3 { get; set; }
3738
public List<int> MyProperty4 { get; }
3839
static int MyProperty5 { get; }
40+
public Dictionary<int, string> MyProperty6 { get; }
3941

4042
public event EventHandler<int> Event1;
4143

0 commit comments

Comments
 (0)