func checkNullableValue()

in interfaces/interface_variable.go [153:178]


func checkNullableValue(vcr *InterfaceVarCheckRule, r tflint.Runner, b *hclext.Block) func() (bool, error) {
	return func() (bool, error) {
		nullableAttr, nullableExists := b.Body.Attributes["nullable"]
		nullableVal := cty.NullVal(cty.Bool)
		var diags hcl.Diagnostics
		if nullableExists {
			nullableVal, diags = nullableAttr.Expr.Value(nil)
		}
		if diags.HasErrors() {
			return false, diags
		}
		// Check nullable attribute.
		if ok := check.Nullable(nullableVal, vcr.Nullable); ok {
			return true, nil
		}
		msg := "nullable should not be set."
		if !vcr.Nullable {
			msg = "nullable should be set to false"
		}
		rg := b.DefRange
		if nullableAttr != nil {
			rg = nullableAttr.Range
		}
		return false, r.EmitIssue(vcr, msg, rg)
	}
}