Skip to content

Commit 953d0b1

Browse files
Enable eslint for cloudflare package (#44)
* add eslint to cloudflare package * add prefer-node-protocol eslint rule * enable eslint sort-imports rule * add linting to gh workflow --------- Co-authored-by: Victor Berchet <[email protected]>
1 parent 11802c4 commit 953d0b1

26 files changed

+842
-256
lines changed

.github/workflows/prettier.yml renamed to .github/workflows/checks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Prettier check
1+
name: Code checks
22
on:
33
push:
44
branches: [main]
@@ -15,5 +15,5 @@ jobs:
1515
node-version: lts/*
1616
- name: Install dependencies
1717
run: npm install -g pnpm && pnpm install
18-
- name: Check formatting
19-
run: pnpm prettier:check
18+
- name: Run code checks
19+
run: pnpm code:checks

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"scripts": {
1010
"prettier:check": "prettier --check .",
1111
"prettier:fix": "prettier --write .",
12+
"lint:check": "pnpm -r lint:check",
13+
"lint:fix": "pnpm -r lint:fix",
14+
"code:checks": "pnpm lint:check && pnpm lint:check",
15+
"code:fixes": "pnpm prettier:fix && pnpm lint:fix",
1216
"postinstall": "pnpm --filter cloudflare build",
1317
"install-playwright": "playwright install --with-deps",
1418
"e2e": "pnpm -r e2e",

packages/cloudflare/eslint.config.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import eslintPluginUnicorn from "eslint-plugin-unicorn";
2+
import globals from "globals";
3+
import pluginJs from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
6+
export default [
7+
{
8+
ignores: ["dist", "**/test-snapshots", "**/test-fixtures"],
9+
},
10+
{
11+
files: ["**/*.{js,mjs,cjs,ts}"],
12+
},
13+
{
14+
languageOptions: {
15+
globals: globals.node,
16+
},
17+
},
18+
pluginJs.configs.recommended,
19+
...tseslint.configs.recommended,
20+
{
21+
plugins: {
22+
unicorn: eslintPluginUnicorn,
23+
},
24+
rules: {
25+
"@typescript-eslint/ban-ts-comment": "off",
26+
"unicorn/prefer-node-protocol": "error",
27+
"sort-imports": "error",
28+
},
29+
},
30+
];

packages/cloudflare/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"scripts": {
66
"build": "tsup",
77
"build:watch": "tsup --watch src",
8+
"lint:check": "eslint",
9+
"lint:fix": "eslint --fix",
810
"test": "vitest --run",
911
"test:watch": "vitest"
1012
},
@@ -38,12 +40,17 @@
3840
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
3941
"devDependencies": {
4042
"@cloudflare/workers-types": "catalog:",
43+
"@eslint/js": "catalog:",
4144
"@types/node": "catalog:",
4245
"esbuild": "catalog:",
46+
"eslint": "catalog:",
47+
"eslint-plugin-unicorn": "catalog:",
4348
"glob": "catalog:",
49+
"globals": "catalog:",
4450
"next": "catalog:",
4551
"tsup": "catalog:",
4652
"typescript": "catalog:",
53+
"typescript-eslint": "catalog:",
4754
"vitest": "catalog:"
4855
},
4956
"dependencies": {

packages/cloudflare/src/api/get-cloudflare-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "server-only";
22

33
declare global {
4-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
4+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
55
interface CloudflareEnv {}
66
}
77

packages/cloudflare/src/cli/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdirSync, type Stats, statSync } from "node:fs";
1+
import { type Stats, mkdirSync, statSync } from "node:fs";
22
import { parseArgs } from "node:util";
33
import { resolve } from "node:path";
44

packages/cloudflare/src/cli/build/build-worker.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
import { Config } from "../config";
2-
import { build, Plugin } from "esbuild";
3-
import { existsSync, readFileSync } from "node:fs";
1+
import { Plugin, build } from "esbuild";
42
import { cp, readFile, writeFile } from "node:fs/promises";
5-
import path from "node:path";
6-
import { fileURLToPath } from "node:url";
7-
8-
import { patchRequire } from "./patches/investigated/patch-require";
3+
import { existsSync, readFileSync } from "node:fs";
4+
import { Config } from "../config";
95
import { copyPackageCliFiles } from "./patches/investigated/copy-package-cli-files";
10-
11-
import { patchReadFile } from "./patches/to-investigate/patch-read-file";
12-
import { patchFindDir } from "./patches/to-investigate/patch-find-dir";
13-
import { inlineNextRequire } from "./patches/to-investigate/inline-next-require";
6+
import { fileURLToPath } from "node:url";
147
import { inlineEvalManifest } from "./patches/to-investigate/inline-eval-manifest";
8+
import { inlineNextRequire } from "./patches/to-investigate/inline-next-require";
9+
import { patchCache } from "./patches/investigated/patch-cache";
10+
import { patchFindDir } from "./patches/to-investigate/patch-find-dir";
11+
import { patchReadFile } from "./patches/to-investigate/patch-read-file";
12+
import { patchRequire } from "./patches/investigated/patch-require";
1513
import { patchWranglerDeps } from "./patches/to-investigate/wrangler-deps";
14+
import path from "node:path";
1615
import { updateWebpackChunksFile } from "./patches/investigated/update-webpack-chunks-file";
17-
import { patchCache } from "./patches/investigated/patch-cache";
1816

1917
/** The dist directory of the Cloudflare adapter package */
2018
const packageDistDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
@@ -177,10 +175,10 @@ function createFixRequiresESBuildPlugin(templateDir: string): Plugin {
177175
name: "replaceRelative",
178176
setup(build) {
179177
// Note: we (empty) shim require-hook modules as they generate problematic code that uses requires
180-
build.onResolve({ filter: /^\.\/require-hook$/ }, (args) => ({
178+
build.onResolve({ filter: /^\.\/require-hook$/ }, () => ({
181179
path: path.join(templateDir, "shims", "empty.ts"),
182180
}));
183-
build.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (args) => ({
181+
build.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, () => ({
184182
path: path.join(templateDir, "shims", "empty.ts"),
185183
}));
186184
},

packages/cloudflare/src/cli/build/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { rm } from "node:fs/promises";
1+
import { containsDotNextDir, getConfig } from "../config";
22
import { buildNextjsApp } from "./build-next-app";
33
import { buildWorker } from "./build-worker";
4-
import { containsDotNextDir, getConfig } from "../config";
54
import { cpSync } from "node:fs";
65
import path from "node:path";
6+
import { rm } from "node:fs/promises";
77

88
/**
99
* Builds the application in a format that can be passed to workerd

packages/cloudflare/src/cli/build/patches/investigated/patch-cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from "node:path";
21
import { Config } from "../../../config";
2+
import path from "node:path";
33

44
/**
55
* Install the cloudflare KV cache handler

packages/cloudflare/src/cli/build/patches/investigated/update-webpack-chunks-file/get-chunk-installation-identifiers.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { readFile } from "node:fs/promises";
2-
3-
import { expect, test, describe } from "vitest";
4-
1+
import { describe, expect, test } from "vitest";
52
import { getChunkInstallationIdentifiers } from "./get-chunk-installation-identifiers";
3+
import { readFile } from "node:fs/promises";
64
import { tsParseFile } from "../../../utils";
75

86
describe("getChunkInstallationIdentifiers", () => {

0 commit comments

Comments
 (0)