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

[no-commonjs] does not catch conditional require #1437

Closed
Pessimistress opened this issue Aug 3, 2019 · 5 comments · Fixed by #1439
Closed

[no-commonjs] does not catch conditional require #1437

Pessimistress opened this issue Aug 3, 2019 · 5 comments · Fixed by #1439

Comments

@Pessimistress
Copy link

The example here: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md#allow-require

cannot be reported even if allowRequire: false, because of this line:

https://github.com/benmosher/eslint-plugin-import/blob/1edbbd03ec636469328ad59da922ed7edc8cd36d/src/rules/no-commonjs.js#L90

The context scope is block in this case.

@ljharb
Copy link
Member

ljharb commented Aug 3, 2019

Looks like we need some failing test cases then, thanks.

@Pessimistress
Copy link
Author

@ljharb I can open a PR to fix this. However these test cases confuse me:

https://github.com/benmosher/eslint-plugin-import/blob/1edbbd03ec636469328ad59da922ed7edc8cd36d/tests/src/rules/no-commonjs.js#L31-L32

Is this by design? Should I add a new option if I want to strictly forbid any usage of require?

@ljharb
Copy link
Member

ljharb commented Aug 4, 2019

Yes, if you’d like to submit 2 PRs - one for this issue, and one to disallow all usage of require - please do.

@Pessimistress
Copy link
Author

Pessimistress commented Aug 4, 2019

I could theoretically fix my issue without breaking the current test cases, though shouldn't these two scenarios be treated the same?

var a = c && require("b")
if (c) {
  require("b")
}

@ljharb
Copy link
Member

ljharb commented Aug 4, 2019

Yes, in theory, but since they’re different scopes it’s not necessarily the same.

ljharb pushed a commit to Pessimistress/eslint-plugin-import that referenced this issue Dec 8, 2019
@ljharb ljharb closed this as completed in a60e5c6 Dec 8, 2019
marcusdarmstrong pushed a commit to marcusdarmstrong/eslint-plugin-import that referenced this issue Dec 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants