Skip to content

Commit 085a565

Browse files
authored
add eslint disable (#8903)
1 parent bb879af commit 085a565

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

.changeset/wild-books-melt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
disable eslint in generated types file

packages/wrangler/e2e/types.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ describe("types", () => {
7373
"utf8"
7474
);
7575
expect(file).toMatchInlineSnapshot(`
76-
"// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 7915eccca244b8d5c107e358ee5929e8)
76+
"/* eslint-disable */
77+
// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 7915eccca244b8d5c107e358ee5929e8)
7778
declare namespace Cloudflare {
7879
interface Env {
7980
MY_VAR: "my-var-value";
@@ -94,10 +95,10 @@ describe("types", () => {
9495
"utf8"
9596
).split("\n");
9697

97-
expect(lines[0]).toMatchInlineSnapshot(
98+
expect(lines[1]).toMatchInlineSnapshot(
9899
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: 7915eccca244b8d5c107e358ee5929e8)"`
99100
);
100-
expect(lines[1]).match(
101+
expect(lines[2]).match(
101102
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
102103
);
103104
});
@@ -121,10 +122,10 @@ describe("types", () => {
121122
"utf8"
122123
).split("\n");
123124

124-
expect(lines[0]).toMatchInlineSnapshot(
125-
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: 2f74a5a99f09ae4d994228b5bb959d24)"`
125+
expect(lines[1]).toMatchInlineSnapshot(
126+
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: fb913b8eb739817c9664fa1da8bdf499)"`
126127
);
127-
expect(lines[1]).match(
128+
expect(lines[2]).match(
128129
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
129130
);
130131
});
@@ -142,6 +143,7 @@ describe("types", () => {
142143
[
143144
file[0],
144145
file[1],
146+
file[2],
145147
"FAKE ENV",
146148
"// Begin runtime types",
147149
"FAKE RUNTIME",

packages/wrangler/src/__tests__/type-generation.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ describe("generate types", () => {
582582
expect(fs.existsSync("./worker-configuration.d.ts")).toBe(true);
583583
expect(fs.readFileSync("./worker-configuration.d.ts", "utf-8"))
584584
.toMatchInlineSnapshot(`
585-
"// Generated by Wrangler by running \`wrangler\` (hash: a123396658ac84465faf6f0f82c0337b)
585+
"/* eslint-disable */
586+
// Generated by Wrangler by running \`wrangler\` (hash: a123396658ac84465faf6f0f82c0337b)
586587
// Runtime types generated with workerd@
587588
declare namespace Cloudflare {
588589
interface Env {
@@ -646,7 +647,8 @@ describe("generate types", () => {
646647
await runWrangler("types");
647648
expect(fs.readFileSync("./worker-configuration.d.ts", "utf8"))
648649
.toMatchInlineSnapshot(`
649-
"// Runtime types generated with workerd@
650+
"/* eslint-disable */
651+
// Runtime types generated with workerd@
650652
// Begin runtime types
651653
<runtime types go here>"
652654
`);
@@ -683,14 +685,10 @@ describe("generate types", () => {
683685

684686
await runWrangler("types --include-runtime=false");
685687

686-
expect(fs.readFileSync("./worker-configuration.d.ts", "utf-8")).toContain(
687-
`\t// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-empty-object-type\n\tinterface Env {\n\t}`
688-
);
689688
expect(std.out).toMatchInlineSnapshot(`
690689
"Generating project types...
691690
692691
declare namespace Cloudflare {
693-
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-empty-object-type
694692
interface Env {
695693
}
696694
}
@@ -1206,7 +1204,8 @@ describe("generate types", () => {
12061204

12071205
expect(fs.readFileSync("./cloudflare-env.d.ts", "utf-8"))
12081206
.toMatchInlineSnapshot(`
1209-
"// Generated by Wrangler by running \`wrangler\` (hash: a123396658ac84465faf6f0f82c0337b)
1207+
"/* eslint-disable */
1208+
// Generated by Wrangler by running \`wrangler\` (hash: a123396658ac84465faf6f0f82c0337b)
12101209
// Runtime types generated with workerd@
12111210
declare namespace Cloudflare {
12121211
interface Env {
@@ -1263,7 +1262,8 @@ describe("generate types", () => {
12631262

12641263
expect(fs.readFileSync("./my-cloudflare-env-interface.d.ts", "utf-8"))
12651264
.toMatchInlineSnapshot(`
1266-
"// Generated by Wrangler by running \`wrangler\` (hash: 7e48a0a15b531f54ca31c564fe6cb101)
1265+
"/* eslint-disable */
1266+
// Generated by Wrangler by running \`wrangler\` (hash: 7e48a0a15b531f54ca31c564fe6cb101)
12671267
// Runtime types generated with workerd@
12681268
declare namespace Cloudflare {
12691269
interface Env {

packages/wrangler/src/type-generation/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export const typesCommand = createCommand({
137137
}
138138
const entrypointFormat = entrypoint?.format ?? "modules";
139139

140-
const header = [];
140+
const header = ["/* eslint-disable */"];
141141
const content = [];
142142
if (args.includeEnv) {
143143
logger.log(`Generating project types...\n`);
@@ -622,22 +622,17 @@ function generateTypeStrings(
622622
compatibilityFlags: string[] | undefined
623623
): { fileContent: string; consoleOutput: string } {
624624
let baseContent = "";
625-
let eslintDisable = "";
626625
let processEnv = "";
627626

628627
if (formatType === "modules") {
629-
if (envTypeStructure.length === 0) {
630-
eslintDisable =
631-
"\t// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-empty-object-type\n";
632-
}
633628
if (
634629
isProcessEnvPopulated(compatibilityDate, compatibilityFlags) &&
635630
stringKeys.length > 0
636631
) {
637632
// StringifyValues ensures that json vars are correctly types as strings, not objects on process.env
638633
processEnv = `\ntype StringifyValues<EnvType extends Record<string, unknown>> = {\n\t[Binding in keyof EnvType]: EnvType[Binding] extends string ? EnvType[Binding] : string;\n};\ndeclare namespace NodeJS {\n\tinterface ProcessEnv extends StringifyValues<Pick<Cloudflare.Env, ${stringKeys.map((k) => `"${k}"`).join(" | ")}>> {}\n}`;
639634
}
640-
baseContent = `declare namespace Cloudflare {\n${eslintDisable}\tinterface Env {${envTypeStructure.map((value) => `\n\t\t${value}`).join("")}\n\t}\n}\ninterface ${envInterface} extends Cloudflare.Env {}${processEnv}`;
635+
baseContent = `declare namespace Cloudflare {\n\tinterface Env {${envTypeStructure.map((value) => `\n\t\t${value}`).join("")}\n\t}\n}\ninterface ${envInterface} extends Cloudflare.Env {}${processEnv}`;
641636
} else {
642637
baseContent = `export {};\ndeclare global {\n${envTypeStructure.map((value) => `\tconst ${value}`).join("\n")}\n}`;
643638
}

0 commit comments

Comments
 (0)