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: max-imports #486

Closed
tizmagik opened this issue Aug 12, 2016 · 8 comments
Closed

Rule: max-imports #486

tizmagik opened this issue Aug 12, 2016 · 8 comments

Comments

@tizmagik
Copy link
Contributor

Curious what you would think about a max-imports rule. Usually if a module has, say, more than 10 imports or so, that is code smell and the module should be split up into smaller pieces.

Would you accept such a rule as a PR, or should such a rule live somewhere separately? Or does it already exist and I'm not aware? :)

@jfmengels
Copy link
Collaborator

Can be an interesting rule.

I'm guessing this would count both imports and requires. Would you count the number of modules, or functions imported. Like if you import the default and 2 named functions of a module, does that count as 1 or 3? I'd say its better to count it as 1.

@benmosher
Copy link
Member

I'd be up for this.

I agree with @jfmengels that it should count imported modules, not names. (though I could imagine having a parameter that limits names imported per-module, which would coerce you to import a namespace instead if you need more than X...)

@benmosher
Copy link
Member

benmosher commented Aug 12, 2016

name options:

  • import/max
  • import/limit

(something longer is fine, but I want to avoid restating import right of the /)

@tizmagik
Copy link
Contributor Author

Great! Yes agreed a shorter name probably makes more sense. I personally like import/max, I'll go with that for now. Will try and get a PR ready today or tomorrow, appreciate any help. Thanks!

@jfmengels
Copy link
Collaborator

I'd go for import/max-dependencies or import/max-imports or something, as max could be applied to many things (like max number of named imports for instance).

@benmosher
Copy link
Member

@jfmengels but wouldn't that be under the purview of this rule, though?

@jfmengels
Copy link
Collaborator

To me, this should only limit the number of modules/dependencies your file uses, not how you import it. If you want to use destructuring to use 10 lodash methods, that should still be counted as 1 dependency

@tizmagik
Copy link
Contributor Author

PR #489 ready for review.

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

No branches or pull requests

3 participants