Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jan 31, 2025

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@github-actions github-actions bot added the jsts label Jan 31, 2025
@kaufco kaufco changed the title Create rule S7197 Create rule S7197: Circular file imports should be resolved Jan 31, 2025
@zglicz zglicz marked this pull request as ready for review February 3, 2025 12:48
@zglicz zglicz requested a review from a team February 3, 2025 12:48
Copy link

sonarqube-next bot commented Feb 3, 2025

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

sonarqube-next bot commented Feb 3, 2025

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@zglicz
Copy link
Contributor

zglicz commented Feb 3, 2025

@gabriel-vivas-sonarsource - rspec PR if you would like to review

Copy link
Contributor

@gabriel-vivas-sonarsource gabriel-vivas-sonarsource left a 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.
Copy link
Contributor

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
Copy link
Contributor

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(); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants