@@ -159,18 +159,14 @@ type Runner interface {
159
159
// See the hclext.DecodeBody documentation and examples for more details.
160
160
DecodeRuleConfig (ruleName string , ret interface {}) error
161
161
162
- // EvaluateExpr evaluates the given expression and assigns the value to the Go value target.
163
- // The target must be a pointer. Otherwise, it will cause a panic.
162
+ // EvaluateExpr evaluates an expression and assigns its value to a Go value target,
163
+ // which must be a pointer or a function. Any other type of target will trigger a panic.
164
164
//
165
- // If the value cannot be assigned to the target, it returns an error.
166
- // There are particularly examples such as:
165
+ // For pointers, if the expression value cannot be assigned to the target, an error is returned.
166
+ // Some examples of this include unknown values (like variables without defaults or
167
+ // aws_instance.foo.arn), null values, and sensitive values (for variables with sensitive = true).
167
168
//
168
- // 1. Unknown value (e.g. variables without defaults, `aws_instance.foo.arn`)
169
- // 2. NULL
170
- // 3. Sensitive value (variables with `sensitive = true`)
171
- //
172
- // However, if the target is cty.Value, these errors will not be returned.
173
- // These errors can be handled with errors.Is().
169
+ // These errors be handled with errors.Is():
174
170
//
175
171
// ```
176
172
// var val string
@@ -192,29 +188,11 @@ type Runner interface {
192
188
// }
193
189
// ```
194
190
//
195
- // The following are the types that can be passed as the target:
196
- //
197
- // 1. string
198
- // 2. int
199
- // 3. []string
200
- // 4. []int
201
- // 5. map[string]string
202
- // 6. map[string]int
203
- // 7. cty.Value
204
- // 8. func (v T) error
205
- //
206
- // Passing any other type will cause a panic. If you pass a function, the assigned value
207
- // will be used as an argument to execute the function. In this case, if a value cannot be
208
- // assigned to the argument type, instead of returning an error, the execution is skipped.
209
- // This is useful when it is always acceptable to ignore exceptional values.
210
- //
211
- // ```
212
- // runner.EvaluateExpr(expr, func (val string) error {
213
- // // Test value
214
- // }, nil)
215
- // ```
191
+ // However, if the target is cty.Value, these errors will not be returned.
216
192
//
217
- // Besides this, you can pass a structure. In that case, you need to explicitly pass wantType.
193
+ // Here are the types that can be passed as the target: string, int, []string, []int,
194
+ // map[string]string, map[string]int, and cty.Value. Passing any other type will
195
+ // result in a panic, but you can make an exception by passing wantType as an option.
218
196
//
219
197
// ```
220
198
// type complexVal struct {
@@ -230,6 +208,19 @@ type Runner interface {
230
208
// var complexVals []complexVal
231
209
// runner.EvaluateExpr(expr, &compleVals, &tflint.EvaluateExprOption{WantType: &wantType})
232
210
// ```
211
+ //
212
+ // For functions (callbacks), the assigned value is used as an argument to execute
213
+ // the function. If a value cannot be assigned to the argument type, the execution
214
+ // is skipped instead of returning an error. This is useful when it's always acceptable
215
+ // to ignore exceptional values.
216
+ //
217
+ // Here's an example of how you can pass a function to EvaluateExpr:
218
+ //
219
+ // ```
220
+ // runner.EvaluateExpr(expr, func (val string) error {
221
+ // // Test value
222
+ // }, nil)
223
+ // ```
233
224
EvaluateExpr (expr hcl.Expression , target interface {}, option * EvaluateExprOption ) error
234
225
235
226
// EmitIssue sends an issue to TFLint. You need to pass the message of the issue and the range.
0 commit comments