Comments (17)
My thought is that most of what I work on still supports 0.12
, and will need to for the next 12 months.
.
vs ./
isn't that big of deal, but it would be nice to call out ./index
and ./index.js
.
Either way, the rule should also handle relative references to index.js
:
../../index.js
->../../
from eslint-plugin-unicorn.
No point in supporting nor having an option for 0.12 at this point. Really! Even ESLint has dropped support for it.
from eslint-plugin-unicorn.
@jfmengels I've been writing new modules with Node.js 4 as target for a while now.
from eslint-plugin-unicorn.
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 esnext
in XO for now.
from eslint-plugin-unicorn.
Alright. So how about we fail on ./index
and ./index.js
and allow .
and ./
, but in a year we change it to only .
?
from eslint-plugin-unicorn.
If it gets in XO with esnext
and not as the default, I don't see why it couldn't be .
already. Or give it an option to prefer ./
or .
, that way, we won't have to change it in a year and "migrate" the codebases that use esnext
.
from eslint-plugin-unicorn.
Or give it an option to prefer ./ or ., that way, we won't have to change it in a year and "migrate" the codebases that use esnext.
I was hoping to not need an option, but I agree with @jfmengels. That sounds like the best solution. Should default to .
, so we can just remove the option in a year.
from eslint-plugin-unicorn.
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) + '`');
}
}
}
}
from eslint-plugin-unicorn.
@ayrton Great! And yes, please make a PR :)
A few remarks already though:
- We would like support for
require
too - You don't handle the case of
./index
Thanks for doing this!
from eslint-plugin-unicorn.
That would be great! :)
Also needs to handle require()
.
from eslint-plugin-unicorn.
@ayrton Are you still up for making a PR for this? No worries if you are not.
from eslint-plugin-unicorn.
@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.
from eslint-plugin-unicorn.
@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 eslint-plugin-import
a bit, I think this would be a better fit there. What do you think @benmosher?
from eslint-plugin-unicorn.
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 .
or also ./foo
?
from eslint-plugin-unicorn.
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.) ..
vs ../
.
I'd make this more generic and also apply it to ./foo
, to prevent ./foo/
, ./foo/index
or ./foo/index.js
, but the index (also parent index?) is a bit special as .
is not valid in 0.12.
from eslint-plugin-unicorn.
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 ./
+../
exceptions behind a flag, if anything, just for consistency.
from eslint-plugin-unicorn.
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?
from eslint-plugin-unicorn.
Related Issues (20)
- `no-array-callback-reference` false positive when using ternary
- `prefer-string-slice` bad autofix from `.substr()`
- `prevent-abbreviations` - non-ASCII characters ignored in filenames HOT 1
- `prefer-node-protocol` should not flag non-node imports HOT 2
- `unicorn/no-array-callback-reference` does not report when optional chaining HOT 1
- Rule change proposal: `no-useless-undefined` add option to skip checking function body
- `prefer-spread` should not report on optional chaining HOT 1
- Override dont work when change only configuration HOT 2
- Reconsider `no-document-cookie` enabled by default HOT 7
- Missing rules in plugin HOT 1
- `multipleFileExtensions` in `unicorn/filename-case` is not working correctly with eslint flat config
- prefer-dom-node-dataset: bad fix for playwright
- Rule proposal: `.replace` or `.replaceAll` with non-literal replacement HOT 3
- filename-case: pascalCase should allow stuff like FAQPage.js
- Don't prefer number properties for Infinity by default HOT 5
- Fix for '/|/g can be optimized to //g' in the better-regex rule breaks regular expression syntax
- `prefer-number-properties` changes HOT 1
- Rule proposal: `require-css-escape` HOT 1
- support calver in package.json error HOT 1
- Check `throw Object.assign(Error('...'), ...)` in `throw-new-error`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-unicorn.