Skip to content

Conversation

@romshark
Copy link
Contributor

@romshark romshark commented May 15, 2025

This finally upgrades golangci-lint to v2 including changes to the code required by the new linter.

The most error-prone change is 2c009b0 (applying De Morgan's law in boolean expressions)

Depends on:

@romshark romshark self-assigned this May 15, 2025
@jiceathome
Copy link
Contributor

This change is Reviewable

romshark added a commit that referenced this pull request May 15, 2025
fixes `QF1012`, `QF1008` and `errcheck` in `scion-pki`. This is a
sub-task of #4769.
@romshark romshark force-pushed the chore-golangci-lint-v2 branch from 9a438e0 to df48429 Compare May 15, 2025 12:01
@katyatitkova
Copy link
Contributor

I wrote some primitive checkers to see if the changes from 2c009b0 work, and they seem to be 100% correct. Here's the code corresponding to every change:

@romshark romshark requested review from a team, lukedirtwalker and oncilla as code owners May 26, 2025 11:31
- staticcheck
- unconvert
- unused
settings:
Copy link
Contributor

Choose a reason for hiding this comment

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

May be QF1001 can be disabled from staticcheck. so we do not have to always bend to a machine's opinion regarding the legibility of boolean expressions?

Viewed in some else's config file:

    staticcheck:
      # SAxxxx checks in https://staticcheck.dev/docs/configuration/options/#checks
      # Example (to disable some checks): [ "all", "-SA1000", "-SA1001"]
      # Default: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022"]
      checks:
        - all
        # Poorly chosen identifier.
        # https://staticcheck.dev/docs/checks/#ST1003
        - -ST1003
        # The documentation of an exported function should start with the function's name.
        # https://staticcheck.dev/docs/checks/#ST1020
        - -ST1020
        # The documentation of an exported type should start with type's name.
        # https://staticcheck.dev/docs/checks/#ST1021
        - -ST1021
        # The documentation of an exported variable or constant should start with variable's name.
        # https://staticcheck.dev/docs/checks/#ST1022
        - -ST1022
        # Apply De Morgan's law.
        # https://staticcheck.dev/docs/checks/#QF1001
        - -QF1001

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll keep the changes to the existing expressions since some of them are both IMHO and in @katyatitkova opinion more readable now (less unnecessary negation) but I'll disable QF1001

Copy link
Contributor

@jiceathome jiceathome left a comment

Choose a reason for hiding this comment

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

Other than my suggestion rgarding QF1001, LGTM.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, 46 of 50 files at r2, 12 of 12 files at r3, 9 of 9 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @jiceatscion, @oncilla, and @romshark)


router/bfd/session.go line 538 at r5 (raw file):

	}
	if pkt.YourDiscriminator == 0 {
		if pkt.State != layers.BFDStateAdminDown && pkt.State != layers.BFDStateDown {

Suggestion:

	if pkt.YourDiscriminator == 0 && pkt.State != layers.BFDStateAdminDown && pkt.State != layers.BFDStateDown {

router/bfd/session.go line 543 at r5 (raw file):

	}
	if !pkt.AuthPresent {
		if pkt.AuthHeader != nil && pkt.AuthHeader.AuthType != layers.BFDAuthTypeNone {

Suggestion:

	if !pkt.AuthPresent && pkt.AuthHeader != nil && pkt.AuthHeader.AuthType != layers.BFDAuthTypeNone {

private/path/pathpol/acl.go line 190 at r5 (raw file):

	case denySymbol:
		return false, nil
	}

I would just put this in the default case

@romshark
Copy link
Contributor Author

private/path/pathpol/acl.go line 190 at r5 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I would just put this in the default case

you mean putting serrors.New in a default case? I don't see a benefit since it's just 1 extra line that does the exact same. 🤷‍♂️

disable QF1001 and ST1003
enforce ST1016
Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r6, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @jiceatscion, @oncilla, and @romshark)

- staticcheck
- unconvert
- unused
settings:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll keep the changes to the existing expressions since some of them are both IMHO and in @katyatitkova opinion more readable now (less unnecessary negation) but I'll disable QF1001

@romshark
Copy link
Contributor Author

.golangcilint.yml line at r3 (raw file):

Previously, jiceatscion wrote…

May be it would help the review of the new file if this one was git mv'd to the new name first?

I don't think that's necessary since the config structure in v2 changed anyway so the diff would probably be just as bad as comparing a new and old config file.

@romshark
Copy link
Contributor Author

router/bfd/session.go line 538 at r5 (raw file):

	}
	if pkt.YourDiscriminator == 0 {
		if pkt.State != layers.BFDStateAdminDown && pkt.State != layers.BFDStateDown {

Done.

@romshark
Copy link
Contributor Author

router/bfd/session.go line 543 at r5 (raw file):

	}
	if !pkt.AuthPresent {
		if pkt.AuthHeader != nil && pkt.AuthHeader.AuthType != layers.BFDAuthTypeNone {

Done.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @jiceatscion, @katyatitkova, and @oncilla)

Copy link
Contributor Author

@romshark romshark left a comment

Choose a reason for hiding this comment

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

checked diff, LGTM, can merge

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 21 of 21 files at r8, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @jiceatscion, @katyatitkova, and @oncilla)


.golangci.yml line 30 at r8 (raw file):

        # The use of Go ideomatic identifiers is a recommendation, not a law.
        - "-ST1003" # disable "Poorly chosen identifier".
        - "-QF1008"	# disable "Omit embedded fields from selector expression".

tab vs space?

Code quote:

	# 

@romshark
Copy link
Contributor Author

.golangci.yml line 30 at r8 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

tab vs space?

indeed, good catch! Done.

@romshark romshark requested a review from lukedirtwalker May 28, 2025 14:08
Copy link
Contributor

@jiceathome jiceathome left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @lukedirtwalker and @oncilla)

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @oncilla)

@romshark romshark merged commit 7fa5b34 into master May 30, 2025
6 checks passed
@romshark romshark deleted the chore-golangci-lint-v2 branch May 30, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants