Giter Site home page Giter Site logo

Comments (9)

tpluscode avatar tpluscode commented on July 18, 2024 1

Sorry, I expressed myself poorly. IMO, the plugin behaves as expected: it adds extension to an import.

I suppose it could be implemented to check for the existence of ./index.(ts|js) and fix accordingly. I would just propose to cater for the edge case where both ./externalTypes.ts and ./externalTypes/index.ts exist. In such case there should be no auto-fix to ensure that the correct alternative is chose.

from eslint-plugin-require-extensions.

tpluscode avatar tpluscode commented on July 18, 2024 1

Just a quick not before I forget. Rather than checking for the index.?? file, the code would better check whether the given path is a dir and in such case append /index.js, which would equally work for JS and TS.

Would still fail for index.mjs but that might be a rare case, requiring manual fix

from eslint-plugin-require-extensions.

tpluscode avatar tpluscode commented on July 18, 2024

Are you sure that import * from ./externalTypes is a valid ES import? I would think that for relative paths they must be exact.

The extensionless modules are only valid when importing a module explicitly listed in package.json exports

from eslint-plugin-require-extensions.

trevor-scheer avatar trevor-scheer commented on July 18, 2024

I'm not sure I understand your question. My understanding is that this plugin exists to lint against and correct invalid imports which are missing the extension.

So directly, no, import * from ./externalTypes is not a valid ES import (since it has no extension). But this plugin is here to detect and correct it to the right thing (which I am very happy about).

What I'm suggesting is that the autofix behavior is incorrect for this scenario. The fixer needs to be aware of the existence of the file. If it doesn't exist, it should look to see if there's an index file in that path and use it appropriately.

So, since there is no actual externalTypes.js file, it should then look for an externalTypes/index file and use that in the fix if it exists. Hopefully that makes sense, let me know if anything is unclear.

from eslint-plugin-require-extensions.

trevor-scheer avatar trevor-scheer commented on July 18, 2024

Agreed. I'm not sure if or when I'd get to it, but would you be open to a PR that implements that? If the answer is yes and someone beats me to it that's fine too 😄

from eslint-plugin-require-extensions.

tpluscode avatar tpluscode commented on July 18, 2024

I'm not the author here. I just opened another PR myself recently. Not saying I would not open the PR but no promises ;)

from eslint-plugin-require-extensions.

trevor-scheer avatar trevor-scheer commented on July 18, 2024

Oh, whoops! I just assumed. Thanks for letting me know.

from eslint-plugin-require-extensions.

jordaaash avatar jordaaash commented on July 18, 2024

#3 (comment)

@tpluscode's fix for non-JS imports was just merged and released. I think a slightly modified approach could work for this issue also. I personally use index imports and run into this quite a bit.

from eslint-plugin-require-extensions.

tpluscode avatar tpluscode commented on July 18, 2024

I use index import too. One that I added your plugin to my base config I'm surely going to hit this issue on occasion.

Happy to submit a PR when this happens

from eslint-plugin-require-extensions.

Related Issues (8)

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.