Skip to content

Commit

Permalink
chore(make): merge extra-lint target into lint
Browse files Browse the repository at this point in the history
Add extra-lint checks to the lint target to ensure they are always run during CI,
removing the need for an additional target that is often neglected. This helps
prevent the accumulation of regressions in the main branch.

Signed-off-by: Akhilesh Kr. Yadav <[email protected]>
  • Loading branch information
Akhilesh Kr. Yadav authored and Akhilesh Kr. Yadav committed Jan 15, 2025
1 parent f5d05a0 commit 7e33dd8
Show file tree
Hide file tree
Showing 28 changed files with 148 additions and 161 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ jobs:
go install github.com/golang/mock/[email protected]
- name: Run required linters in .golangci.yml plus hard-coded ones here
run: make lint
- name: Run optional linters (not required to pass)
run: make lint-extra
17 changes: 5 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ GOPKG += github.com/veraison/corim/extensions

GOLINT ?= golangci-lint

ifeq ($(MAKECMDGOALS),lint)
GOLINT_ARGS ?= run --timeout=3m
else
ifeq ($(MAKECMDGOALS),lint-extra)
GOLINT_ARGS ?= run --timeout=3m --issues-exit-code=0 -E dupl -E gocritic -E gosimple -E lll -E prealloc
endif
endif
GOLINT_ARGS ?= run --timeout=3m -E dupl -E gocritic -E gosimple -E lll -E prealloc

.PHONY: lint lint-extra
lint lint-extra:
.PHONY: lint
lint:
$(GOLINT) $(GOLINT_ARGS)

ifeq ($(MAKECMDGOALS),test)
Expand Down Expand Up @@ -50,7 +44,7 @@ presubmit:
@echo
@echo ">>> Fix any lint error"
@echo
$(MAKE) lint-extra
$(MAKE) lint

.PHONY: licenses
licenses: ; @./scripts/licenses.sh
Expand All @@ -60,8 +54,7 @@ help:
@echo "Available targets:"
@echo " * test: run unit tests for $(GOPKG)"
@echo " * test-cover: run unit tests and measure coverage for $(GOPKG)"
@echo " * lint: lint sources using default configuration"
@echo " * lint-extra: lint sources using default configuration and some extra checkers"
@echo " * lint: lint sources using default configuration and some extra checkers"
@echo " * presubmit: check you are ready to push your local branch to remote"
@echo " * help: print this menu"
@echo " * licenses: check licenses of dependent packages"
2 changes: 2 additions & 0 deletions comid/classid.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func (o *ClassID) UnmarshalCBOR(data []byte) error {
// uuid: standard UUID string representation, e.g. "550e8400-e29b-41d4-a716-446655440000"
// int: an integer value, e.g. 7
// bytes: a variable length opaque bytes, example {0x07, 0x12, 0x34}

//nolint:dupl
func (o *ClassID) UnmarshalJSON(data []byte) error {
var tnv encoding.TypeAndValue

Expand Down
16 changes: 8 additions & 8 deletions comid/comid.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (o *Comid) AddDevIdentityKey(val KeyTriple) *Comid {
return o
}

func (o Comid) Valid() error {
func (o *Comid) Valid() error {
if err := o.TagIdentity.Valid(); err != nil {
return fmt.Errorf("tag-identity validation failed: %w", err)
}
Expand All @@ -263,11 +263,11 @@ func (o Comid) Valid() error {
return fmt.Errorf("triples validation failed: %w", err)
}

return o.Extensions.validComid(&o)
return o.Extensions.validComid(o)
}

// ToCBOR serializes the target Comid to CBOR
func (o Comid) ToCBOR() ([]byte, error) {
func (o *Comid) ToCBOR() ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}
Expand All @@ -282,7 +282,7 @@ func (o Comid) ToCBOR() ([]byte, error) {
o.Entities = nil
}

return encoding.SerializeStructToCBOR(em, &o)
return encoding.SerializeStructToCBOR(em, o)
}

// FromCBOR deserializes a CBOR-encoded CoMID into the target Comid
Expand All @@ -291,7 +291,7 @@ func (o *Comid) FromCBOR(data []byte) error {
}

// ToJSON serializes the target Comid to JSON
func (o Comid) ToJSON() ([]byte, error) {
func (o *Comid) ToJSON() ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}
Expand All @@ -306,18 +306,18 @@ func (o Comid) ToJSON() ([]byte, error) {
o.Entities = nil
}

return encoding.SerializeStructToJSON(&o)
return encoding.SerializeStructToJSON(o)
}

// FromJSON deserializes a JSON-encoded CoMID into the target Comid
func (o *Comid) FromJSON(data []byte) error {
return encoding.PopulateStructFromJSON(data, o)
}

func (o Comid) ToJSONPretty(indent string) ([]byte, error) {
func (o *Comid) ToJSONPretty(indent string) ([]byte, error) {
if err := o.Valid(); err != nil {
return nil, err
}

return json.MarshalIndent(&o, "", indent)
return json.MarshalIndent(o, "", indent)
}
6 changes: 3 additions & 3 deletions comid/example_cca_realm_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func extractRealmRefVal(rv ValueTriple) error {
}
return nil
}

func extractMeasurements(m Measurements) error {
if len(m.Values) == 0 {
return fmt.Errorf("no measurements")
}
for i, meas := range m.Values {
for i := range m.Values {
meas := &m.Values[i]
if err := extractMeasurement(meas); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
Expand All @@ -91,7 +91,7 @@ func extractMeasurements(m Measurements) error {
return nil
}

func extractMeasurement(m Measurement) error {
func extractMeasurement(m *Measurement) error {
if err := extractRealmPersonalizationValue(m.Val.RawValue); err != nil {
return fmt.Errorf("extracting realm personalization value: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions comid/example_cca_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func extractCCARefVal(rv ValueTriple) error {
return fmt.Errorf("extracting impl-id: %w", err)
}

for i, m := range rv.Measurements.Values {
for i := range rv.Measurements.Values {
m := &rv.Measurements.Values[i]
if m.Key == nil {
return fmt.Errorf("missing mKey at index %d", i)
}
Expand All @@ -75,10 +76,10 @@ func extractCCARefVal(rv ValueTriple) error {
return fmt.Errorf("extracting cca-refval-id: %w", err)
}
if err := extractRawValue(m.Val.RawValue); err != nil {
return fmt.Errorf("extracting raw vlue: %w", err)
return fmt.Errorf("extracting raw value: %w", err)
}
default:
return fmt.Errorf("unexpected Mkey type: %T", t)
return fmt.Errorf("unexpected Mkey type: %T", t)
}
}

Expand Down
7 changes: 4 additions & 3 deletions comid/example_psa_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ func extractSwMeasurements(m Measurements) error {
if len(m.Values) == 0 {
return fmt.Errorf("no measurements")
}
for i, m := range m.Values {
if err := extractSwMeasurement(m); err != nil {
for i := range m.Values {
meas := &m.Values[i]
if err := extractSwMeasurement(meas); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
}
return nil
}

func extractSwMeasurement(m Measurement) error {
func extractSwMeasurement(m *Measurement) error {
if err := extractPSARefValID(m.Key); err != nil {
return fmt.Errorf("extracting PSA refval id: %w", err)
}
Expand Down
Loading

0 comments on commit 7e33dd8

Please sign in to comment.