Create rule S7134: Architectural constraints should not be violated (JavaScript) (#4646)
* Add javascript to rule S7134 * Create rule S7134: Architectural constraints should not be violated (JavaScript) * Gab's comments --------- Co-authored-by: kaufco <kaufco@users.noreply.github.com> Co-authored-by: Marco Kaufmann <marco.kaufmann@sonarsource.com> Co-authored-by: zglicz <michal.zgliczynski@sonarsource.com>
This commit is contained in:
parent
36d247fb3b
commit
d9a7e045e9
@ -1,25 +1,2 @@
|
||||
{
|
||||
"title": "Architectural constraints should not be violated",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "0min"
|
||||
},
|
||||
"tags": [
|
||||
"architecture",
|
||||
"design"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-7134",
|
||||
"sqKey": "S7134",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "infeasible",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "HIGH"
|
||||
},
|
||||
"attribute": "MODULAR"
|
||||
}
|
||||
}
|
||||
|
2
rules/S7134/javascript/metadata.json
Normal file
2
rules/S7134/javascript/metadata.json
Normal file
@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
65
rules/S7134/javascript/rule.adoc
Normal file
65
rules/S7134/javascript/rule.adoc
Normal file
@ -0,0 +1,65 @@
|
||||
This rule reports when a source file does not adhere to the architectural constraints defined for a project.
|
||||
|
||||
== Why is this an issue?
|
||||
|
||||
There is an import from one source file 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 files in the directory `./src/panels` should not directly access files in the directory `./src/repos`:
|
||||
|
||||
==== Noncompliant code example
|
||||
|
||||
[source,javascript,diff-id=1,diff-type=noncompliant]
|
||||
----
|
||||
// ./src/panels/showCustomersPanel.js
|
||||
import { CustomerRepo } from '../repos/customerRepo.js';
|
||||
|
||||
class ShowCustomersPanel {
|
||||
constructor() {
|
||||
this.customerRepo = new CustomerRepo();
|
||||
}
|
||||
|
||||
getCustomers() {
|
||||
return this.customerRepo.findAll();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
==== Compliant solution
|
||||
|
||||
[source,javascript,diff-id=1,diff-type=compliant]
|
||||
----
|
||||
// ./src/panels/showCustomersPanel.js
|
||||
import { CustomerService } from '../services/customerService.js';
|
||||
|
||||
class ShowCustomersPanel {
|
||||
constructor() {
|
||||
this.customerService = new CustomerService();
|
||||
}
|
||||
|
||||
getCustomers() {
|
||||
return this.customerService.getAllCustomers();
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
=== Documentation
|
||||
|
||||
- Defining architectural constraints for SonarQube
|
@ -1,2 +1,25 @@
|
||||
{
|
||||
"title": "Architectural constraints should not be violated",
|
||||
"type": "CODE_SMELL",
|
||||
"status": "ready",
|
||||
"remediation": {
|
||||
"func": "Constant\/Issue",
|
||||
"constantCost": "0min"
|
||||
},
|
||||
"tags": [
|
||||
"architecture",
|
||||
"design"
|
||||
],
|
||||
"defaultSeverity": "Major",
|
||||
"ruleSpecification": "RSPEC-7134",
|
||||
"sqKey": "S7134",
|
||||
"scope": "All",
|
||||
"defaultQualityProfiles": ["Sonar way"],
|
||||
"quickfix": "infeasible",
|
||||
"code": {
|
||||
"impacts": {
|
||||
"MAINTAINABILITY": "HIGH"
|
||||
},
|
||||
"attribute": "MODULAR"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user