-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create rule S7197: Circular file imports should be resolved #4645
base: master
Are you sure you want to change the base?
Conversation
Quality Gate passed for 'rspec-tools'Issues Measures |
Quality Gate passed for 'rspec-frontend'Issues Measures |
@gabriel-vivas-sonarsource - rspec PR if you would like to review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're good. Added a few suggestions, feel free to use what makes sense to you.
@@ -0,0 +1,100 @@ | |||
This rule reports circular dependencies between source files caused by circular imports. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can mention that the rule detects both direct cycles and indirect cycles, as these can be less intuitive but more prevalent. The example we provide is an indirect one.
Perhaps something like:
- This rule reports circular dependencies between source files caused by circular imports.
+ This rule detects circular dependencies between files, including indirect cycles spanning multiple files.
|
||
=== Code examples | ||
|
||
==== Noncompliant code example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel the example is confusing and incomplete, this is also the case in Java IMO.
What do you think about something like this below (no clue if the ASCII diagram would work though).
Non-compliant:
// ┌──────┐ ┌──────┐
// │ A │ ─────▶ │ B │
// └──────┘ └──────┘
// ▲ │
// └───────────────┘
// main.js
import { A } from "./A.js";
A();
// A.js
import { B } from "./B.js";
export function A() {
console.log("A calls B");
B();
}
// B.js
import { A } from "./A.js";
export function B() {
console.log("B calls A");
A();
}
Compliant:
// ┌──────┐ ┌────────┐ ┌──────┐
// │ A │ ──▶ │ Shared │ ◀── │ B │
// └──────┘ └────────┘ └──────┘
// main.js
import { A } from "./A.js";
A();
// A.js
import { callB } from "./shared.js";
export function A() {
console.log("A calls B");
callB();
}
// B.js
import { callA } from "./shared.js";
export function B() {
console.log("B calls A");
callA();
}
// shared.js
import { A } from "./A.js";
import { B } from "./B.js";
export function callA() { A(); }
export function callB() { B(); }
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: