Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 2058e4c

Browse files
authored
fix: pathExpression for RequireIfAttributeIsOneOf validator (#53)
* fix: pathExpression and ExceptedValues missing in require_if_attribute_is_one_of validator * fix: disable depguard after golang-ci-lint upgrade * fix: structcheck lint `foo` is unused
1 parent 0788fda commit 2058e4c

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ linters:
1010
- bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
1111
- deadcode # Finds unused code [fast: false, auto-fix: false]
1212
- decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
13-
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
1413
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
1514
- durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
1615
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
@@ -61,6 +60,7 @@ linters:
6160
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
6261

6362
disable:
63+
- depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
6464
- dupl # Tool for code clone detection [fast: true, auto-fix: false]
6565
- containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
6666
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]

internal/require_if_attribute_is_one_of.go

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ func (av RequireIfAttributeIsOneOf) Validate(ctx context.Context, req RequireIfA
7474
return
7575
}
7676

77+
expression := req.PathExpression.Merge(av.PathExpression)
78+
7779
// Here attribute configuration is null or unknown, so we need to check if attribute in the path
7880
// is equal to one of the excepted values
79-
paths, diags := req.Config.PathMatches(ctx, av.PathExpression)
81+
paths, diags := req.Config.PathMatches(ctx, expression)
8082
res.Diagnostics.Append(diags...)
81-
if diags.HasError() {
83+
if res.Diagnostics.HasError() {
8284
return
8385
}
8486

@@ -123,9 +125,10 @@ func (av RequireIfAttributeIsOneOf) Validate(ctx context.Context, req RequireIfA
123125

124126
func (av RequireIfAttributeIsOneOf) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) {
125127
validateReq := RequireIfAttributeIsOneOfRequest{
126-
Config: req.Config,
127-
ConfigValue: req.ConfigValue,
128-
Path: req.Path,
128+
Config: req.Config,
129+
ConfigValue: req.ConfigValue,
130+
Path: req.Path,
131+
PathExpression: req.PathExpression,
129132
}
130133
validateResp := &RequireIfAttributeIsOneOfResponse{}
131134

@@ -136,9 +139,10 @@ func (av RequireIfAttributeIsOneOf) ValidateBool(ctx context.Context, req valida
136139

137140
func (av RequireIfAttributeIsOneOf) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) {
138141
validateReq := RequireIfAttributeIsOneOfRequest{
139-
Config: req.Config,
140-
ConfigValue: req.ConfigValue,
141-
Path: req.Path,
142+
Config: req.Config,
143+
ConfigValue: req.ConfigValue,
144+
Path: req.Path,
145+
PathExpression: req.PathExpression,
142146
}
143147
validateResp := &RequireIfAttributeIsOneOfResponse{}
144148

@@ -149,9 +153,10 @@ func (av RequireIfAttributeIsOneOf) ValidateFloat64(ctx context.Context, req val
149153

150154
func (av RequireIfAttributeIsOneOf) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) {
151155
validateReq := RequireIfAttributeIsOneOfRequest{
152-
Config: req.Config,
153-
ConfigValue: req.ConfigValue,
154-
Path: req.Path,
156+
Config: req.Config,
157+
ConfigValue: req.ConfigValue,
158+
Path: req.Path,
159+
PathExpression: req.PathExpression,
155160
}
156161
validateResp := &RequireIfAttributeIsOneOfResponse{}
157162

@@ -162,9 +167,10 @@ func (av RequireIfAttributeIsOneOf) ValidateInt64(ctx context.Context, req valid
162167

163168
func (av RequireIfAttributeIsOneOf) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) {
164169
validateReq := RequireIfAttributeIsOneOfRequest{
165-
Config: req.Config,
166-
ConfigValue: req.ConfigValue,
167-
Path: req.Path,
170+
Config: req.Config,
171+
ConfigValue: req.ConfigValue,
172+
Path: req.Path,
173+
PathExpression: req.PathExpression,
168174
}
169175
validateResp := &RequireIfAttributeIsOneOfResponse{}
170176

@@ -175,9 +181,10 @@ func (av RequireIfAttributeIsOneOf) ValidateList(ctx context.Context, req valida
175181

176182
func (av RequireIfAttributeIsOneOf) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) {
177183
validateReq := RequireIfAttributeIsOneOfRequest{
178-
Config: req.Config,
179-
ConfigValue: req.ConfigValue,
180-
Path: req.Path,
184+
Config: req.Config,
185+
ConfigValue: req.ConfigValue,
186+
Path: req.Path,
187+
PathExpression: req.PathExpression,
181188
}
182189
validateResp := &RequireIfAttributeIsOneOfResponse{}
183190

@@ -188,9 +195,10 @@ func (av RequireIfAttributeIsOneOf) ValidateMap(ctx context.Context, req validat
188195

189196
func (av RequireIfAttributeIsOneOf) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) {
190197
validateReq := RequireIfAttributeIsOneOfRequest{
191-
Config: req.Config,
192-
ConfigValue: req.ConfigValue,
193-
Path: req.Path,
198+
Config: req.Config,
199+
ConfigValue: req.ConfigValue,
200+
Path: req.Path,
201+
PathExpression: req.PathExpression,
194202
}
195203
validateResp := &RequireIfAttributeIsOneOfResponse{}
196204

@@ -201,9 +209,10 @@ func (av RequireIfAttributeIsOneOf) ValidateNumber(ctx context.Context, req vali
201209

202210
func (av RequireIfAttributeIsOneOf) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) {
203211
validateReq := RequireIfAttributeIsOneOfRequest{
204-
Config: req.Config,
205-
ConfigValue: req.ConfigValue,
206-
Path: req.Path,
212+
Config: req.Config,
213+
ConfigValue: req.ConfigValue,
214+
Path: req.Path,
215+
PathExpression: req.PathExpression,
207216
}
208217
validateResp := &RequireIfAttributeIsOneOfResponse{}
209218

@@ -214,9 +223,10 @@ func (av RequireIfAttributeIsOneOf) ValidateObject(ctx context.Context, req vali
214223

215224
func (av RequireIfAttributeIsOneOf) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) {
216225
validateReq := RequireIfAttributeIsOneOfRequest{
217-
Config: req.Config,
218-
ConfigValue: req.ConfigValue,
219-
Path: req.Path,
226+
Config: req.Config,
227+
ConfigValue: req.ConfigValue,
228+
Path: req.Path,
229+
PathExpression: req.PathExpression,
220230
}
221231
validateResp := &RequireIfAttributeIsOneOfResponse{}
222232

@@ -227,9 +237,10 @@ func (av RequireIfAttributeIsOneOf) ValidateSet(ctx context.Context, req validat
227237

228238
func (av RequireIfAttributeIsOneOf) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
229239
validateReq := RequireIfAttributeIsOneOfRequest{
230-
Config: req.Config,
231-
ConfigValue: req.ConfigValue,
232-
Path: req.Path,
240+
Config: req.Config,
241+
ConfigValue: req.ConfigValue,
242+
Path: req.Path,
243+
PathExpression: req.PathExpression,
233244
}
234245
validateResp := &RequireIfAttributeIsOneOfResponse{}
235246

listvalidator/not_valid_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
func TestNotValidator(t *testing.T) {
1616
t.Parallel()
1717

18-
type testStruct struct {
19-
foo string
20-
}
21-
2218
type testCase struct {
2319
val []attr.Value
2420
expectError bool

mapvalidator/not_valid_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
func TestNotValidator(t *testing.T) {
1616
t.Parallel()
1717

18-
type testStruct struct {
19-
foo string
20-
}
21-
2218
type testCase struct {
2319
val map[string]attr.Value
2420
expectError bool

setvalidator/not_valid_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
func TestNotValidator(t *testing.T) {
1616
t.Parallel()
1717

18-
type testStruct struct {
19-
foo string
20-
}
21-
2218
type testCase struct {
2319
val []attr.Value
2420
expectError bool

0 commit comments

Comments
 (0)