-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[New] add enforce-node-protocol-usage
rule
#3024
[New] add enforce-node-protocol-usage
rule
#3024
Conversation
…` setting Co-authored-by: Mikhail Pertsev <mikhail.pertsev@brightpattern.com> Co-authored-by: sevenc-nanashi <sevenc7c@sevenc7c.com>
d728d5c
to
968e562
Compare
@GoldStrikeArch are you still interested in completing this PR? |
Yeah, forgot about this. I will try to finish it on this weekend |
Any updates on this PR? I'm very excited about this rule. (I'd like to take over this PR if needed) |
@sevenc-nanashi if you'd like to do so, please do NOT make a new PR - instead, comment here with a link to your branch containing this PR, rebased and updated per #3024 (comment), and i'll pull in the changes. |
@ljharb
I think the name should be |
@sevenc-nanashi i don't think it should have "prefer" in it at all, because the rule won't be expressing an opinion that using, or avoiding, the protocol is preferred, but I agree that "node protocol" is better wording. Perhaps |
@ljharb I renamed to |
enforce-node-protocol-usage
rule
The rule should either default to “never” - the far more universal behavior - or have no default at all. The docs will need a lot of work too - deno and hun only support the protocol, i believe, so you’d want to set the rule to “always”; if you’re supporting a node version, bundler, or tool that doesn’t understand the node protocol, you’d want to set it to “never”. Additionally, prefix-only core modules, like node:test, node:sea, node:sqlite, etc need to remain unaffected by the “never” setting. Although, because module.builtinModules doesn’t include prefix-only modules, you may not need to do anything here but add test cases. |
@ljharb
|
968e562
to
e897498
Compare
k, i've pulled in and rebased the changes. I also made it use is-core-module since module.builtinModules isn't available in older node versions. |
@sevenc-nanashi i haven't reviewed the tests yet; assuming that every module being tested is tested with both configurations, and that eg |
e897498
to
8b62c8b
Compare
@ljharb I made some changes:
|
8b62c8b
to
7dccf82
Compare
hmm, lots of the tests are failing for me locally, but i'm not sure why. the logic seems correct. |
@ljharb Looks like the issue caused by the guard of visitor. The fixdiff --git a/src/rules/enforce-node-protocol-usage.js b/src/rules/enforce-node-protocol-usage.js
index f8f3ee39..548f303b 100644
--- a/src/rules/enforce-node-protocol-usage.js
+++ b/src/rules/enforce-node-protocol-usage.js
@@ -96,11 +96,16 @@ module.exports = {
url: docsUrl('enforce-node-protocol-usage'),
},
fixable: 'code',
- schema: [
- {
- enum: ['always', 'never'],
- },
- ],
+ schema: {
+ type: 'array',
+ minItems: 1,
+ maxItems: 1,
+ items: [
+ {
+ enum: ['always', 'never'],
+ },
+ ],
+ },
messages,
},
create(context) {
@@ -115,18 +120,12 @@ module.exports = {
return checkAndReport(arg, context);
},
ExportNamedDeclaration(node) {
- if (!isStringLiteral(node)) { return; }
-
return checkAndReport(node.source, context);
},
ImportDeclaration(node) {
- if (!isStringLiteral(node)) { return; }
-
return checkAndReport(node.source, context);
},
ImportExpression(node) {
- if (!isStringLiteral(node)) { return; }
-
return checkAndReport(node.source, context);
},
}; In my environment, all tests passed with this patch. |
3459368
to
165fb3b
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
d11494f
to
1f38d1b
Compare
So one thing to note: the list of core modules is dependent on the node version that eslint is running in. I think perhaps it might make sense to add a |
1f38d1b
to
ad0d6f5
Compare
ok, updated. lmk what yall think |
8d2e510
to
d7bafc3
Compare
6e08655
to
a77f197
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3024 +/- ##
==========================================
+ Coverage 94.72% 95.10% +0.37%
==========================================
Files 83 84 +1
Lines 3583 3634 +51
Branches 1252 1279 +27
==========================================
+ Hits 3394 3456 +62
+ Misses 189 178 -11 ☔ View full report in Codecov by Sentry. |
a77f197
to
8c8058c
Compare
Fixes #2717
Added a new rule
prefer-node-builtin-imports
.All test cases are taken from eslint-plugin-unicorn_test