Skip to content

Commit ad8d601

Browse files
committed
Fix tests
1 parent 2bacc66 commit ad8d601

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

scripts/eslint/rules/prefer-direct-import.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ module.exports = createRule({
3636
* @param {string} p
3737
*/
3838
function getImportPath(p) {
39-
return path.relative(path.dirname(context.filename), path.join(srcRoot, p)).replace(/\\/g, "/");
39+
let out = path.relative(path.dirname(context.filename), path.join(srcRoot, p)).replace(/\\/g, "/");
40+
if (!out.startsWith(".")) out = "./" + out;
41+
return out;
4042
}
4143

4244
/** @type {any} */

scripts/eslint/tests/prefer-direct-import.cjs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,50 @@ import { type Debug } from "./_namespaces/ts";
2929

3030
invalid: [
3131
{
32+
filename: "src/compiler/checker.ts",
3233
code: `
3334
import { Debug } from "./_namespaces/ts";
34-
`,
35+
`.replace(/\r?\n/g, "\r\n"),
36+
errors: [{ messageId: "importError", data: { name: "Debug", path: "compiler/debug" } }],
37+
output: `
38+
import * as Debug from "./debug";
39+
`.replace(/\r?\n/g, "\r\n"),
40+
},
41+
{
42+
filename: "src/compiler/transformers/ts.ts",
43+
code: `
44+
import { Debug } from "../_namespaces/ts";
45+
`.replace(/\r?\n/g, "\r\n"),
3546
errors: [{ messageId: "importError", data: { name: "Debug", path: "compiler/debug" } }],
47+
output: `
48+
import * as Debug from "../debug";
49+
`.replace(/\r?\n/g, "\r\n"),
3650
},
51+
// TODO(jakebailey): the rule probably needs to handle .js extensions
3752
{
53+
filename: "src/compiler/checker.ts",
3854
code: `
3955
import { Debug } from "./_namespaces/ts.js";
40-
`,
56+
`.replace(/\r?\n/g, "\r\n"),
4157
errors: [{ messageId: "importError", data: { name: "Debug", path: "compiler/debug" } }],
58+
output: `
59+
import * as Debug from "./debug";
60+
`.replace(/\r?\n/g, "\r\n"),
4261
},
4362
{
63+
filename: "src/compiler/checker.ts",
4464
code: `
4565
import * as ts from "./_namespaces/ts";
4666
4767
ts.Debug.assert(true);
48-
`,
68+
`.replace(/\r?\n/g, "\r\n"),
4969
errors: [{ messageId: "importError", data: { name: "Debug", path: "compiler/debug" } }],
70+
output: `
71+
import * as Debug from "./debug";
72+
import * as ts from "./_namespaces/ts";
73+
74+
Debug.assert(true);
75+
`.replace(/\r?\n/g, "\r\n"),
5076
},
5177
],
5278
});

0 commit comments

Comments
 (0)