Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lint): Add support for linter in mage #2392

Merged
merged 14 commits into from
Jan 31, 2025
Merged

chore(lint): Add support for linter in mage #2392

merged 14 commits into from
Jan 31, 2025

Conversation

simar7
Copy link
Member

@simar7 simar7 commented Jan 23, 2025

Description

  • Add support for linter in mage
  • Address linting issues

.golanci.yaml is taken from Trivy.

list-mode: lax
deny:
# Cannot use gomodguard, which examines go.mod, as "golang.org/x/exp/slices" is not a module and doesn't appear in go.mod.
- pkg: "golang.org/x/exp/slices"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's relevant for trivy-operator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, removed!

@@ -46,8 +47,8 @@ func evaluate(ctx context.Context, policies *policy.Policies, resource client.Ob
if err != nil {
return Misconfiguration{}, err
}
infraChecks := make([]v1alpha1.Check, 0)
checks := make([]v1alpha1.Check, 0)
var infraChecks []v1alpha1.Check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like it's not equal update.

Comment on lines 10 to 15
`$name := []$t{}`,
`$name := make([]$t, 0)`,
).
Suggest(`var $name []$t`).
Report(`replace '$$' with 'var $name []$t'`)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for me, var $name []$t isn't equal $name := make([]$t, 0),
because $name := make([]$t, 0) contains two operations:

  • create a new variable
  • init this one with an empty array,

but var $name []$t does only creating

Copy link
Contributor

@afdesk afdesk Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so after var $name []$t, $name is nil, but after $name := make([]$t, 0) $name is []$t

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, in this case as per the golang spec it makes sense to use make due to JSON being involved. I've updated it.

@@ -142,7 +143,7 @@ type secretsReader struct {
}

func (r *secretsReader) ListByLocalObjectReferences(ctx context.Context, refs []corev1.LocalObjectReference, ns string) ([]corev1.Secret, error) {
secrets := make([]corev1.Secret, 0)
var secrets []corev1.Secret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imho it's not equal too, and it's important for tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@simar7 simar7 force-pushed the mage-lint branch 2 times, most recently from 8aa63b3 to ded4707 Compare January 29, 2025 02:02
@simar7
Copy link
Member Author

simar7 commented Jan 29, 2025

@afdesk thanks for the review, could you take another look? The tests are green now.

Comment on lines +4 to +8
"github.com/aquasecurity/go-version/pkg/semver"
)

func compareTagVersion(currentTag string, contraint string) bool {
c, err := semver.NewConstraint(contraint)
func compareTagVersion(currentTag, constraint string) bool {
c, err := semver.NewConstraints(constraint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change made by linter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partially yes. The change to eliminate the redundant type was suggested by the linter and the typo was fixed by me.

As for the semver package, We have had issues in the past with upstream semver, for aqua projects we use the aqua go-version pkg.

Comment on lines +101 to +102
TrueString = "true"
FalseString = "false"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just note. For me it's an interesting action for linter

@afdesk
Copy link
Contributor

afdesk commented Jan 29, 2025

@simar7 LGTM

I left two comments just to make sure you saw and approved these changes.

@simar7 simar7 merged commit f6d43a8 into main Jan 31, 2025
8 checks passed
@simar7 simar7 deleted the mage-lint branch January 31, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants