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
Enforce import index style #9
Comments
I don't see the point in an option. 0.12 is already being phased out. It went into maintenance mode early this month. I'd rather have a simple rule without any options that we can add to |
My thought is that most of what I work on still supports
Either way, the rule should also handle relative references to
|
Alright. So how about we fail on |
If it gets in XO with |
I was hoping to not need an option, but I agree with @jfmengels. That sounds like the best solution. Should default to |
I wrote this earlier today for closed project, happy to open a PR: module.exports = function(context) {
return {
'ImportDeclaration': function(node) {
if (node.source.value.slice(-1) === '/') {
context.report(node, 'Omit trailing slashes in your imports. Rename to `' + node.source.value.slice(0, -1) + '`');
}
if (node.source.value.match(/\/index\.js/)) {
var index = node.source.value.indexOf('/index.js')
context.report(node, 'Omit `/index.js` in your imports. Rename to `' + node.source.value.slice(0, index) + '`');
}
}
}
} |
@ayrton Great! And yes, please make a PR :) A few remarks already though:
Thanks for doing this! |
That would be great! :) Also needs to handle |
@ayrton Are you still up for making a PR for this? No worries if you are not. |
@jfmengels I'm currently on holiday - so wouldn't mind if someone took over. Won't be able to work on it for another two weeks. |
@ayrton Sure, no problem. Maybe I'll tackle this, maybe I won't, you'll see when you come back 😄 Enjoy the holidays! Now that I think about it and that we've worked with |
Sounds like: import-js/eslint-plugin-import#394 which I'm up for. I skimmed this thread, but is what you're looking for applicable only to |
Hah. I actually 👍'd that one. Totally slipped my mind. Originally, this issue is only for the index of the current folder. Now that you mention it, the same will be applicable to the parent (or its parent, etc.) I'd make this more generic and also apply it to |
I'd be inclined not to support 0.12 since it's August, now. The majority of this thread is from before 0.12 phased into maintenance mode, IIRC. I could go either way, though. Would probably want the default to be 0.12-ignorant and put |
No point in supporting nor having an option for 0.12 at this point. Really! Even ESLint has dropped support for it. |
True. And if it does, they can disable this rule. 👍 @sindresorhus Does that mean you'll start writing packages in Node v4 ES6 code from now on? Or soon? |
@jfmengels I've been writing new modules with Node.js 4 as target for a while now. |
I want to enforce
require('.');
andfrom '.';
. Before Node.js 4 you had to do'./'
. In Node.js 4 you can do:'.'
.Should catch the following cases:
'./'
'./index'
'./index.js'
Should be easy to implement auto-fixing for this rule.
The text was updated successfully, but these errors were encountered: