Repository navigation
fix(srp): count sibling modules as one concern - #866
Merged
DaisukeYoda merged 1 commit intoOct 28, 2026
Merged
Conversation
concernLabel returned the first segment that differs from the module's own path, so for a module importing a sibling in its own package that segment was the sibling's file name. A facade composing a few private helpers (_actor importing _errors, _ref, _registry, _messages) was reported as mixing one concern per file, while the same edges raised the package's cohesion. A direct sibling module now maps to one label named after the shared package, so siblings count as at most one concern and flat-layout packages are still checked instead of having the rule switched off. A generic package name such as utils is skipped, as it is elsewhere. Sibling subpackages and modules elsewhere in the project are labelled as before. Closes ludo-technologies#846
DaisukeYoda
self-requested a review
October 27, 2026 06:21
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.
Summary
The
single-responsibilityrule counted each sibling module in a module's own package as a separate concern. A facade likemypkg._actorthat imports_errors,_ref,_registryand_messageswas flagged as mixing 4 concerns, while the same imports raised the package's cohesion. With this PR the siblings count as one concern, named after the package.Type of Change
Related Issues
Closes #846
Changes
service/responsibility_analysis.go: inconcernLabel, a neighbor with the same depth as the module and the same parent package (a direct sibling) returns the parent package's last segment. This is the "map all siblings to one own-package label" option from the issue, not the looser shared-prefix test it warns against. Sibling subpackages (a.b.mod→a.b.sub.x) and modules elsewhere keep their current label. Top-level modules (no parent package) are unchanged.service/responsibility_analysis_test.go:TestConcernLabelGroupsSiblingModules: the issue repro (mypkg._actor→mypkg) and the Masendor siblings (unit), the aiomisc ones todns, siblings in a generic package such asapp.utilsto no concern (the generic-name filter still applies), andconcernLabel("myapp.core", "myapp.routers.user_router")is stillroutersTestAnalyzeResponsibilityCountsSiblingModulesAsOneConcern: the issue's_actorrepro has one concern and no violationwebsite/docs/rules/single-responsibility.mdand thefr,ja,zhtranslations: one sentence in the paragraph that explains how concerns are inferred.Testing
make testpasses locally (all responsibility and cohesion tests pass; see below for the rest)make lintpasses locally (go vet,golangci-lint run; gofmt is clean on the changed files)Other checks:
TestAnalyzeResponsibilityDetectsHubModuleand the other existing responsibility tests pass unchanged.go test ./...on Windows: three tests inservicefail on this machine (TestFileReader_ErrorTypes,TestFileReader_PermissionHandling,TestProjectSnapshotResolvesRelativeModulePathsAtCaptureTime), and they fail the same way onmainwithout this change.pyscn analyze --json --no-open .:mypkg._actorconcerns["_errors", "_messages", "_ref", "_registry"], one SRP violation, compliance 0.857, health 88 (B)["mypkg"], no violation, compliance 1.0, health 90 (A)Documentation
Additional Context
A sibling subpackage's
__init__(a.b.subseen froma.b.mod) has the same depth as a sibling module, so it is grouped with them too. Telling them apart would needModuleNode.IsPackage, whichconcernLabeldoesn't get today. I left that out to keep the change small.