Skip to content

Commit 1af9686

Browse files
committed
fix lints
Signed-off-by: Carlos Panato <ctadeu@gmail.com>
1 parent f67edd7 commit 1af9686

13 files changed

Lines changed: 22 additions & 40 deletions

.github/workflows/coverage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
contents: read
2525

2626
strategy:
27+
fail-fast: false
2728
matrix:
2829
go-version:
2930
- '1.23'

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ linters:
1010
- importas
1111
- misspell
1212
- prealloc
13-
- revive
13+
# - revive # disabled due becasue ask to change some variables and functions that might break the api compatibility
1414
- staticcheck
1515
- tparallel
1616
- unconvert

pkg/api/bindings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func AsCloudEvent(event CDEventReader) (*cloudevents.Event, error) {
108108
// Validate the event
109109
err := Validate(event)
110110
if err != nil {
111-
return nil, fmt.Errorf("cannot validate CDEvent %v", err)
111+
return nil, fmt.Errorf("cannot validate CDEvent %w", err)
112112
}
113113
ce := cloudevents.NewEvent()
114114
ce.SetID(event.GetId())
@@ -149,10 +149,10 @@ func Validate(event CDEventReader) error {
149149
var v interface{}
150150
jsonString, err := AsJsonString(event)
151151
if err != nil {
152-
return fmt.Errorf("cannot render the event %s as json %s", event, err)
152+
return fmt.Errorf("cannot render the event %s as json %w", event, err)
153153
}
154154
if err := json.Unmarshal([]byte(jsonString), &v); err != nil {
155-
return fmt.Errorf("cannot unmarshal event json: %v", err)
155+
return fmt.Errorf("cannot unmarshal event json: %w", err)
156156
}
157157
// Validate the "validate" tags
158158
if err := validate.Struct(event); err != nil {

pkg/api/bindings_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func setContext(event api.CDEventWriter, subjectId string) {
143143
event.SetSubjectId(subjectId)
144144
}
145145

146-
func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) {
146+
func setContextV04(event api.CDEventWriterV04, chainId, schemaUri bool) { //nolint: unparam
147147
if chainId {
148148
event.SetChainId(testChainId)
149149
}
@@ -239,7 +239,6 @@ func init() {
239239
// TestAsCloudEvent produces a CloudEvent from a CDEvent using `AsCloudEvent`
240240
// and then attempts to parse the CloudEvent payload back into a specific CDEvent
241241
func TestAsCloudEvent(t *testing.T) {
242-
243242
tests := []struct {
244243
name string
245244
event api.CDEventReader
@@ -309,7 +308,6 @@ func TestAsCloudEvent(t *testing.T) {
309308
}
310309

311310
func TestAsCloudEventInvalid(t *testing.T) {
312-
313311
tests := []struct {
314312
name string
315313
event api.CDEventReader
@@ -353,7 +351,6 @@ func TestAsCloudEventInvalid(t *testing.T) {
353351
// rendered JSON depends on a number of factors, and is not deterministic
354352
// so we must compare events unmarshalled to an interface
355353
func TestAsJsonBytes(t *testing.T) {
356-
357354
tests := []struct {
358355
name string
359356
event api.CDEvent
@@ -393,7 +390,7 @@ func TestAsJsonBytes(t *testing.T) {
393390
if err != nil {
394391
t.Fatalf("didn't expected it to fail, but it did: %v", err)
395392
}
396-
err = json.Unmarshal([]byte(obtainedJsonString), &obtainedInteface)
393+
err = json.Unmarshal(obtainedJsonString, &obtainedInteface)
397394
if err != nil {
398395
t.Fatalf("didn't expected it to fail, but it did: %v", err)
399396
}
@@ -409,7 +406,6 @@ func TestAsJsonBytes(t *testing.T) {
409406
}
410407

411408
func TestInvalidEvent(t *testing.T) {
412-
413409
// mandatory source missing
414410
eventNoSource, _ := testapi.NewFooSubjectBarPredicateEvent()
415411
eventNoSource.SetSubjectId(testSubjectId)
@@ -506,7 +502,6 @@ func TestAsJsonStringEmpty(t *testing.T) {
506502
}
507503

508504
func TestNewFromJsonString(t *testing.T) {
509-
510505
tests := []struct {
511506
name string
512507
event api.CDEventV04
@@ -582,7 +577,6 @@ func TestNewFromJsonString(t *testing.T) {
582577
}
583578

584579
func TestParseType(t *testing.T) {
585-
586580
tests := []struct {
587581
name string
588582
eventType string
@@ -668,7 +662,6 @@ func testEventWithVersion(eventVersion string, specVersion string) *testapi.FooS
668662
}
669663

670664
func TestNewFromJsonBytes(t *testing.T) {
671-
672665
minorVersion := testEventWithVersion("2.999.1", testapi.SpecVersion)
673666
patchVersion := testEventWithVersion("2.2.999", testapi.SpecVersion)
674667
pastPatchVersion := testEventWithVersion("2.2.0", testapi.SpecVersion)

pkg/api/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
var timeNow = time.Now
2929
var uuidNewRandom = uuid.NewRandom
3030

31-
func initCDEvent(e CDEvent) (CDEvent, error) {
31+
func initCDEvent(e CDEvent) (CDEvent, error) { //nolint: unparam
3232
eventUUID, err := uuidNewRandom()
3333
if err != nil {
3434
return nil, err

pkg/api/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,28 +290,29 @@ func (ela *EmbeddedLinksArray) UnmarshalJSON(b []byte) error {
290290
if err != nil {
291291
return err
292292
}
293-
if m.LinkType == LinkTypeEnd {
293+
switch m.LinkType {
294+
case LinkTypeEnd:
294295
var e embeddedLinkEnd
295296
err = json.Unmarshal(*rawEmbeddedLink, &e)
296297
if err != nil {
297298
return err
298299
}
299300
receiver[index] = &e
300-
} else if m.LinkType == LinkTypePath {
301+
case LinkTypePath:
301302
var e embeddedLinkPath
302303
err = json.Unmarshal(*rawEmbeddedLink, &e)
303304
if err != nil {
304305
return err
305306
}
306307
receiver[index] = &e
307-
} else if m.LinkType == LinkTypeRelation {
308+
case LinkTypeRelation:
308309
var e embeddedLinkRelation
309310
err = json.Unmarshal(*rawEmbeddedLink, &e)
310311
if err != nil {
311312
return err
312313
}
313314
receiver[index] = &e
314-
} else {
315+
default:
315316
return fmt.Errorf("unsupported link type %s found", m.LinkType)
316317
}
317318
}

pkg/api/types_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ type testWrongType struct {
7676
}
7777

7878
func TestGetCustomDataAsNonJson(t *testing.T) {
79-
8079
receiver := &testType{}
8180
expectedError := "cannot unmarshal content-type application/xml"
8281

@@ -91,7 +90,6 @@ func TestGetCustomDataAsNonJson(t *testing.T) {
9190
}
9291

9392
func TestGetCustomDataAsJson(t *testing.T) {
94-
9593
receiver := &testType{}
9694
expectedValue := "testValue"
9795

@@ -127,7 +125,6 @@ func TestGetCustomDataAsJson(t *testing.T) {
127125
}
128126

129127
func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {
130-
131128
receiver := &testWrongType{}
132129
expectedReceiver := &testWrongType{}
133130

@@ -163,7 +160,6 @@ func TestGetCustomDataAsJsonInvalidReceiver(t *testing.T) {
163160
}
164161

165162
func TestSetCustomData(t *testing.T) {
166-
167163
tests := []struct {
168164
name string
169165
contentType string
@@ -215,7 +211,6 @@ func TestSetCustomDataInvalid(t *testing.T) {
215211
}
216212

217213
func TestGetCustomData(t *testing.T) {
218-
219214
tests := []struct {
220215
name string
221216
contentType string
@@ -302,7 +297,6 @@ func TestGetCustomDataXmlNotBytes(t *testing.T) {
302297
}
303298

304299
func TestGetCustomDataRaw(t *testing.T) {
305-
306300
tests := []struct {
307301
name string
308302
contentType string
@@ -327,7 +321,7 @@ func TestGetCustomDataRaw(t *testing.T) {
327321
name: "json, interface",
328322
contentType: "application/json",
329323
data: testType{TestData: "testValue"},
330-
expectedData: []byte(testJsonString),
324+
expectedData: testJsonString,
331325
}}
332326

333327
for _, tc := range tests {

pkg/api/v03/examples_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ func exampleTestOutputPublishedEvent(e *apiv03.TestOutputPublishedEvent) {
376376
}
377377

378378
func init() {
379-
380379
// Load event examples from the spec
381380
examplesConsumed = make(map[string][]byte)
382381

@@ -394,7 +393,6 @@ func init() {
394393
// - it parses the examples into a CDEvent and
395394
// - it verifies that produced and consumed CDEvent match
396395
func TestExamples(t *testing.T) {
397-
398396
for name, exampleConsumed := range examplesConsumed {
399397
t.Run(name, func(t *testing.T) {
400398
produced, ok := examplesProduced[name]

pkg/api/v03/factory_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func TestNewCDEvent(t *testing.T) {
129129
}
130130

131131
func TestNewCDEventFailed(t *testing.T) {
132-
133132
_, err := cdevents.NewCDEvent(api.CDEventType{Subject: "not supported"}.String(), testSpecVersion)
134133
if err == nil {
135134
t.Fatalf("expected it to fail, but it didn't")

pkg/api/v04/conformance_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ func exampleCustomTypeEvent(e *apiv04.CustomTypeEvent) {
562562
// - it parses the examples into a CDEvent and
563563
// - it verifies that produced and consumed CDEvent match
564564
func TestExamples(t *testing.T) {
565-
566565
for name, exampleConsumed := range examplesConsumed {
567566
t.Run(name, func(t *testing.T) {
568567
produced, ok := examplesProduced[name]

0 commit comments

Comments
 (0)