Giter VIP home page Giter VIP logo

Comments (17)

jamestalmage avatar jamestalmage commented on May 21, 2024 2

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.

sindresorhus avatar sindresorhus commented on May 21, 2024 1

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.

sindresorhus avatar sindresorhus commented on May 21, 2024 1

@jfmengels I've been writing new modules with Node.js 4 as target for a while now.

from eslint-plugin-unicorn.

sindresorhus avatar sindresorhus commented on May 21, 2024

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.

sindresorhus avatar sindresorhus commented on May 21, 2024

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.

jfmengels avatar jfmengels commented on May 21, 2024

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.

sindresorhus avatar sindresorhus commented on May 21, 2024

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.

ayrton avatar ayrton commented on May 21, 2024

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.

jfmengels avatar jfmengels commented on May 21, 2024

@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.

sindresorhus avatar sindresorhus commented on May 21, 2024

That would be great! :)

Also needs to handle require().

from eslint-plugin-unicorn.

jfmengels avatar jfmengels commented on May 21, 2024

@ayrton Are you still up for making a PR for this? No worries if you are not.

from eslint-plugin-unicorn.

ayrton avatar ayrton commented on May 21, 2024

@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.

jfmengels avatar jfmengels commented on May 21, 2024

@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.

benmosher avatar benmosher commented on May 21, 2024

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.

jfmengels avatar jfmengels commented on May 21, 2024

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.

benmosher avatar benmosher commented on May 21, 2024

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.

jfmengels avatar jfmengels commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.