Skip to content

CHORE: Replace parser.ParseDir, which is deprecated#4154

Open
tlimoncelli wants to merge 1 commit intomainfrom
tlim_b4089
Open

CHORE: Replace parser.ParseDir, which is deprecated#4154
tlimoncelli wants to merge 1 commit intomainfrom
tlim_b4089

Conversation

@tlimoncelli
Copy link
Contributor

Fixed #4089

FYI: I used Claude to fix this. I actually don't understand the original code so please give this extra scrutiny.

CC @philpennock

Issue

lint is reporting that parser.ParseDir is deprecated:

$ golangci-lint run ./...
pkg/normalize/capabilities_test.go:24:15: SA1019: parser.ParseDir has been deprecated since Go 1.25 and an alternative has been available since Go 1.11: ParseDir does not consider build tags when associating files with packages. For precise information about the relationship between packages and files, use golang.org/x/tools/go/packages, which can also optionally parse and type-check the files too. (staticcheck)
	pkgs, err := parser.ParseDir(fset, providersImportDir, nil, 0)
	             ^

Resolution

Use golang.org/x/tools/go/packages instead.

Copy link
Contributor

@philpennock philpennock left a comment

Choose a reason for hiding this comment

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

Basic smoke test: invoke go test -v -run TestCapabilitiesAreFiltered ./pkg/normalize

The reported details with this patch are very bogus. "is checked for with ..."

Before:

=== RUN   TestCapabilitiesAreFiltered
    capabilities_test.go:74: ok: providers.CanUseAKAMAICDN (4) is checked for with "AKAMAICDN"
    capabilities_test.go:74: ok: providers.CanUseAKAMAITLC (29) is checked for with "AKAMAITLC"
    capabilities_test.go:74: ok: providers.CanUseAlias (5) is checked for with "ALIAS"
    capabilities_test.go:74: ok: providers.CanUseAzureAlias (6) is checked for with "AZURE_ALIAS"
    capabilities_test.go:74: ok: providers.CanUseCAA (7) is checked for with "CAA"
    capabilities_test.go:74: ok: providers.CanUseDHCID (8) is checked for with "DHCID"
    capabilities_test.go:74: ok: providers.CanUseDNAME (9) is checked for with "DNAME"
    capabilities_test.go:74: ok: providers.CanUseDNSKEY (24) is checked for with "DNSKEY"
    capabilities_test.go:74: ok: providers.CanUseDS (10) is checked for with "DS"
    capabilities_test.go:74: ok: providers.CanUseDSForChildren (11) is checked for with "DS"
    capabilities_test.go:74: ok: providers.CanUseHTTPS (12) is checked for with "HTTPS"
    capabilities_test.go:74: ok: providers.CanUseLOC (13) is checked for with "LOC"
    capabilities_test.go:74: ok: providers.CanUseNAPTR (14) is checked for with "NAPTR"
    capabilities_test.go:74: ok: providers.CanUseOPENPGPKEY (25) is checked for with "OPENPGPKEY"
    capabilities_test.go:74: ok: providers.CanUsePTR (15) is checked for with "PTR"
    capabilities_test.go:74: ok: providers.CanUseRP (17) is checked for with "RP"
    capabilities_test.go:74: ok: providers.CanUseRoute53Alias (16) is checked for with "R53_ALIAS"
    capabilities_test.go:74: ok: providers.CanUseSMIMEA (18) is checked for with "SMIMEA"
    capabilities_test.go:74: ok: providers.CanUseSOA (19) is checked for with "SOA"
    capabilities_test.go:74: ok: providers.CanUseSRV (20) is checked for with "SRV"
    capabilities_test.go:74: ok: providers.CanUseSSHFP (21) is checked for with "SSHFP"
    capabilities_test.go:74: ok: providers.CanUseSVCB (22) is checked for with "SVCB"
    capabilities_test.go:74: ok: providers.CanUseTLSA (23) is checked for with "TLSA"
--- PASS: TestCapabilitiesAreFiltered (0.00s)

On this branch:

=== RUN   TestCapabilitiesAreFiltered
    capabilities_test.go:86: ok: providers.CanUseAKAMAICDN (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseAKAMAITLC (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseAlias (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseAzureAlias (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseCAA (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseDHCID (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseDNAME (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseDNSKEY (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseDS (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseDSForChildren (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseHTTPS (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseLOC (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseNAPTR (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseOPENPGPKEY (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUsePTR (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseRP (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseRoute53Alias (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseSMIMEA (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseSOA (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseSRV (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseSSHFP (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseSVCB (0) is checked for with "AUTODNSSEC"
    capabilities_test.go:86: ok: providers.CanUseTLSA (0) is checked for with "AUTODNSSEC"
--- PASS: TestCapabilitiesAreFiltered (1.69s)
PASS

@philpennock
Copy link
Contributor

The second check is to edit pkg/normalize/validate.go to find the providerCapabilityChecks array, and comment out an entry. If the test passes when we're not actually doing the check, then the test has been made bogus.

If I apply this test of the test on main, then the test correctly fails when I comment out DNAME. If I do the same on this branch, then the test passes, which means it has been made ineffective.

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.

Replace SA1019: parser.ParseDir

2 participants