Skip to content

Commit

Permalink
fix/introduce no-unused-vars and no-shadow eslint rules and also incl…
Browse files Browse the repository at this point in the history
…ude c3.ts files in linting (#4851)

* enable `@typescript-eslint/no-unused-vars` eslint rule (and fix related errors)

* properly enable `@typescript-eslint/no-shadow` eslint rule (and fix related errors)

* re-introduce compatDateFlag to C3 svelteKit scripts (removed by mistake)
  • Loading branch information
dario-piotrowicz authored Jan 29, 2024
1 parent eb76082 commit fbd2a4c
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 28 deletions.
8 changes: 7 additions & 1 deletion packages/create-cloudflare/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
root: true,
extends: ["@cloudflare/eslint-config-worker"],
ignorePatterns: ["dist", "scripts"],
ignorePatterns: [
"dist",
"scripts",
// template files are ignored by the eslint-config-worker configuration
// we do however want the c3 files to be linted
"!**/templates/**/c3.ts",
],
};
5 changes: 2 additions & 3 deletions packages/create-cloudflare/templates/angular/c3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cp } from "node:fs/promises";
import { resolve } from "node:path";
import { logRaw } from "@cloudflare/cli";
import { brandColor, dim } from "@cloudflare/cli/colors";
Expand All @@ -19,10 +18,10 @@ const generate = async (ctx: C3Context) => {
const configure = async (ctx: C3Context) => {
updateAngularJson(ctx);
await updateAppCode();
await installCFWorker(ctx);
await installCFWorker();
};

async function installCFWorker(ctx: C3Context) {
async function installCFWorker() {
await installPackages(
["@cloudflare/workers-types", "@miniflare/tre@next", "wrangler@beta"],
{
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/astro/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const generate = async (ctx: C3Context) => {
logRaw(""); // newline
};

const configure = async (ctx: C3Context) => {
const configure = async () => {
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
silent: true,
startText: "Installing adapter",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/nuxt/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const generate = async (ctx: C3Context) => {
logRaw(""); // newline
};

const configure = async (ctx: C3Context) => {
const configure = async () => {
const configFileName = "nuxt.config.ts";
const configFilePath = resolve(configFileName);
const s = spinner();
Expand Down
5 changes: 2 additions & 3 deletions packages/create-cloudflare/templates/pre-existing/c3.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { cp, mkdtemp, readdir, rm } from "fs/promises";
import { cp, mkdtemp } from "fs/promises";
import { tmpdir } from "os";
import { join } from "path";
import { crash } from "@cloudflare/cli";
import { processArgument } from "@cloudflare/cli/args";
import { brandColor, dim } from "@cloudflare/cli/colors";
import { runCommand } from "helpers/command";
Expand All @@ -10,7 +9,7 @@ import { chooseAccount } from "../../src/common";
import type { C3Context } from "types";

export async function copyExistingWorkerFiles(ctx: C3Context) {
const { dlx, npm } = detectPackageManager();
const { dlx } = detectPackageManager();

await chooseAccount(ctx);

Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/qwik/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const generate = async (ctx: C3Context) => {
await runFrameworkGenerator(ctx, ["basic", ctx.project.name]);
};

const configure = async (ctx: C3Context) => {
const configure = async () => {
// Add the pages integration
const cmd = [npx, "qwik", "add", "cloudflare-pages"];
endSection(`Running ${quoteShellArgs(cmd)}`);
Expand Down
5 changes: 2 additions & 3 deletions packages/create-cloudflare/templates/solid/c3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { logRaw, updateStatus } from "@cloudflare/cli";
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
import { installPackages, runFrameworkGenerator } from "helpers/command";
import { logRaw } from "@cloudflare/cli";
import { runFrameworkGenerator } from "helpers/command";
import { compatDateFlag } from "helpers/files";
import { detectPackageManager } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/svelte/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const config: TemplateConfig = {
configure,
transformPackageJson: async () => ({
scripts: {
"pages:preview": `${npm} run build && wrangler pages dev .svelte-kit/cloudflare`,
"pages:preview": `${npm} run build && wrangler pages dev ${await compatDateFlag()} .svelte-kit/cloudflare`,
"pages:deploy": `${npm} run build && wrangler pages deploy .svelte-kit/cloudflare`,
},
}),
Expand Down
15 changes: 12 additions & 3 deletions packages/eslint-config-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
ignorePatterns: [
"**/node_modules/**",
"examples",
"**/templates/**",
"**/templates/**/*.*",
".eslintrc.js",
"**/dist/**",
],
Expand Down Expand Up @@ -49,14 +49,23 @@ module.exports = {
"no-empty-function": "off",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-only-tests/no-only-tests": "error",
"no-shadow": "error",
"require-yield": "off",
"@typescript-eslint/consistent-type-imports": ["error"],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-unused-vars": "off",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: ".*",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { RawSourceMap } from "source-map";
* directly in the terminal.
*/
const mapConsoleAPIMessageTypeToConsoleMethod: {
[key in Protocol.Runtime.ConsoleAPICalledEvent["type"]]: Exclude<
[_key in Protocol.Runtime.ConsoleAPICalledEvent["type"]]: Exclude<
keyof Console,
"Console"
>;
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/pages/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { RoutesValidationError } from "./functions/routes-validation";
/**
* Error codes returned by requests to Pages APIs
*/
/* eslint-disable-next-line no-shadow */
export enum ApiErrorCodes {
UNKNOWN_ERROR = 8000000,
UNAUTHORIZED = 8000013,
Expand Down
1 change: 0 additions & 1 deletion packages/wrangler/src/pages/functions/routes-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
import { getRoutesValidationErrorMessage } from "../errors";
import type { RoutesJSONSpec } from "./routes-transformation";

/* eslint-disable-next-line no-shadow */
export enum RoutesValidationError {
INVALID_JSON_SPEC,
NO_INCLUDE_RULES,
Expand Down
12 changes: 6 additions & 6 deletions packages/wrangler/src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export function pages(yargs: CommonYargsArgv) {
* `wrangler pages functions` is meant for internal use only for now,
* so let's hide this command from the help output
*/
.command("functions", false, (yargs) =>
yargs
.command("functions", false, (args) =>
args
.command(
"build [directory]",
"Compile a folder of Cloudflare Pages Functions into a single Worker",
Expand All @@ -49,8 +49,8 @@ export function pages(yargs: CommonYargsArgv) {
Functions.OptimizeRoutesHandler
)
)
.command("project", "⚡️ Interact with your Pages projects", (yargs) =>
yargs
.command("project", "⚡️ Interact with your Pages projects", (args) =>
args
.command(
"list",
"List your Cloudflare Pages projects",
Expand Down Expand Up @@ -80,8 +80,8 @@ export function pages(yargs: CommonYargsArgv) {
.command(
"deployment",
"🚀 Interact with the deployments of a project",
(yargs) =>
yargs
(args) =>
args
.command(
"list",
"List deployments in your Cloudflare Pages project",
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/pages/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,14 @@ function renderProgress(done: number, total: number) {
<Progress done={done} total={total} />
);
return {
// eslint-disable-next-line no-shadow
// eslint-disable-next-line @typescript-eslint/no-shadow
rerender(done: number, total: number) {
rerender(<Progress done={done} total={total} />);
},
unmount,
};
} else {
// eslint-disable-next-line no-shadow
// eslint-disable-next-line @typescript-eslint/no-shadow
const rerender = (done: number, total: number) => {
logger.log(`Uploading... (${done}/${total})`);
};
Expand Down

0 comments on commit fbd2a4c

Please sign in to comment.