-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
ESLint rule for enforcing order of require()
calls
#62
Comments
I just want to clear up some ambiguities:
This can mean You should specify ordering if multiple indexes are required. (index in another directory vs index in the same directory). Any value in further ordering the require calls within that grouping? Alphabetically? Or (my preference) stair-stepped: var fs = require('fs');
var events = require('events');
var childProcess = require('child-process');
var chalk = require('chalk');
var isPromise = require('is-promise');
var objectAssign = require('object-assign'); Finally, IMO this rule should work with ES2015 |
It doesn't really matter and no.
Updated the example.
Maybe alphabetically on the require string not the variable name? That way this would sort correctly: var apple = require('lodash/apple');
var pear = require('lodash/pear'); I don't really see the value in per-group stair-stepping. It creates for some noisy zigzagging. I think I prefer the randomness of alphabetic sorting instead. But happy to be convinced otherwise.
Ah yes. Definitely. |
I'm interested on working on this :)
I think it'd be nice if there was no further ordering by default, but that it could take a parameter allowing it (with built-in alphabetical, and why not stair case). Any thoughts on ordering the following? var foo = require('../../foo'); // relative in another directory
var bar = require('./bar'); // relative in the same directory
var bar = require('./bar/baz'); // relative in subdirectory from the same directory |
There isn't a whole lot, except it does give you visual clues as to group boundaries. I usually just stair-step everything instead of grouping the way you do. Not a big deal to me. Alphabetical is probably better anyways, it would be the easiest to explain to new users.
Hmm. Seems like that could cause confusion. I'm starting to think "ordering within ordered groups" is just going to be too much of a burden on contributors. |
We should definitely support the |
Alright. Let's just drop per-group ordering. I agree it would cause a lot of moot overhead for contributors. |
var foo = require('../../foo'); // relative in another directory
var moo = require('../../'); // index in another directory I find these two cases to be hardly different. The latter is an index in a strictly parent directory, while the former is not necessarily an index (but it can be, as it can point to |
✨ Tada! ✨ Let me know what you think if in the issues of the project: https://www.npmjs.com/package/eslint-plugin-import-order. |
@jfmengels Looks awesome! Thanks for taking on this 🎉🦄👍 Would you be interested in doing a PR to XO adding it there? See https://github.com/sindresorhus/xo/blob/master/config/plugins.js |
Sure, will do that later :) |
Woo! |
I need an ESLint plugin with a rule for enforcing the following order for
require
calls:If it ends up good, I plan to depend on it in XO.
Anyone interested?
I don't have time to mentor so probably better for someone with previous experience with AST's or strong willingness to learn :)
You can check if something is a builtin with https://github.com/sindresorhus/is-builtin-module.
// @jfmengels @twada @jamestalmage @dustinspecker
The text was updated successfully, but these errors were encountered: