Create rule S7134 (#4740)
Co-authored-by: Marco Kaufmann <marco.kaufmann@sonarsource.com>
This commit is contained in:
parent
51dd4ca773
commit
c6cbb0a4bd
2
rules/S7134/python/metadata.json
Normal file
2
rules/S7134/python/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
64
rules/S7134/python/rule.adoc
Normal file
64
rules/S7134/python/rule.adoc
Normal file
@ -0,0 +1,64 @@
|
||||
This rule reports when a source module does not adhere to the architectural constraints defined for a project.
|
||||
|
||||
== Why is this an issue?
|
||||
|
||||
There is an import from one module to another that is prohibited by the architectural constraints defined for the project.
|
||||
These constraints are established by the project maintainers in the architecture configuration file.
|
||||
|
||||
=== What is the potential impact?
|
||||
|
||||
Over time, codebases often drift from the intended project architecture,
|
||||
gradually degrading the code structure and misaligning it with the original design.
|
||||
|
||||
This misalignment reduces visibility and control over daily decisions affecting the architecture.
|
||||
As these small decisions accumulate, the codebase becomes harder to understand, and the architecture grows increasingly complex and unstructured.
|
||||
|
||||
== How to fix it
|
||||
|
||||
Refactor your source code to adhere to the architectural constraints.
|
||||
The specific approach will depend on your project architecture and the code not adhering to the constraints.
|
||||
For example, you might replace an import with an alternative import from another module
|
||||
or create a new function in the appropriate module to maintain a clean architecture.
|
||||
|
||||
=== Code examples
|
||||
|
||||
Assuming that modules in the directory `panels` should not directly access files in the directory `repos`:
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,python,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
# repos/order_repo.py
|
||||
class OrderRepo: ...
|
||||
|
||||
# panels/foo.py
|
||||
from repos.order_repo import OrderRepo # Noncompliant
|
||||
|
||||
def foo():
|
||||
repo = OrderRepo()
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,python,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
# repos/order_repo.py
|
||||
class OrderRepo: ...
|
||||
|
||||
# services/order_service.py
|
||||
from repos.order_repo import OrderRepo
|
||||
|
||||
class OrderService:
|
||||
def __init__(self):
|
||||
self.repo = OrderRepo()
|
||||
|
||||
# panels/foo.py
|
||||
from services.order_service import OrderService
|
||||
|
||||
def foo():
|
||||
repo = OrderService()
|
||||
----
|
||||
|
||||
=== Documentation
|
||||
|
||||
- Architectural Analysis Configuration for SonarQube
|
Loading…
x
Reference in New Issue
Block a user