GithubHelp home page GithubHelp logo

Comments (5)

scagood avatar scagood commented on June 16, 2024 1

If we want to convert n/file-extension-in-import to a recommended rule, can we create another issue for this please? ๐Ÿ™

from eslint-plugin-n.

aladdin-add avatar aladdin-add commented on June 16, 2024

well, I think it's time to rethink the rule. It was written when the node.js esm was not stabilized. Nowadays it's stabilized in node v12. time to make some changes.

  1. renaming to file-extension, and also check requires(common.js). the rule was only checking imports. but some devs may still want to use file extensions for some reasons.

  2. more configurable(easy to adopt if using ts/babel/esbuild/...):

"n/file-extension": [2, { "requires": "always", "imports": "always"}
  1. recommended preset changes:

    a. recommended-script:

"n/file-extension": [2, { "requires": "never"}
b. recommended-module:
"n/file-extension": [2, { "requires": "always", "imports": "always"}

from eslint-plugin-n.

aladdin-add avatar aladdin-add commented on June 16, 2024

do you mean the meta.docs.category?
https://github.com/weiran-zsd/eslint-plugin-node/blob/d7b975a07e1b876ca2c75597d054a81564b25685/lib/rules/file-extension-in-import.js#L40

it's not actually used anywhere, and eslint has removed it in all its core rules.

from eslint-plugin-n.

jimmywarting avatar jimmywarting commented on June 16, 2024

I think both of import(x) and require(x) should by default require file extensions

It don't hurt to use extension in CommonJS too. in fact it makes things faster to lookup and also easier for build tools to not having to 2nd guess what you meant to import. it only complicates things further and they need to apply to the same rule as node.js resolve algoritm over at: https://nodejs.org/dist/latest-v18.x/docs/api/modules.html#all-together (which is just insane)
Ryan dhal regretted all of it and it is not how the web/esm works.

more and more ppl are switching over to esm and refactor cjs to esm is no easy task as just simply switching out all require calls to import() and using the same path. it needs to solve the path to index.js as well.
If things where just require('./index.js') then it would be as simple as just changing it to an import statement and makeing an auto fix would be easier to write.

After reading The cost of many small modules i made a bench test that tried to require many files with and without file extension and using index.js vs just a normal name such as mod.js
And the script loaded faster if the path was more explicit as it did not have to stat files/folder to look up as many files to quickly figuring out what you ment to import

from eslint-plugin-n.

aladdin-add avatar aladdin-add commented on June 16, 2024

well, perf is a good point, but IMHO it do hurt DX. afaict, most node.js devs(like me lol.) are used to not writing it.

please note it's just a default, and it cannot meet everyone's wants. If it does not, you can always add your own config to overwrite it. ๐Ÿ˜„

from eslint-plugin-n.

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.