Skip to content

Commit

Permalink
enable eslint's no-shadow rule (#180)
Browse files Browse the repository at this point in the history
* enable eslint's `no-shadow` rule

This PR enables eslint's `no-shadow` rule. I started a refactor of a couple of pieces and found myself getting confused with vars that claimed to be defined without it being so. The `no-shadow` rule prevents vars from being defined in inner scopes if they've already been defined in an outer scope.

This PR is mostly clean. It did lead to some wordy vars in `index.tsx`, but that's fine, it only made them more obvious.

I didn't bother doing this in `pages.tsx`, I'll leave that up to the pages team. Instead, I've just disabled the rule for that file.

* add a changeset

* stray commented out line

* Apply suggested changes from review
  • Loading branch information
threepointone authored Jan 2, 2022
1 parent 1594036 commit 562d3ad
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-guests-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

chore: enable eslint's no-shadow rule
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@typescript-eslint/consistent-type-imports": [
"error"
],
"no-shadow": "error",
"@typescript-eslint/no-floating-promises": "error",
"no-empty": "off",
"require-yield": "off",
Expand Down
9 changes: 5 additions & 4 deletions packages/wrangler/src/api/form_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export function toFormData(worker: CfWorkerInit): FormData {
compatibility_date,
compatibility_flags,
} = worker;
const { name, type: mainType } = main;

const metadataBindings: WorkerMetadata["bindings"] = [];

Expand Down Expand Up @@ -104,7 +103,9 @@ export function toFormData(worker: CfWorkerInit): FormData {
});

const metadata: WorkerMetadata = {
...(mainType !== "commonjs" ? { main_module: name } : { body_part: name }),
...(main.type !== "commonjs"
? { main_module: main.name }
: { body_part: main.name }),
bindings: metadataBindings,
...(compatibility_date && { compatibility_date }),
...(compatibility_flags && { compatibility_flags }),
Expand All @@ -114,15 +115,15 @@ export function toFormData(worker: CfWorkerInit): FormData {

formData.set("metadata", JSON.stringify(metadata));

if (mainType === "commonjs" && modules && modules.length > 0) {
if (main.type === "commonjs" && modules && modules.length > 0) {
throw new TypeError(
"More than one module can only be specified when type = 'esm'"
);
}

for (const module of [main].concat(modules || [])) {
const { name } = module;
const blob = toModule(module, mainType ?? "esm");
const blob = toModule(module, main.type ?? "esm");
formData.set(name, blob, name);
}

Expand Down
30 changes: 13 additions & 17 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,10 @@ function useEsbuild(props: {
else {
// nothing really changes here, so let's increment the id
// to change the return object's identity
setBundle((bundle) => ({ ...bundle, id: bundle.id + 1 }));
setBundle((previousBundle) => ({
...previousBundle,
id: previousBundle.id + 1,
}));
}
},
},
Expand Down Expand Up @@ -818,31 +821,24 @@ function useHotkeys(initial: useHotkeysInitialState, port: number) {
) => {
switch (input) {
case "b": // open browser
await open(
`http://localhost:${port}/`
// {
// app: {
// name: open.apps.chrome, // TODO: fallback on other browsers
// },
// }
);
await open(`http://localhost:${port}/`);
break;
case "d": // toggle inspector
await open(
`https://built-devtools.pages.dev/js_app?experiments=true&v8only=true&ws=localhost:9229/ws`
// {
// app: {
// name: open.apps.chrome,
// // todo - add firefox and edge fallbacks
// },
// }
);
break;
case "s": // toggle tunnel
setToggles((toggles) => ({ ...toggles, tunnel: !toggles.tunnel }));
setToggles((previousToggles) => ({
...previousToggles,
tunnel: !previousToggles.tunnel,
}));
break;
case "l": // toggle local
setToggles((toggles) => ({ ...toggles, local: !toggles.local }));
setToggles((previousToggles) => ({
...previousToggles,
local: !previousToggles.local,
}));
break;
case "q": // shut down
case "x": // shut down
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/dialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export async function prompt(text: string, type: "text" | "password" = "text") {
<Prompt
text={text}
type={type}
onSubmit={(text) => {
onSubmit={(inputText) => {
unmount();
resolve(text);
resolve(inputText);
}}
/>
);
Expand Down
Loading

0 comments on commit 562d3ad

Please sign in to comment.