Skip to content

Commit 7816928

Browse files
committed
Broken case
1 parent f97138d commit 7816928

File tree

3 files changed

+43
-87
lines changed

3 files changed

+43
-87
lines changed

test/prefer-module.js

+4
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ test.snapshot({
407407
import path from "path";
408408
const dirname = path.dirname(new URL(import.meta.url).pathname);
409409
`,
410+
outdent`
411+
import path from "path";
412+
const not_dirname = path.dirname(new URL(import.meta.url).pathname);
413+
`,
410414
outdent`
411415
import { fileURLToPath } from "url";
412416
const dirname = fileURLToPath(new URL(".", import.meta.url));

test/snapshots/prefer-module.js.md

+39-87
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,31 @@ Generated by [AVA](https://avajs.dev).
19901990
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
19911991
`
19921992

1993-
## invalid(4): import { fileURLToPath } from "url"; const dirname = fileURLToPath(new URL(".", import.meta.url));
1993+
## invalid(4): import path from "path"; const not_dirname = path.dirname(new URL(import.meta.url).pathname);
1994+
1995+
> Input
1996+
1997+
`␊
1998+
1 | import path from "path";␊
1999+
2 | const not_dirname = path.dirname(new URL(import.meta.url).pathname);␊
2000+
`
2001+
2002+
> Output
2003+
2004+
`␊
2005+
1 | import path from "path";␊
2006+
2 | const not_dirname = import.meta.dirname;␊
2007+
`
2008+
2009+
> Error 1/1
2010+
2011+
`␊
2012+
1 | import path from "path";␊
2013+
> 2 | const not_dirname = path.dirname(new URL(import.meta.url).pathname);␊
2014+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
2015+
`
2016+
2017+
## invalid(5): import { fileURLToPath } from "url"; const dirname = fileURLToPath(new URL(".", import.meta.url));
19942018

19952019
> Input
19962020
@@ -2014,7 +2038,7 @@ Generated by [AVA](https://avajs.dev).
20142038
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
20152039
`
20162040

2017-
## invalid(5): import { fileURLToPath } from "url"; const dirname = fileURLToPath(new URL("./", import.meta.url));
2041+
## invalid(6): import { fileURLToPath } from "url"; const dirname = fileURLToPath(new URL("./", import.meta.url));
20182042

20192043
> Input
20202044
@@ -2038,7 +2062,7 @@ Generated by [AVA](https://avajs.dev).
20382062
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
20392063
`
20402064

2041-
## invalid(6): import { fileURLToPath } from "url"; const filename = fileURLToPath(import.meta.url);
2065+
## invalid(7): import { fileURLToPath } from "url"; const filename = fileURLToPath(import.meta.url);
20422066

20432067
> Input
20442068
@@ -2062,7 +2086,7 @@ Generated by [AVA](https://avajs.dev).
20622086
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
20632087
`
20642088

2065-
## invalid(7): import { fileURLToPath } from "url"; const filename = fileURLToPath(new URL(import.meta.url));
2089+
## invalid(8): import { fileURLToPath } from "url"; const filename = fileURLToPath(new URL(import.meta.url));
20662090

20672091
> Input
20682092
@@ -2086,7 +2110,7 @@ Generated by [AVA](https://avajs.dev).
20862110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
20872111
`
20882112

2089-
## invalid(8): import path from "node:path"; import { fileURLToPath } from "node:url"; const dirname = path.dirname(fileURLToPath(import.meta.url));
2113+
## invalid(9): import path from "node:path"; import { fileURLToPath } from "node:url"; const dirname = path.dirname(fileURLToPath(import.meta.url));
20902114

20912115
> Input
20922116
@@ -2113,7 +2137,7 @@ Generated by [AVA](https://avajs.dev).
21132137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
21142138
`
21152139

2116-
## invalid(9): import { fileURLToPath } from "node:url"; const filename = fileURLToPath(import.meta.url);
2140+
## invalid(10): import { fileURLToPath } from "node:url"; const filename = fileURLToPath(import.meta.url);
21172141

21182142
> Input
21192143
@@ -2137,7 +2161,7 @@ Generated by [AVA](https://avajs.dev).
21372161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
21382162
`
21392163

2140-
## invalid(10): import * as path from "node:path"; import url from "node:url"; const dirname = path.dirname(url.fileURLToPath(import.meta.url));
2164+
## invalid(11): import * as path from "node:path"; import url from "node:url"; const dirname = path.dirname(url.fileURLToPath(import.meta.url));
21412165

21422166
> Input
21432167
@@ -2164,7 +2188,7 @@ Generated by [AVA](https://avajs.dev).
21642188
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
21652189
`
21662190

2167-
## invalid(11): import url from "node:url"; const filename = url.fileURLToPath(import.meta.url);
2191+
## invalid(12): import url from "node:url"; const filename = url.fileURLToPath(import.meta.url);
21682192

21692193
> Input
21702194
@@ -2188,7 +2212,7 @@ Generated by [AVA](https://avajs.dev).
21882212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
21892213
`
21902214

2191-
## invalid(12): import path from "node:path"; import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename);
2215+
## invalid(13): import path from "node:path"; import { fileURLToPath } from "node:url"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename);
21922216

21932217
> Input
21942218
@@ -2228,7 +2252,7 @@ Generated by [AVA](https://avajs.dev).
22282252
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
22292253
`
22302254

2231-
## invalid(13): import path from "node:path"; const __filename = new URL(import.meta.url).pathname; const __dirname = path.dirname(__filename);
2255+
## invalid(14): import path from "node:path"; const __filename = new URL(import.meta.url).pathname; const __dirname = path.dirname(__filename);
22322256

22332257
> Input
22342258
@@ -2255,7 +2279,7 @@ Generated by [AVA](https://avajs.dev).
22552279
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
22562280
`
22572281

2258-
## invalid(14): import path from "node:path"; const __filename = import.meta.filename; const __dirname = path.dirname(__filename);
2282+
## invalid(15): import path from "node:path"; const __filename = import.meta.filename; const __dirname = path.dirname(__filename);
22592283

22602284
> Input
22612285
@@ -2282,7 +2306,7 @@ Generated by [AVA](https://avajs.dev).
22822306
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
22832307
`
22842308

2285-
## invalid(15): const path = process.getBuiltinModule("node:path"); const { fileURLToPath } = process.getBuiltinModule("node:url"); const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename);
2309+
## invalid(16): const path = process.getBuiltinModule("node:path"); const { fileURLToPath } = process.getBuiltinModule("node:url"); const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename);
22862310

22872311
> Input
22882312
@@ -2322,7 +2346,7 @@ Generated by [AVA](https://avajs.dev).
23222346
| ^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
23232347
`
23242348

2325-
## invalid(16): const { fileURLToPath: renamed } = process.getBuiltinModule("node:url"); const filename = renamed(import.meta.url);
2349+
## invalid(17): const { fileURLToPath: renamed } = process.getBuiltinModule("node:url"); const filename = renamed(import.meta.url);
23262350

23272351
> Input
23282352
@@ -2346,79 +2370,7 @@ Generated by [AVA](https://avajs.dev).
23462370
| ^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
23472371
`
23482372

2349-
## invalid(17): const path = process.getBuiltinModule("path"); const { fileURLToPath } = process.getBuiltinModule("url"); const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename);
2350-
2351-
> Input
2352-
2353-
`␊
2354-
1 | const path = process.getBuiltinModule("path");␊
2355-
2 | const { fileURLToPath } = process.getBuiltinModule("url");␊
2356-
3 | const filename = fileURLToPath(import.meta.url);␊
2357-
4 | const dirname = path.dirname(filename);␊
2358-
`
2359-
2360-
> Output
2361-
2362-
`␊
2363-
1 | const path = process.getBuiltinModule("path");␊
2364-
2 | const { fileURLToPath } = process.getBuiltinModule("url");␊
2365-
3 | const filename = import.meta.filename;␊
2366-
4 | const dirname = import.meta.dirname;␊
2367-
`
2368-
2369-
> Error 1/2
2370-
2371-
`␊
2372-
1 | const path = process.getBuiltinModule("path");␊
2373-
2 | const { fileURLToPath } = process.getBuiltinModule("url");␊
2374-
> 3 | const filename = fileURLToPath(import.meta.url);␊
2375-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
2376-
4 | const dirname = path.dirname(filename);␊
2377-
`
2378-
2379-
> Error 2/2
2380-
2381-
`␊
2382-
1 | const path = process.getBuiltinModule("path");␊
2383-
2 | const { fileURLToPath } = process.getBuiltinModule("url");␊
2384-
3 | const filename = fileURLToPath(import.meta.url);␊
2385-
> 4 | const dirname = path.dirname(filename);␊
2386-
| ^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
2387-
`
2388-
2389-
## invalid(18): const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url); const dirname = process.getBuiltinModule("node:path").dirname(filename);
2390-
2391-
> Input
2392-
2393-
`␊
2394-
1 | const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url);␊
2395-
2 | const dirname = process.getBuiltinModule("node:path").dirname(filename);␊
2396-
`
2397-
2398-
> Output
2399-
2400-
`␊
2401-
1 | const filename = import.meta.filename;␊
2402-
2 | const dirname = import.meta.dirname;␊
2403-
`
2404-
2405-
> Error 1/2
2406-
2407-
`␊
2408-
> 1 | const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url);␊
2409-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct filename using \`fileURLToPath()\`.␊
2410-
2 | const dirname = process.getBuiltinModule("node:path").dirname(filename);␊
2411-
`
2412-
2413-
> Error 2/2
2414-
2415-
`␊
2416-
1 | const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url);␊
2417-
> 2 | const dirname = process.getBuiltinModule("node:path").dirname(filename);␊
2418-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
2419-
`
2420-
2421-
## invalid(16): const path = process.getBuiltinModule("path"); const { fileURLToPath } = process.getBuiltinModule("url"); const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename);
2373+
## invalid(18): const path = process.getBuiltinModule("path"); const { fileURLToPath } = process.getBuiltinModule("url"); const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename);
24222374

24232375
> Input
24242376
@@ -2458,7 +2410,7 @@ Generated by [AVA](https://avajs.dev).
24582410
| ^^^^^^^^^^^^^^^^^^^^^^ Do not construct dirname.␊
24592411
`
24602412

2461-
## invalid(17): const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url); const dirname = process.getBuiltinModule("node:path").dirname(filename);
2413+
## invalid(19): const filename = process.getBuiltinModule("node:url").fileURLToPath(import.meta.url); const dirname = process.getBuiltinModule("node:path").dirname(filename);
24622414

24632415
> Input
24642416

test/snapshots/prefer-module.js.snap

5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)