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

rule: no-cycle #1052

Merged
merged 8 commits into from
Mar 30, 2018
Merged

rule: no-cycle #1052

merged 8 commits into from
Mar 30, 2018

Conversation

benmosher
Copy link
Member

Rule implementation for #941.

I need to do a final smoke test locally before merging, but wanted to open this up for implementation/docs/tests comments. Most notably, this first draft won't detect cycles introduced by deep requires. It will only lint require calls that import modules that import modules.

@benmosher benmosher requested a review from ljharb March 26, 2018 11:06
@coveralls
Copy link

coveralls commented Mar 26, 2018

Coverage Status

Coverage increased (+0.03%) to 96.264% when pulling ad66aea on no-cycles into 1eac942 on master.

### Options

By default, this rule only detects cycles for ES6 imports, but see the [`no-unresolved` options](./no-unresolved.md#options) as this rule also supports the same `commonjs` and `amd` flags. However, these flags only impact which import types are _linted_; the
import/export infrastructure only registers `import` statements in dependencies, so
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems super important that this can detect requires as well as imports. What’s involved in making that happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I knew you'd pick up on that as I realized it and wrote it out. 😅

Right now, all the normal static analysis inspection of dependencies only picks up imports/exports from the topmost scope of the module.

Could also potentially nab any single-argument requires that are either alone or in AssignmentExpressions but everything gets dicier once requires are in the mix, since they could be present in any scope in the module, technically.

I want to avoid blocking merging and shipping this on supporting deep registration of CJS requires, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use an ast selector like CallExpression[callee.name=“require”] for the visitor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure. That's certainly what the moduleVisitor implementation does to find and lint requires.

It would be a substantial improvement, and I think I am probably overstating the complexity. I'll try to take a second look.


export function bar() {
return "side effects???"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nbd ofc but missing a trailing newline

filename: testFilePath('./cycles/depth-zero.js'),
}))

describe.only("no-cycle", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only probably needs to be removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agh! yep 🤕

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

Successfully merging this pull request may close these issues.

3 participants