-
-
Notifications
You must be signed in to change notification settings - Fork 400
Add prefer-import-meta-properties
rule
#2607
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
Add prefer-import-meta-properties
rule
#2607
Conversation
I realized that |
I have changed this PR. |
|
Thank you! |
rules/prefer-module.js
Outdated
const fix = fixer => | ||
fixer.replaceText(node, `import.meta.${name}`); | ||
|
||
if (filename.endsWith('.mjs')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should import.meta
already ensure these files are in ESM? Why this check needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we give the community some time to drop Node.js 18, and add an option instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right, no need to check for mjs 😓
It's definitely an ESM because it already uses import.meta
.
I'll change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we give the community some time to drop Node.js 18, and add an option instead?
With Node v18 reaching EOL next month, I'm not sure if it should be an option 😅
Thank you for your review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ota-meshi Please take a look
Thank you for reviewing this PR! |
Pushed some commits, most of them are making all kinds of check stricter and improve readability. |
Due to bug in |
I think it's the same test case as L406, and I think it's intentional. Any suggestions on how to fix it 🤔 |
Sorry, I was wrong about it. |
Everything looks good to me, except one thing. Do you think it's possible that we break this case?
Since |
Also, about this
Your answer make sense to me
But I don't want people to disable this rule only because their target environment doesn't have Personally, I even prefer add this PR as a separate rule, this part also not technically "prefer-module".
@sindresorhus What do you think? |
Thank you for your comment, I didn't know it would return different results for Windows paths 😅 |
By the way, originally I wanted a rule to be added to convert |
It could be a separate rule, but isn't it easier just to keep it in here under an option? We still want this rule to enforce not using |
We already provide both If the new rule enabled, it doesn't matter which one user choose, user will end up using Since you are not against seperate rule, let's do it. My suggestion for rule name is |
👍 I will change this PR to add the new rule. |
prefer-module
: Support import.meta.{dirname,filename}
prefer-import-meta-properties
rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Thank you!
This PR adds
prefer-import-meta-properties
rule that reports the following code:close #2255