Skip to content

Commit c28a086

Browse files
authoredApr 3, 2024··
import-style: Support node: protocol (#2297)
1 parent 677af7f commit c28a086

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed
 

‎rules/import-style.js

+6
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ const defaultStyles = {
117117
path: {
118118
default: true,
119119
},
120+
'node:path': {
121+
default: true,
122+
},
120123
util: {
121124
named: true,
122125
},
126+
'node:util': {
127+
named: true,
128+
},
123129
};
124130

125131
/** @param {import('eslint').Rule.RuleContext} context */

‎test/import-style.mjs

+45
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,18 @@ test({
121121
code: 'import {inspect} from \'util\'',
122122
options: [],
123123
},
124+
{
125+
code: 'import {inspect} from \'node:util\'',
126+
options: [],
127+
},
124128
{
125129
code: 'const {inspect} = require(\'util\')',
126130
options: [],
127131
},
132+
{
133+
code: 'const {inspect} = require(\'node:util\')',
134+
options: [],
135+
},
128136
{
129137
code: 'import chalk from \'chalk\'',
130138
options: [],
@@ -137,10 +145,18 @@ test({
137145
code: 'const {inspect} = require(\'util\')',
138146
options: [],
139147
},
148+
{
149+
code: 'const {inspect} = require(\'node:util\')',
150+
options: [],
151+
},
140152
{
141153
code: 'export {promisify, callbackify} from \'util\'',
142154
options: [],
143155
},
156+
{
157+
code: 'export {promisify, callbackify} from \'node:util\'',
158+
options: [],
159+
},
144160

145161
{
146162
code: 'require(\'chalk\')',
@@ -538,26 +554,51 @@ test({
538554
options: [],
539555
errors: [{}],
540556
},
557+
{
558+
code: 'import util from \'node:util\'',
559+
options: [],
560+
errors: [{}],
561+
},
541562
{
542563
code: 'import * as util from \'util\'',
543564
options: [],
544565
errors: [{}],
545566
},
567+
{
568+
code: 'import * as util from \'node:util\'',
569+
options: [],
570+
errors: [{}],
571+
},
546572
{
547573
code: 'const util = require(\'util\')',
548574
options: [],
549575
errors: [{}],
550576
},
577+
{
578+
code: 'const util = require(\'node:util\')',
579+
options: [],
580+
errors: [{}],
581+
},
551582
{
552583
code: 'require(\'util\')',
553584
options: [],
554585
errors: [{}],
555586
},
587+
{
588+
code: 'require(\'node:util\')',
589+
options: [],
590+
errors: [{}],
591+
},
556592
{
557593
code: 'require(\'ut\' + \'il\')',
558594
options: [],
559595
errors: [{}],
560596
},
597+
{
598+
code: 'require(\'node:\' + \'util\')',
599+
options: [],
600+
errors: [{}],
601+
},
561602
{
562603
code: 'import {red} from \'chalk\'',
563604
options: [],
@@ -626,9 +667,13 @@ test.snapshot({
626667
],
627668
invalid: [
628669
'import util from \'util\'',
670+
'import util from \'node:util\'',
629671
'import * as util from \'util\'',
672+
'import * as util from \'node:util\'',
630673
'const util = require(\'util\')',
674+
'const util = require(\'node:util\')',
631675
'require(\'util\')',
676+
'require(\'node:util\')',
632677
'import {red} from \'chalk\'',
633678
'import {red as green} from \'chalk\'',
634679
outdent`

‎test/snapshots/import-style.mjs.md

+66-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,22 @@ Generated by [AVA](https://avajs.dev).
1919
| ^^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`util\`.␊
2020
`
2121

22-
## invalid(2): import * as util from 'util'
22+
## invalid(2): import util from 'node:util'
23+
24+
> Input
25+
26+
`␊
27+
1 | import util from 'node:util'␊
28+
`
29+
30+
> Error 1/1
31+
32+
`␊
33+
> 1 | import util from 'node:util'␊
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`node:util\`.␊
35+
`
36+
37+
## invalid(3): import * as util from 'util'
2338

2439
> Input
2540
@@ -34,7 +49,22 @@ Generated by [AVA](https://avajs.dev).
3449
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`util\`.␊
3550
`
3651

37-
## invalid(3): const util = require('util')
52+
## invalid(4): import * as util from 'node:util'
53+
54+
> Input
55+
56+
`␊
57+
1 | import * as util from 'node:util'␊
58+
`
59+
60+
> Error 1/1
61+
62+
`␊
63+
> 1 | import * as util from 'node:util'␊
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`node:util\`.␊
65+
`
66+
67+
## invalid(5): const util = require('util')
3868

3969
> Input
4070
@@ -49,7 +79,22 @@ Generated by [AVA](https://avajs.dev).
4979
| ^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`util\`.␊
5080
`
5181

52-
## invalid(4): require('util')
82+
## invalid(6): const util = require('node:util')
83+
84+
> Input
85+
86+
`␊
87+
1 | const util = require('node:util')␊
88+
`
89+
90+
> Error 1/1
91+
92+
`␊
93+
> 1 | const util = require('node:util')␊
94+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use named import for module \`node:util\`.␊
95+
`
96+
97+
## invalid(7): require('util')
5398

5499
> Input
55100
@@ -64,7 +109,22 @@ Generated by [AVA](https://avajs.dev).
64109
| ^^^^^^^^^^^^^^^ Use named import for module \`util\`.␊
65110
`
66111

67-
## invalid(5): import {red} from 'chalk'
112+
## invalid(8): require('node:util')
113+
114+
> Input
115+
116+
`␊
117+
1 | require('node:util')␊
118+
`
119+
120+
> Error 1/1
121+
122+
`␊
123+
> 1 | require('node:util')␊
124+
| ^^^^^^^^^^^^^^^^^^^^ Use named import for module \`node:util\`.␊
125+
`
126+
127+
## invalid(9): import {red} from 'chalk'
68128

69129
> Input
70130
@@ -79,7 +139,7 @@ Generated by [AVA](https://avajs.dev).
79139
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Use default import for module \`chalk\`.␊
80140
`
81141

82-
## invalid(6): import {red as green} from 'chalk'
142+
## invalid(10): import {red as green} from 'chalk'
83143

84144
> Input
85145
@@ -94,7 +154,7 @@ Generated by [AVA](https://avajs.dev).
94154
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use default import for module \`chalk\`.␊
95155
`
96156

97-
## invalid(7): async () => { const {red} = await import('chalk'); }
157+
## invalid(11): async () => { const {red} = await import('chalk'); }
98158

99159
> Input
100160

‎test/snapshots/import-style.mjs.snap

110 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.