Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
New Rule suggestion: sort-dependencies #3143
TBD - to be discussed
The use case for the rule - what is it trying to prevent or flag? Include code examples.
This rule would flag unordered dependencies preferably configurable.
Default flagging: Symbols -> Upper case letters -> Lower case letters
Whether the rule is trying to prevent an error or is purely stylistic.
Why you believe this rule is generic enough to be included.
The rule would basically collect all dependencies and sort them. This is possible for both es5 and es6 using the same rule.
Whether the rule should be on or off by default.
Off by default
Thanks for the issue! We get a lot of issues, so this message is automatically posted to each one to help you check that you've included all of the information we need to help you.
Reporting a bug? Please be sure to include:
Requesting a new rule? Please be sure to include:
Requesting a feature? Please be sure to include:
Including this information in your issue helps us to triage it and get you a response as quickly as possible.
A common pattern is also for people to group dependencies and then sort within those groups. Eg. third party dependencies followed by a blank line and then local dependencies:
var _ = require('underscore'); var eslint = require('eslint'); var database = require('./database'); var fizzbuzzer = require('../fizzbuzzer');
It'd be nice if this theoretical rule had an option to only check groups of require statement that don't have blank lines between them.
I'm looking for a way to enforce the sorting of imports/requires based on grouping, not alphabetically.
var fs = require('fs'); // core var async = require('async'); // module var foo = require('./'); // main var bar = require('./foo'); // file var baz = require(getName()); // computed
Could this potentially be an option in
@necolas sorry, I'm not being very clear. What I'd like to know is how your pattern is expected to influence this issue? Are you saying we should implement your way of doing this? Are you saying there should be an option? Are you saying you wouldn't be able to use this rule but would like to?
I am not sure how relevant it is, but I wrote a node package that sorts ES6 imports (also look here for a better description. The order is customizable (although this mechanism is not really exposed at the moment). Maybe this can be used to implement the import sort rule and a corresponding auto fix.
@wmertens Sorry, the chance is very low, but not zero