Skip to content

Commit d73fa0e

Browse files
committed
feat(ast): Add new predicates for string handling and if conditions
1 parent ed93d56 commit d73fa0e

File tree

3 files changed

+175
-0
lines changed

3 files changed

+175
-0
lines changed

ql/test/library-tests/ast/AST.expected

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1+
ast
2+
| conditions.bicep:1:1:1:39 | ParameterDeclaration |
3+
| conditions.bicep:1:1:1:39 | ParameterDeclaration |
4+
| conditions.bicep:1:1:1:39 | ParameterDeclaration |
5+
| conditions.bicep:1:1:12:2 | Infrastructure |
6+
| conditions.bicep:1:7:1:26 | enableStorageAccount |
7+
| conditions.bicep:1:7:1:26 | enableStorageAccount |
8+
| conditions.bicep:1:7:1:26 | enableStorageAccount |
9+
| conditions.bicep:1:28:1:31 | Type |
10+
| conditions.bicep:1:28:1:31 | bool |
11+
| conditions.bicep:1:35:1:39 | false |
12+
| conditions.bicep:1:35:1:39 | false |
13+
| conditions.bicep:1:35:1:39 | false |
14+
| conditions.bicep:2:1:2:54 | ParameterDeclaration |
15+
| conditions.bicep:2:1:2:54 | ParameterDeclaration |
16+
| conditions.bicep:2:1:2:54 | ParameterDeclaration |
17+
| conditions.bicep:2:7:2:24 | storageAccountName |
18+
| conditions.bicep:2:7:2:24 | storageAccountName |
19+
| conditions.bicep:2:7:2:24 | storageAccountName |
20+
| conditions.bicep:2:26:2:31 | Type |
21+
| conditions.bicep:2:26:2:31 | string |
22+
| conditions.bicep:2:35:2:54 | String |
23+
| conditions.bicep:2:35:2:54 | String |
24+
| conditions.bicep:2:35:2:54 | String |
25+
| conditions.bicep:2:36:2:53 | examplestorageacct |
26+
| conditions.bicep:4:1:12:1 | ResourceDeclaration |
27+
| conditions.bicep:4:1:12:1 | ResourceDeclaration |
28+
| conditions.bicep:4:1:12:1 | ResourceDeclaration |
29+
| conditions.bicep:4:10:4:23 | storageAccount |
30+
| conditions.bicep:4:10:4:23 | storageAccount |
31+
| conditions.bicep:4:10:4:23 | storageAccount |
32+
| conditions.bicep:4:25:4:70 | String |
33+
| conditions.bicep:4:25:4:70 | String |
34+
| conditions.bicep:4:25:4:70 | String |
35+
| conditions.bicep:4:26:4:69 | Microsoft.Storage/storageAccounts@2022-09-01 |
36+
| conditions.bicep:4:74:12:1 | IfStatement |
37+
| conditions.bicep:4:77:4:98 | ParenthesizedExpression |
38+
| conditions.bicep:4:77:4:98 | ParenthesizedExpression |
39+
| conditions.bicep:4:77:4:98 | ParenthesizedExpression |
40+
| conditions.bicep:4:78:4:97 | enableStorageAccount |
41+
| conditions.bicep:4:78:4:97 | enableStorageAccount |
42+
| conditions.bicep:4:78:4:97 | enableStorageAccount |
43+
| conditions.bicep:4:100:12:1 | Object |
44+
| conditions.bicep:4:100:12:1 | Object |
45+
| conditions.bicep:4:100:12:1 | Object |
46+
| conditions.bicep:5:3:5:6 | name |
47+
| conditions.bicep:5:3:5:6 | name |
48+
| conditions.bicep:5:3:5:6 | name |
49+
| conditions.bicep:5:3:5:26 | ObjectProperty |
50+
| conditions.bicep:5:9:5:26 | storageAccountName |
51+
| conditions.bicep:5:9:5:26 | storageAccountName |
52+
| conditions.bicep:5:9:5:26 | storageAccountName |
53+
| conditions.bicep:6:3:6:10 | location |
54+
| conditions.bicep:6:3:6:10 | location |
55+
| conditions.bicep:6:3:6:10 | location |
56+
| conditions.bicep:6:3:6:36 | ObjectProperty |
57+
| conditions.bicep:6:13:6:25 | resourceGroup |
58+
| conditions.bicep:6:13:6:25 | resourceGroup |
59+
| conditions.bicep:6:13:6:25 | resourceGroup |
60+
| conditions.bicep:6:13:6:27 | CallExpression |
61+
| conditions.bicep:6:13:6:27 | CallExpression |
62+
| conditions.bicep:6:13:6:27 | CallExpression |
63+
| conditions.bicep:6:13:6:36 | MemberExpression |
64+
| conditions.bicep:6:13:6:36 | MemberExpression |
65+
| conditions.bicep:6:13:6:36 | MemberExpression |
66+
| conditions.bicep:6:26:6:27 | Arguments |
67+
| conditions.bicep:6:29:6:36 | location |
68+
| conditions.bicep:7:3:7:5 | sku |
69+
| conditions.bicep:7:3:7:5 | sku |
70+
| conditions.bicep:7:3:7:5 | sku |
71+
| conditions.bicep:7:3:9:3 | ObjectProperty |
72+
| conditions.bicep:7:8:9:3 | Object |
73+
| conditions.bicep:7:8:9:3 | Object |
74+
| conditions.bicep:7:8:9:3 | Object |
75+
| conditions.bicep:8:5:8:8 | name |
76+
| conditions.bicep:8:5:8:8 | name |
77+
| conditions.bicep:8:5:8:8 | name |
78+
| conditions.bicep:8:5:8:24 | ObjectProperty |
79+
| conditions.bicep:8:11:8:24 | String |
80+
| conditions.bicep:8:11:8:24 | String |
81+
| conditions.bicep:8:11:8:24 | String |
82+
| conditions.bicep:8:12:8:23 | Standard_LRS |
83+
| conditions.bicep:10:3:10:6 | kind |
84+
| conditions.bicep:10:3:10:6 | kind |
85+
| conditions.bicep:10:3:10:6 | kind |
86+
| conditions.bicep:10:3:10:19 | ObjectProperty |
87+
| conditions.bicep:10:9:10:19 | String |
88+
| conditions.bicep:10:9:10:19 | String |
89+
| conditions.bicep:10:9:10:19 | String |
90+
| conditions.bicep:10:10:10:18 | StorageV2 |
91+
| conditions.bicep:11:3:11:12 | properties |
92+
| conditions.bicep:11:3:11:12 | properties |
93+
| conditions.bicep:11:3:11:12 | properties |
94+
| conditions.bicep:11:3:11:16 | ObjectProperty |
95+
| conditions.bicep:11:15:11:16 | Object |
96+
| conditions.bicep:11:15:11:16 | Object |
97+
| conditions.bicep:11:15:11:16 | Object |
198
| data.bicep:1:1:1:10 | Comment |
299
| data.bicep:1:1:62:4 | Infrastructure |
3100
| data.bicep:2:1:6:1 | VariableDeclaration |
@@ -1013,3 +1110,62 @@
10131110
| sample.bicep:98:15:98:20 | MemberExpression |
10141111
| sample.bicep:98:15:98:20 | MemberExpression |
10151112
| sample.bicep:98:19:98:20 | id |
1113+
strings
1114+
| conditions.bicep:2:35:2:54 | String | examplestorageacct |
1115+
| conditions.bicep:4:25:4:70 | String | Microsoft.Storage/storageAccounts@2022-09-01 |
1116+
| conditions.bicep:8:11:8:24 | String | Standard_LRS |
1117+
| conditions.bicep:10:9:10:19 | String | StorageV2 |
1118+
| data.bicep:3:3:3:7 | String | abc |
1119+
| data.bicep:4:3:4:7 | String | def |
1120+
| data.bicep:5:3:5:7 | String | ghi |
1121+
| data.bicep:8:24:8:28 | String | abc |
1122+
| data.bicep:8:31:8:35 | String | def |
1123+
| data.bicep:8:38:8:42 | String | ghi |
1124+
| data.bicep:10:19:10:23 | String | abc |
1125+
| data.bicep:10:26:10:30 | String | def |
1126+
| data.bicep:11:5:11:9 | String | ghi |
1127+
| data.bicep:27:40:27:50 | String | test name |
1128+
| data.bicep:27:57:27:65 | String | 123-abc |
1129+
| data.bicep:30:9:30:19 | String | test name |
1130+
| data.bicep:31:7:31:15 | String | 123-abc |
1131+
| data.bicep:36:35:36:45 | String | test name |
1132+
| data.bicep:36:52:36:60 | String | 123-abc |
1133+
| data.bicep:41:13:41:25 | String | whats up? |
1134+
| data.bicep:42:18:42:24 | String | north |
1135+
| data.bicep:42:28:42:34 | String | south |
1136+
| data.bicep:42:38:42:43 | String | east |
1137+
| data.bicep:42:47:42:52 | String | west |
1138+
| data.bicep:43:19:43:62 | String | storage${CallExpression} |
1139+
| data.bicep:46:13:46:24 | String | hello! |
1140+
| data.bicep:49:14:50:9 | String | \nhello! |
1141+
| data.bicep:53:14:55:3 | String | \nhello!\n |
1142+
| data.bicep:58:14:62:3 | String | \n this\n is\n indented\n |
1143+
| sample.bicep:2:35:2:80 | String | toylaunch${CallExpression} |
1144+
| sample.bicep:3:23:3:28 | String | myVM |
1145+
| sample.bicep:4:30:4:40 | String | azureuser |
1146+
| sample.bicep:5:30:5:43 | String | P@ssw0rd123! |
1147+
| sample.bicep:6:25:6:32 | String | myVnet |
1148+
| sample.bicep:7:27:7:36 | String | mySubnet |
1149+
| sample.bicep:8:29:8:40 | String | myPublicIP |
1150+
| sample.bicep:9:24:9:30 | String | myNIC |
1151+
| sample.bicep:11:25:11:70 | String | Microsoft.Storage/storageAccounts@2021-06-01 |
1152+
| sample.bicep:15:11:15:24 | String | Standard_LRS |
1153+
| sample.bicep:17:9:17:19 | String | StorageV2 |
1154+
| sample.bicep:19:17:19:21 | String | Hot |
1155+
| sample.bicep:23:15:23:60 | String | Microsoft.Network/virtualNetworks@2021-05-01 |
1156+
| sample.bicep:29:9:29:21 | String | 10.0.0.0/16 |
1157+
| sample.bicep:36:26:36:38 | String | 10.0.0.0/24 |
1158+
| sample.bicep:43:19:43:66 | String | Microsoft.Network/publicIPAddresses@2021-05-01 |
1159+
| sample.bicep:47:31:47:39 | String | Dynamic |
1160+
| sample.bicep:51:14:51:61 | String | Microsoft.Network/networkInterfaces@2021-05-01 |
1161+
| sample.bicep:57:15:57:25 | String | ipconfig1 |
1162+
| sample.bicep:62:38:62:46 | String | Dynamic |
1163+
| sample.bicep:72:13:72:58 | String | Microsoft.Compute/virtualMachines@2021-07-01 |
1164+
| sample.bicep:77:15:77:31 | String | Standard_DS1_v2 |
1165+
| sample.bicep:86:20:86:30 | String | Canonical |
1166+
| sample.bicep:87:16:87:29 | String | UbuntuServer |
1167+
| sample.bicep:88:14:88:24 | String | 18.04-LTS |
1168+
| sample.bicep:89:18:89:25 | String | latest |
1169+
| sample.bicep:92:23:92:33 | String | FromImage |
1170+
ifCondition
1171+
| conditions.bicep:4:74:12:1 | IfStatement | conditions.bicep:4:77:4:98 | ParenthesizedExpression | conditions.bicep:4:100:12:1 | Object |

ql/test/library-tests/ast/AST.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
private import bicep
22

33
query predicate ast(AstNode ast) { any() }
4+
5+
query predicate strings(String str, string output) { output = str.getValue() }
6+
7+
query predicate ifCondition(IfStatement ifStmt, Expr condition, Expr body) {
8+
ifStmt.getCondition() = condition and
9+
ifStmt.getBody() = body
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
param enableStorageAccount bool = false
2+
param storageAccountName string = 'examplestorageacct'
3+
4+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = if (enableStorageAccount) {
5+
name: storageAccountName
6+
location: resourceGroup().location
7+
sku: {
8+
name: 'Standard_LRS'
9+
}
10+
kind: 'StorageV2'
11+
properties: {}
12+
}

0 commit comments

Comments
 (0)