From 323d1b17e9adb52adaf37d4c1bd615b078a45784 Mon Sep 17 00:00:00 2001 From: Cody Olsen <81981+stipsan@users.noreply.github.com> Date: Fri, 3 Jan 2025 13:34:18 +0100 Subject: [PATCH] chore: add github problem matcher for PR linting (#8161) --- .github/eslint-compact.json | 14 +++++++ .github/workflows/lintPr.yml | 5 ++- dev/design-studio/package.json | 2 +- dev/page-building-studio/package.json | 2 +- dev/starter-studio/package.json | 2 +- dev/strict-studio/package.json | 2 +- dev/studio-e2e-testing/package.json | 2 +- .../package.json | 2 +- dev/test-next-studio/package.json | 2 +- dev/test-studio/package.json | 2 +- examples/blog-studio/package.json | 2 +- examples/clean-studio/package.json | 2 +- examples/ecommerce-studio/package.json | 2 +- examples/movies-studio/package.json | 2 +- package.json | 2 +- packages/@sanity/block-tools/package.json | 2 +- packages/@sanity/cli/package.json | 2 +- packages/@sanity/codegen/package.json | 2 +- packages/@sanity/diff/package.json | 2 +- packages/@sanity/migrate/package.json | 2 +- packages/@sanity/mutator/package.json | 2 +- packages/@sanity/schema/package.json | 2 +- packages/groq/package.json | 2 +- packages/sanity/package.json | 2 +- .../form/studio/assetSource/file/AssetRow.tsx | 39 ++++++++++--------- perf/studio/package.json | 2 +- perf/tests/package.json | 2 +- 27 files changed, 63 insertions(+), 43 deletions(-) diff --git a/.github/eslint-compact.json b/.github/eslint-compact.json index c45497febd4..efef43f072d 100644 --- a/.github/eslint-compact.json +++ b/.github/eslint-compact.json @@ -13,6 +13,20 @@ "code": 6 } ] + }, + { + "owner": "turbo-eslint-compact", + "pattern": [ + { + "regexp": "^(?:[^:]+: )?([^:]+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)\\.?$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5, + "code": 6 + } + ] } ] } diff --git a/.github/workflows/lintPr.yml b/.github/workflows/lintPr.yml index d131661cdb5..3e5ab138dcf 100644 --- a/.github/workflows/lintPr.yml +++ b/.github/workflows/lintPr.yml @@ -46,5 +46,8 @@ jobs: - name: Install project dependencies run: pnpm install + - name: Register Problem Matcher for ESLint that handles -f compact and shows warnings inline on PRs + run: echo "::add-matcher::.github/eslint-compact.json" + - name: Lint files - run: pnpm lint + run: pnpm turbo run lint --output-logs=full --continue -- -f compact diff --git a/dev/design-studio/package.json b/dev/design-studio/package.json index 9413e4ae1dc..98abbb9c726 100644 --- a/dev/design-studio/package.json +++ b/dev/design-studio/package.json @@ -27,7 +27,7 @@ "build": "../.bin/sanity build", "clean": "rimraf .sanity dist", "dev": "../.bin/sanity dev --port 4000", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "../.bin/sanity start --port 4000" }, "dependencies": { diff --git a/dev/page-building-studio/package.json b/dev/page-building-studio/package.json index e8f9a64a837..b047509064f 100644 --- a/dev/page-building-studio/package.json +++ b/dev/page-building-studio/package.json @@ -8,7 +8,7 @@ "build": "../.bin/sanity build", "clean": "rimraf .sanity dist", "dev": "../.bin/sanity dev", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "../.bin/sanity start" }, "dependencies": { diff --git a/dev/starter-studio/package.json b/dev/starter-studio/package.json index 990b2f03397..b8a62324d10 100644 --- a/dev/starter-studio/package.json +++ b/dev/starter-studio/package.json @@ -8,7 +8,7 @@ "build": "../.bin/sanity build", "clean": "rimraf .sanity dist", "dev": "../.bin/sanity dev --port 3337", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "../.bin/sanity start --port 3337" }, "dependencies": { diff --git a/dev/strict-studio/package.json b/dev/strict-studio/package.json index cd9c3663660..1a60c265922 100644 --- a/dev/strict-studio/package.json +++ b/dev/strict-studio/package.json @@ -8,7 +8,7 @@ "build": "../.bin/sanity build", "clean": "rimraf .sanity dist", "dev": "../.bin/sanity dev", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "../.bin/sanity start" }, "dependencies": { diff --git a/dev/studio-e2e-testing/package.json b/dev/studio-e2e-testing/package.json index a39687e88d9..5c9670ee629 100644 --- a/dev/studio-e2e-testing/package.json +++ b/dev/studio-e2e-testing/package.json @@ -10,7 +10,7 @@ "scripts": { "build": "sanity build", "dev": "sanity dev --port 3339", - "lint": "eslint .", + "lint": "eslint --cache .", "preview": "sanity preview --port 3339", "start": "sanity preview --port 3339" }, diff --git a/dev/test-create-integration-studio/package.json b/dev/test-create-integration-studio/package.json index f92df10fe2f..68eda8931a6 100644 --- a/dev/test-create-integration-studio/package.json +++ b/dev/test-create-integration-studio/package.json @@ -9,7 +9,7 @@ "clean": "rimraf .sanity dist", "deploy": "npx sanity deploy", "dev": "../.bin/sanity dev", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "../.bin/sanity start" }, "dependencies": { diff --git a/dev/test-next-studio/package.json b/dev/test-next-studio/package.json index e7283ad2fd8..c5a8012d3d3 100644 --- a/dev/test-next-studio/package.json +++ b/dev/test-next-studio/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "next build", "dev": "next dev -p 3333", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "next start" }, "dependencies": { diff --git a/dev/test-studio/package.json b/dev/test-studio/package.json index 5a10e1f6a60..05b8de4529e 100644 --- a/dev/test-studio/package.json +++ b/dev/test-studio/package.json @@ -8,7 +8,7 @@ "build": "run-s workshop:build sanity:build", "clean": "rimraf .sanity dist", "dev": "run-p workshop:dev sanity:dev", - "lint": "eslint .", + "lint": "eslint --cache .", "sanity:build": "../.bin/sanity build --source-maps", "sanity:dev": "../.bin/sanity dev", "start": "../.bin/sanity start", diff --git a/examples/blog-studio/package.json b/examples/blog-studio/package.json index c832ae455f3..3a0bfb3d2b0 100644 --- a/examples/blog-studio/package.json +++ b/examples/blog-studio/package.json @@ -24,7 +24,7 @@ "author": "Sanity.io ", "main": "package.json", "scripts": { - "lint": "eslint .", + "lint": "eslint --cache .", "start": "sanity dev --port 3336" }, "dependencies": { diff --git a/examples/clean-studio/package.json b/examples/clean-studio/package.json index c64ea7e4134..636b72f0e08 100644 --- a/examples/clean-studio/package.json +++ b/examples/clean-studio/package.json @@ -24,7 +24,7 @@ "author": "Sanity.io ", "main": "package.json", "scripts": { - "lint": "eslint .", + "lint": "eslint --cache .", "start": "sanity dev --port 3338" }, "dependencies": { diff --git a/examples/ecommerce-studio/package.json b/examples/ecommerce-studio/package.json index dab5fabcd7e..c677dabb6d4 100644 --- a/examples/ecommerce-studio/package.json +++ b/examples/ecommerce-studio/package.json @@ -25,7 +25,7 @@ "main": "package.json", "scripts": { "clean": "rimraf lib dest", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "sanity dev --port 3337" }, "dependencies": { diff --git a/examples/movies-studio/package.json b/examples/movies-studio/package.json index d710c5d9740..0875f3b6eb9 100644 --- a/examples/movies-studio/package.json +++ b/examples/movies-studio/package.json @@ -25,7 +25,7 @@ "main": "package.json", "scripts": { "clean": "rimraf lib dest", - "lint": "eslint .", + "lint": "eslint --cache .", "start": "sanity dev --port 3334" }, "dependencies": { diff --git a/package.json b/package.json index b9f004b9e59..9a07ba6cac0 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "prepublishOnly": "pnpm build", "example:movies-studio": "cd examples/blog-studio && pnpm start", "install:deps": "pnpm install", - "lint": "run-s check:lint", + "lint": "pnpm check:lint", "lint:fix": "run-s chore:lint:fix", "list:deps-updates": "npm-check-updates --workspaces --root -m", "normalize-pkgfields": "node -r esbuild-register scripts/normalizePackageFields", diff --git a/packages/@sanity/block-tools/package.json b/packages/@sanity/block-tools/package.json index 34b53344f2a..a4665e30847 100644 --- a/packages/@sanity/block-tools/package.json +++ b/packages/@sanity/block-tools/package.json @@ -43,7 +43,7 @@ "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib", "coverage": "NODE_ENV=test vitest --coverage", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest run", "watch": "pkg-utils watch" diff --git a/packages/@sanity/cli/package.json b/packages/@sanity/cli/package.json index acd3b040542..8caeab4253a 100644 --- a/packages/@sanity/cli/package.json +++ b/packages/@sanity/cli/package.json @@ -49,7 +49,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest", "ts": "node -r esbuild-register", diff --git a/packages/@sanity/codegen/package.json b/packages/@sanity/codegen/package.json index 6443272434d..ccb767e1d88 100644 --- a/packages/@sanity/codegen/package.json +++ b/packages/@sanity/codegen/package.json @@ -44,7 +44,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib coverage", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest", "watch": "pkg-utils watch" diff --git a/packages/@sanity/diff/package.json b/packages/@sanity/diff/package.json index 0299a2bf60f..78448e64987 100644 --- a/packages/@sanity/diff/package.json +++ b/packages/@sanity/diff/package.json @@ -42,7 +42,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib coverage", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "watch": "pkg-utils watch" }, diff --git a/packages/@sanity/migrate/package.json b/packages/@sanity/migrate/package.json index 028cbd33d60..8949060a7c4 100644 --- a/packages/@sanity/migrate/package.json +++ b/packages/@sanity/migrate/package.json @@ -44,7 +44,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib coverage", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest", "watch": "pkg-utils watch" diff --git a/packages/@sanity/mutator/package.json b/packages/@sanity/mutator/package.json index 5bee2ae91a9..1fc83259ac1 100644 --- a/packages/@sanity/mutator/package.json +++ b/packages/@sanity/mutator/package.json @@ -42,7 +42,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib", - "lint": "eslint .", + "lint": "eslint --cache .", "perf": "node ./perf/run.js", "prepublishOnly": "turbo run build", "test": "vitest run", diff --git a/packages/@sanity/schema/package.json b/packages/@sanity/schema/package.json index 9bc74d14e77..06426eaa9d9 100644 --- a/packages/@sanity/schema/package.json +++ b/packages/@sanity/schema/package.json @@ -56,7 +56,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf _internal.js lib", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest run", "test:watch": "vitest watch", diff --git a/packages/groq/package.json b/packages/groq/package.json index 634ad4f137f..aeed9ed4950 100644 --- a/packages/groq/package.json +++ b/packages/groq/package.json @@ -45,7 +45,7 @@ "build": "pkg-utils build --strict --check --clean", "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf lib", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "pretest": "run-s build", "test": "node --test", diff --git a/packages/sanity/package.json b/packages/sanity/package.json index bfeaf325ccd..ffc05c348d2 100644 --- a/packages/sanity/package.json +++ b/packages/sanity/package.json @@ -140,7 +140,7 @@ "check:types": "tsc --project tsconfig.lib.json", "clean": "rimraf _internal.js _singletons.js _createContext.js cli.js desk.js migrate.js presentation.js router.js structure.js lib", "coverage": "vitest --coverage", - "lint": "eslint .", + "lint": "eslint --cache .", "prepublishOnly": "turbo run build", "test": "vitest run", "test:ct": "rimraf playwright-ct/template/.cache && playwright test -c playwright-ct.config.ts", diff --git a/packages/sanity/src/core/form/studio/assetSource/file/AssetRow.tsx b/packages/sanity/src/core/form/studio/assetSource/file/AssetRow.tsx index 547b3c3531b..305ac9f6e25 100644 --- a/packages/sanity/src/core/form/studio/assetSource/file/AssetRow.tsx +++ b/packages/sanity/src/core/form/studio/assetSource/file/AssetRow.tsx @@ -128,7 +128,7 @@ const STYLES_ASSETMENU_WRAPPER = { marginBottom: '-0.5rem', } -export const AssetRow = (props: RowProps) => { +export const AssetRow = (props: RowProps): React.JSX.Element => { const versionedClient = useClient(DEFAULT_STUDIO_CLIENT_OPTIONS) const toast = useToast() const deleteRef$ = useRef() @@ -195,28 +195,31 @@ export const AssetRow = (props: RowProps) => { versionedClient.observable, ]) - const handleDialogClose = () => { + const handleDialogClose = useCallback(() => { setShowUsageDialog(false) setShowDeleteDialog(false) - } + }, []) - const handleToggleUsageDialog = () => { + const handleToggleUsageDialog = useCallback(() => { setShowUsageDialog(true) - } + }, []) - const handleToggleOpen = () => { - setIsOpen(!isOpen) - } + const handleToggleOpen = useCallback(() => { + setIsOpen((prev) => !prev) + }, []) - const handleMenuAction = (action: AssetMenuAction) => { - if (action.type === 'delete') { - handleConfirmDelete() - } + const handleMenuAction = useCallback( + (action: AssetMenuAction) => { + if (action.type === 'delete') { + handleConfirmDelete() + } - if (action.type === 'showUsage') { - handleToggleUsageDialog() - } - } + if (action.type === 'showUsage') { + handleToggleUsageDialog() + } + }, + [handleConfirmDelete, handleToggleUsageDialog], + ) const usageDialog = useMemo(() => { return ( @@ -224,7 +227,7 @@ export const AssetRow = (props: RowProps) => { ) ) - }, [asset, showUsageDialog]) + }, [asset, handleDialogClose, showUsageDialog]) const deleteDialog = useMemo(() => { return ( @@ -238,7 +241,7 @@ export const AssetRow = (props: RowProps) => { /> ) ) - }, [asset, handleDeleteAsset, isDeleting, showDeleteDialog]) + }, [asset, handleDeleteAsset, handleDialogClose, isDeleting, showDeleteDialog]) if (isMobile) { return ( diff --git a/perf/studio/package.json b/perf/studio/package.json index ed0706a9155..5071e22b455 100644 --- a/perf/studio/package.json +++ b/perf/studio/package.json @@ -9,7 +9,7 @@ "build": "sanity build", "clean": "rimraf .sanity dist", "dev": "sanity dev --port 3300", - "lint": "eslint .", + "lint": "eslint --cache .", "preview": "pnpm build && pnpm start", "start": "sanity start --port 3300" }, diff --git a/perf/tests/package.json b/perf/tests/package.json index bd4bf20170a..155cea27e29 100644 --- a/perf/tests/package.json +++ b/perf/tests/package.json @@ -7,7 +7,7 @@ "author": "Sanity.io ", "scripts": { "build": "pnpm build:cli && (cd studio && pnpm build)", - "lint": "eslint .", + "lint": "eslint --cache .", "perf:codegen": "ts-node --files -r dotenv/config codegen", "perf:test": "ts-node --files cli", "perf:test:ci": "ts-node --files cli",