63 lines
2.0 KiB
Plaintext
63 lines
2.0 KiB
Plaintext
This rule reports when a class, package or other source code component violates the architectural constraints defined for a project.
|
|
|
|
== Why is this an issue?
|
|
|
|
There is a reference from one source code component to another that is prohibited by the architectural constraints defined for the project.
|
|
These definitions are made by the maintainers of the project 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 violating the constraints.
|
|
For example, you might replace a function call with an alternative function call from another software layer
|
|
or create a new function in that layer to maintain a clean architecture.
|
|
|
|
=== Code examples
|
|
|
|
Assuming that for source code components in directory `./src/main/com/example/panels`, access to
|
|
components in directory `./src/main/com/example/repos` is constrained:
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
package com.example.panels;
|
|
|
|
import com.example.repos.CustomerRepo;
|
|
|
|
class ShowCustomersPanel extends Panel {
|
|
|
|
CustomerRepo customerRepo = ...;
|
|
|
|
List<Customer> customers = customerRepo.findAll();
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
package com.example.panels;
|
|
|
|
import com.example.services.CustomerService;
|
|
|
|
class ShowCustomersPanel extends Panel {
|
|
|
|
CustomerService customerService = ...;
|
|
|
|
List<Customer> customers = customerService.getAllCustomers();
|
|
}
|
|
----
|
|
|
|
=== Documentation
|
|
|
|
- Defining architectural constraints for SonarQube
|