From e7b09891070648b006b9bdaa4a2255cf96e23d9a Mon Sep 17 00:00:00 2001 From: Ashref Gwader Date: Mon, 20 Jan 2025 14:43:25 +0100 Subject: [PATCH] build: update `eslint` & `tsconfig` (#469) * build: minimize shared `tsconfig` options * build: update `eslint` shared conf * build: add `eslint` to `playwright` & `vitest` confs * fix: codacy ` @typescript-eslint/no-unsafe-assignment` go away --- apps/blog/tsconfig.json | 15 ++------------- apps/www/package.json | 2 +- apps/www/tsconfig.json | 15 ++------------- packages/env/eslint.config.js | 9 +++++++++ packages/env/index.ts | 4 +++- packages/env/package.json | 6 ++++++ packages/env/tsconfig.json | 5 +---- packages/ui/tsconfig.json | 9 +-------- pnpm-lock.yaml | 9 +++++++++ tooling/eslint/tsconfig.json | 4 +--- tooling/playwright/base.ts | 9 ++++++--- tooling/playwright/eslint.config.js | 9 +++++++++ tooling/playwright/package.json | 8 +++++++- tooling/playwright/tsconfig.json | 4 +--- tooling/prettier/tsconfig.json | 4 +--- tooling/tailwind/tsconfig.json | 4 +--- tooling/typescript/base.json | 4 +++- tooling/vitest/eslint.config.js | 9 +++++++++ tooling/vitest/package.json | 6 ++++++ tooling/vitest/tsconfig.json | 4 +--- 20 files changed, 79 insertions(+), 60 deletions(-) create mode 100644 packages/env/eslint.config.js create mode 100644 tooling/playwright/eslint.config.js create mode 100644 tooling/vitest/eslint.config.js diff --git a/apps/blog/tsconfig.json b/apps/blog/tsconfig.json index 80b829ed..6b6354e6 100644 --- a/apps/blog/tsconfig.json +++ b/apps/blog/tsconfig.json @@ -1,20 +1,9 @@ { "extends": "@ashgw/tsconfig/base.json", "compilerOptions": { - "lib": ["ES2022", "dom", "dom.iterable"], - "jsx": "preserve", "baseUrl": ".", - "module": "esnext", - "target": "ES2022", "paths": { "~/*": ["./src/*"] - }, - "plugins": [ - { - "name": "next" - } - ] - }, - "include": [".", ".next/types/**/*.ts"], - "exclude": ["node_modules"] + } + } } diff --git a/apps/www/package.json b/apps/www/package.json index 3220f778..75c12d0f 100644 --- a/apps/www/package.json +++ b/apps/www/package.json @@ -18,8 +18,8 @@ "lint": "pnpm run lint:ts ", "lint-all": "pnpm run lint:ts && pnpm run lint:md && pnpm run format && pnpm run lint:knip && pnpm run lint:spelling", "lint:ts": "tsc --noEmit; eslint .", - "lint:knip": "knip --production --strict --exclude exports,nsExports,types,nsTypes", "format": "prettier . --write", + "lint:knip": "knip --production --strict --exclude exports,nsExports,types,nsTypes", "format-check": "prettier --check .", "lint:md": "markdownlint \"**/*.md\" --config=.markdownlint.json --ignore-path=.markdownlintignore", "lint:spelling": "cspell \"**\" \".github/**/*\"", diff --git a/apps/www/tsconfig.json b/apps/www/tsconfig.json index 80b829ed..6b6354e6 100644 --- a/apps/www/tsconfig.json +++ b/apps/www/tsconfig.json @@ -1,20 +1,9 @@ { "extends": "@ashgw/tsconfig/base.json", "compilerOptions": { - "lib": ["ES2022", "dom", "dom.iterable"], - "jsx": "preserve", "baseUrl": ".", - "module": "esnext", - "target": "ES2022", "paths": { "~/*": ["./src/*"] - }, - "plugins": [ - { - "name": "next" - } - ] - }, - "include": [".", ".next/types/**/*.ts"], - "exclude": ["node_modules"] + } + } } diff --git a/packages/env/eslint.config.js b/packages/env/eslint.config.js new file mode 100644 index 00000000..8640519f --- /dev/null +++ b/packages/env/eslint.config.js @@ -0,0 +1,9 @@ +import baseConfig from "@ashgw/eslint-config/base"; + +/** @type {import('typescript-eslint').Config} */ +export default [ + { + ignores: ["dist/**"], + }, + ...baseConfig, +]; diff --git a/packages/env/index.ts b/packages/env/index.ts index 868dcda4..6c984ba0 100644 --- a/packages/env/index.ts +++ b/packages/env/index.ts @@ -1,9 +1,11 @@ +import path from "path"; import { config } from "dotenv"; import { z } from "zod"; import { createEnv } from "@ashgw/ts-env"; -config({ path: require("path").resolve(__dirname, "../../.env") }); +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +config({ path: path.resolve(__dirname, "../../.env") }); const isBrowser = typeof window !== "undefined"; diff --git a/packages/env/package.json b/packages/env/package.json index 43c2ee1f..5164c958 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -3,14 +3,20 @@ "exports": { ".": "./index.ts" }, + "type": "module", "private": true, "version": "0.1.0", + "scripts": { + "lint": "tsc --noEmit; eslint .", + "format": "prettier . --write" + }, "dependencies": { "@ashgw/ts-env": "^1.3.6", "zod": "catalog:", "dotenv": "^16.4.5" }, "devDependencies": { + "@ashgw/eslint-config": "workspace:*", "@ashgw/tsconfig": "workspace:*", "typescript": "catalog:" } diff --git a/packages/env/tsconfig.json b/packages/env/tsconfig.json index 9a946ec1..75084067 100644 --- a/packages/env/tsconfig.json +++ b/packages/env/tsconfig.json @@ -1,6 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "compilerOptions": { "lib": ["DOM", "ES2022"] }, - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json index 01e33353..75084067 100644 --- a/packages/ui/tsconfig.json +++ b/packages/ui/tsconfig.json @@ -1,10 +1,3 @@ { - "extends": "@ashgw/tsconfig/internal-package.json", - "compilerOptions": { - "lib": ["ES2022", "dom", "dom.iterable"], - "jsx": "preserve", - "rootDir": "." - }, - "include": ["src"], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5689f673..3b6155ba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -467,6 +467,9 @@ importers: specifier: 'catalog:' version: 3.23.8 devDependencies: + '@ashgw/eslint-config': + specifier: workspace:* + version: link:../../tooling/eslint '@ashgw/tsconfig': specifier: workspace:* version: link:../../tooling/typescript @@ -592,6 +595,9 @@ importers: tooling/playwright: devDependencies: + '@ashgw/eslint-config': + specifier: workspace:* + version: link:../eslint '@ashgw/tsconfig': specifier: workspace:* version: link:../typescript @@ -656,6 +662,9 @@ importers: tooling/vitest: devDependencies: + '@ashgw/eslint-config': + specifier: workspace:* + version: link:../eslint '@ashgw/tsconfig': specifier: workspace:* version: link:../typescript diff --git a/tooling/eslint/tsconfig.json b/tooling/eslint/tsconfig.json index 99fa424f..75084067 100644 --- a/tooling/eslint/tsconfig.json +++ b/tooling/eslint/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/tooling/playwright/base.ts b/tooling/playwright/base.ts index a453b4e2..e870aebc 100644 --- a/tooling/playwright/base.ts +++ b/tooling/playwright/base.ts @@ -1,5 +1,8 @@ import { defineConfig, devices } from "@playwright/test"; +/* eslint-disable turbo/no-undeclared-env-vars */ +const isRunningInCI = !!process.env.CI; + /** * Read environment variables from file. * https://github.com/motdotla/dotenv @@ -14,11 +17,11 @@ export const baseConfig = defineConfig({ /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, + forbidOnly: isRunningInCI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: isRunningInCI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: isRunningInCI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: "html", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ diff --git a/tooling/playwright/eslint.config.js b/tooling/playwright/eslint.config.js new file mode 100644 index 00000000..8640519f --- /dev/null +++ b/tooling/playwright/eslint.config.js @@ -0,0 +1,9 @@ +import baseConfig from "@ashgw/eslint-config/base"; + +/** @type {import('typescript-eslint').Config} */ +export default [ + { + ignores: ["dist/**"], + }, + ...baseConfig, +]; diff --git a/tooling/playwright/package.json b/tooling/playwright/package.json index 92646b6b..7903d595 100644 --- a/tooling/playwright/package.json +++ b/tooling/playwright/package.json @@ -3,11 +3,17 @@ "exports": { ".": "./index.ts" }, + "type": "module", "private": true, "version": "0.1.0", + "scripts": { + "lint": "tsc --noEmit; eslint .", + "format": "prettier . --write" + }, "devDependencies": { "@playwright/test": "catalog:", "@ashgw/tsconfig": "workspace:*", - "typescript": "catalog:" + "typescript": "catalog:", + "@ashgw/eslint-config": "workspace:*" } } diff --git a/tooling/playwright/tsconfig.json b/tooling/playwright/tsconfig.json index 99fa424f..75084067 100644 --- a/tooling/playwright/tsconfig.json +++ b/tooling/playwright/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/tooling/prettier/tsconfig.json b/tooling/prettier/tsconfig.json index 99fa424f..75084067 100644 --- a/tooling/prettier/tsconfig.json +++ b/tooling/prettier/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/tooling/tailwind/tsconfig.json b/tooling/tailwind/tsconfig.json index 99fa424f..75084067 100644 --- a/tooling/tailwind/tsconfig.json +++ b/tooling/tailwind/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" } diff --git a/tooling/typescript/base.json b/tooling/typescript/base.json index dadceb55..9fe71393 100644 --- a/tooling/typescript/base.json +++ b/tooling/typescript/base.json @@ -4,8 +4,10 @@ /** Base Options */ "esModuleInterop": true, "skipLibCheck": true, + "jsx": "preserve", "target": "ES2022", - "lib": ["ES2022"], + + "lib": ["ES2022", "dom", "dom.iterable"], "allowJs": true, "resolveJsonModule": true, "moduleDetection": "force", diff --git a/tooling/vitest/eslint.config.js b/tooling/vitest/eslint.config.js new file mode 100644 index 00000000..8640519f --- /dev/null +++ b/tooling/vitest/eslint.config.js @@ -0,0 +1,9 @@ +import baseConfig from "@ashgw/eslint-config/base"; + +/** @type {import('typescript-eslint').Config} */ +export default [ + { + ignores: ["dist/**"], + }, + ...baseConfig, +]; diff --git a/tooling/vitest/package.json b/tooling/vitest/package.json index 2ab158b2..d5cb2fb0 100644 --- a/tooling/vitest/package.json +++ b/tooling/vitest/package.json @@ -3,12 +3,18 @@ "exports": { ".": "./index.ts" }, + "type": "module", "private": true, "version": "0.1.0", + "scripts": { + "lint": "tsc --noEmit; eslint .", + "format": "prettier . --write" + }, "devDependencies": { "vitest": "catalog:", "@vitest/ui": "catalog:", "@ashgw/tsconfig": "workspace:*", + "@ashgw/eslint-config": "workspace:*", "typescript": "catalog:" } } diff --git a/tooling/vitest/tsconfig.json b/tooling/vitest/tsconfig.json index 99fa424f..75084067 100644 --- a/tooling/vitest/tsconfig.json +++ b/tooling/vitest/tsconfig.json @@ -1,5 +1,3 @@ { - "extends": "@ashgw/tsconfig/base.json", - "include": ["."], - "exclude": ["node_modules"] + "extends": "@ashgw/tsconfig/base.json" }