Repository navigation
refactor(translate): reduce cognitive complexity in export and reposync - #2157
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Extract one helper per concern from the five functions SonarCloud flags over the cognitive-complexity threshold (go:S3776) and give the token scan in notes.go tokensIn a loop body (go:S108). Evaluation order and every early return are unchanged. - api_json_derived.go: completeDerived -> completedValue - behavior.go: behaviorHead -> sendHead - rdf_in.go: reservedNames -> annotatedForms, declaredNamesOf - rdf_normative.go: materializeRelationships -> pendingRelationships, pendingAt - reposync/diff.go: viewOf -> subjectRoles, carriedContent, settleViews 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)".
|
This branch has not been deployed
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's analysis of
developreports six open findings underinternal/translate: five functions over the cognitive-complexity threshold (go:S3776) and one empty loop body (go:S108). This PR fixes each at the root by extracting one or two well-named helpers per concern. No behaviour changes: evaluation order and every early return are kept, no test changes, no suppressions or rule exclusions.internal/translate/export/api_json_derived.gocompleteDerivedcompletedValue, which returns the spelled value or reports the omission andfalse; the loop keeps only the "already stated" skip and the default-value shortcut.internal/translate/export/behavior.gobehaviorHeadmSendcase body moved tosendHead, which builds the declaration,send, and the payload/via/toclauses; the switch case calls it and wraps the(head, true, err)triple.internal/translate/export/notes.gotokensInforheader is a loop with a body (end++) over the same bound, with the same result.internal/translate/export/rdf_in.goreservedNamesannotatedFormssplits an owner'sannotatedElementobjects into written names and IRIs;declaredNamesOflists an element's declared name then short name.statedForm, which spelled the same two-property loop, now callsdeclaredNamesOftoo.internal/translate/export/rdf_normative.gomaterializeRelationshipspendingtype is the file-levelpendingRelationship;pendingRelationshipscollects the targets and the two position maps;pendingAtresolves a spelled head item to its pending index (anaboutitem by itself, other clauses by kind and object). The emit order (spelled head items first, then every remaining target) is unchanged.internal/translate/interop/reposync/diff.goviewOfsubjectRolesindexes library references and unheld subjects;carriedContentmaps a content triple through theCarrier(a nil carrier carries all, the error keeps itsview.name()/ property label wrapping);settleViewssorts property values and derives name,normative,declaredandmintable, returning theAmbiguousMetaclassErrorwhere the loop did.The gocognit approximation of Sonar's metric now reports 13, 26, 2, 25, 21 and 28 for the six functions (was 37, 35, –, 34, 36, 39).
How it was verified
All on the pushed head, locally:
go build ./...,go vet ./...,gofmt -l .(empty),make lint(staticcheck + gosec): clean.go test ./internal/translate/... ./tests/export/...,go test ./tests/hygiene: pass.make test-quick SHARDS="export export-library export-examples translate": pass.go test ./...: pass (cmd/sysml,tests/codegenandtests/exporthit the default 10m per-package timeout under the full-suite load on an 8-core box and passed on a rerun with-timeout 45m, as CI runs them).go run -C tools ./cmd/pilot-apijson-diff -updateover all nine roots (training, pilot and spec examples downloaded): the baseline underdocs/project/api-json-differential/is byte-identical todevelop(935 files; every count unchanged, the digest included), so no baseline change is in the diff.go test -C tools ./referee/apijson: pass.OPENSYSML_REQUIRE_TRAINING_CORPUS=1 OPENSYSML_REQUIRE_PILOT_CORPORA=1 OPENSYSML_REQUIRE_SPEC_EXAMPLES=1 go test ./tests/corpus -run TestCorpusRoundTrip: pass, no per-file verdict moved.git diff --merge-base origin/develop | awk ...),scripts/check-doc-ids.py,scripts/changelog.py check: clean..agents/skills/reviewing-pull-requests/SKILL.md: each helper was checked against its original inline block for the same evaluation order, early returns and error wrapping; every caller is the one function it was extracted from (declaredNamesOfalso replaces the identical loop instatedForm).Dry merges (
git merge-tree --write-tree HEAD pr/N) against the open PRs touching these files: #2143 and #2133 clean; #2142 and #2042 conflict only on files they already conflict withdevelopon (API-JSON differential baseline files, and for #2042 alsoannotations.go,derived_census_baseline.jsonand.golden.ttl.sha256fixtures), none of them touched here.Checklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build)F4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/e21f30dd70b84ec387741f788db727ff
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/e21f30dd70b84ec387741f788db727ff?variant=devin
Requested by: @HuiJun
🟢 Devin Review found nothing to fix · View findings