Repository navigation
refactor(runtime): clear the three Sonar smells left on develop - #1771
Merged
Merged
Conversation
eachUnwrappedDeclMember and unwrappedDeclMembers opened with the same three-way dispatch — ast.OwnedConstraintOf, then a type switch over the assume and require members — although the first check only ever answers for those same two node types and returns their Body unchanged. Both now call one helper, constraintMemberBody, so the iterator keeps a single yield loop and its cognitive complexity drops from 33 to 17 (go:S3776). The member sequence each reader yields is unchanged for every declaration kind, and the helper inlines and allocates nothing. Two `got :=` variables in validate_test.go that were only read in their if condition are inlined (godre:S8193). Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
4 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
SonarCloud reports three open Go code smells on
developthat should be cleared before 0.12.0 is cut:go:S3776oneachUnwrappedDeclMemberininternal/exec/runtime/invoke_calc.go: cognitive complexity 33, the allowed maximum is 30.godre:S8193twice ininternal/frontend/grpc/validate_test.go: agot :=variable declared in anifand used only in the condition.eachUnwrappedDeclMemberandunwrappedDeclMembersboth opened with the same three-way dispatch —ast.OwnedConstraintOf, then a type switch over*ast.AssumeMemberand*ast.RequireMember— and the iterator form repeated the yield loop in each arm.ast.OwnedConstraintOfonly answers true for those same two node types and hands back theirBodyunchanged, so the first check never selected a member list the type switch would not have selected. Both readers now call one helper,constraintMemberBody(decl) ([]ast.Node, bool), which returns the nested members of an assume or require member in either of its forms; the iterator keeps a single yield loop over that body and the existingast.DeclMemberswalk. The sequence of members each reader produces is unchanged for every declaration kind, so no caller, error or error timing moves. The iterator's cognitive complexity drops from 33 to 17.The two test variables are inlined into their conditions; the failure messages already print the slices, not the joined string.
No changelog fragment: a pure refactor with no user-visible change.
How it was verified
go build ./...,go vet ./...,gofmt -l .(empty)go test ./internal/exec/runtime/... ./internal/frontend/grpc/...make test-shorteachUnwrappedDeclMemberwas just perf-tuned (#1742 removed allocations from the binding walks), so the three benchmarks that walk it were measured ondevelop(8dc84706) and on this branch, six rounds each, withgo test -run '^$' -bench <name> -benchmem -count=6;InstantiateWarmModelwas measured in alternating develop/branch rounds because its single-tree runs vary by ±50% on this box.benchstatfinds B/op, allocs/op and sec/op unchanged within noise (the new helper allocates nothing and is inlined):Checklist
make testandmake lintpass locally (make test-shortand the race-free package suites; see above)F4,K5) in the body, docs, or changelog