From f861976fb78e1941907253a25bbd56a0734c5fed Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 16 Aug 2024 09:04:11 +0000 Subject: [PATCH] tsconfig and eslint --- .gitignore | 1 + eslint.config.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 20 ++++++++++++------- tsconfig.app.json | 33 ++++++++++++++++++++++++++++++ tsconfig.json | 33 ++++-------------------------- tsconfig.node.json | 23 +++++++++++++++++---- 6 files changed, 120 insertions(+), 40 deletions(-) create mode 100644 eslint.config.js create mode 100644 tsconfig.app.json diff --git a/.gitignore b/.gitignore index 048179c..73c9097 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ node_modules dist dist-ssr *.local +tsconfig.tsbuildinfo # Editor directories and files .idea diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..d3f0ba8 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,50 @@ +import js from "@eslint/js" +import globals from "globals" +import reactHooks from "eslint-plugin-react-hooks" +import reactRefresh from "eslint-plugin-react-refresh" +import tseslint from "typescript-eslint" + +export default tseslint.config( + { ignores: ["dist"] }, + { + extends: [js.configs.recommended, ...tseslint.configs.recommended], + files: ["**/*.{ts,tsx}"], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + }, + // TODO: add prettier plugin. + plugins: { + "react-hooks": reactHooks, + "react-refresh": reactRefresh, + }, + rules: { + ...reactHooks.configs.recommended.rules, + "sort-imports": ["error", { allowSeparatedGroups: true }], + "@typescript-eslint/no-empty-object-type": "off", + "@typescript-eslint/consistent-type-imports": [ + "error", + { fixStyle: "inline-type-imports" }, + ], + "@typescript-eslint/no-restricted-imports": [ + "error", + { + paths: [ + { + name: "react-redux", + importNames: ["useSelector", "useStore", "useDispatch"], + message: + "Please use pre-typed versions from `src/app/hooks.ts` instead.", + }, + ], + patterns: [ + { + group: ["codeforlife/src"], + message: "Please use `codeforlife` instead of `codeforlife/src`.", + }, + ], + }, + ], + }, + }, +) diff --git a/package.json b/package.json index 4880351..8e1e462 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,11 @@ { + "//": [ + "Based off of:", + "https://github.com/vitejs/vite/blob/main/packages/create-vite/template-react-ts/package.json", + "Dependency rules:", + "🚫 Don't add `dependencies` below that are inherited from the CFL package.", + "✅ Do add `devDependencies` below that are `peerDependencies` in the CFL package." + ], "name": "replace-me", "private": true, "version": "0.0.0", @@ -18,20 +25,15 @@ "lint:fix": "eslint --fix .", "type-check": "tsc --noEmit" }, - "//": [ - "🚫 Don't add `dependencies` below that are inherited from the CFL package.", - "✅ Do add `devDependencies` below that are `peerDependencies` in the CFL package." - ], "dependencies": { - "codeforlife": "github:ocadotechnology/codeforlife-package-javascript#v2.2.2", - "crypto-js": "^4.2.0" + "codeforlife": "github:ocadotechnology/codeforlife-package-javascript#template-frontend-1" }, "devDependencies": { + "@eslint/js": "^9.9.0", "@testing-library/dom": "^9.3.4", "@testing-library/jest-dom": "^6.2.0", "@testing-library/react": "^14.1.2", "@testing-library/user-event": "^14.5.2", - "@types/crypto-js": "^4.2.2", "@types/js-cookie": "^3.0.3", "@types/node": "^20.14.2", "@types/qs": "^6.9.7", @@ -44,9 +46,13 @@ "eslint-config-prettier": "^9.1.0", "eslint-config-react-app": "^7.0.1", "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-react-refresh": "^0.4.9", + "globals": "^15.9.0", "jsdom": "^23.2.0", "prettier": "^3.2.1", "typescript": "^5.3.3", + "typescript-eslint": "^8.1.0", "vite": "^5.0.11", "vitest": "^1.2.0" } diff --git a/tsconfig.app.json b/tsconfig.app.json new file mode 100644 index 0000000..17afe84 --- /dev/null +++ b/tsconfig.app.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": [ + "ES2020", + "DOM", + "DOM.Iterable" + ], + "module": "ESNext", + "skipLibCheck": true, + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + "jsx": "react-jsx", + "paths": { + "codeforlife/*": [ + "./node_modules/codeforlife/src/*" + ] + }, + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + }, + "include": [ + "src" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index ff10417..65f670c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,34 +1,9 @@ { - "compilerOptions": { - "target": "ESNext", - "useDefineForClassFields": true, - "lib": [ - "DOM", - "DOM.Iterable", - "ESNext" - ], - "allowJs": false, - "skipLibCheck": true, - "esModuleInterop": false, - "allowSyntheticDefaultImports": true, - "strict": true, - "module": "ESNext", - "moduleResolution": "bundler", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx", - "types": [ - "vitest/globals", - "node" - ], - "paths": { - "codeforlife/*": [ - "./node_modules/codeforlife/src/*" - ] - } - }, + "files": [], "references": [ + { + "path": "./tsconfig.app.json" + }, { "path": "./tsconfig.node.json" } diff --git a/tsconfig.node.json b/tsconfig.node.json index a535f7d..c2f5e7d 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,9 +1,24 @@ { "compilerOptions": { - "composite": true, + "target": "ES2022", + "lib": [ + "ES2023" + ], "module": "ESNext", + "skipLibCheck": true, + /* Bundler mode */ "moduleResolution": "bundler", - "allowSyntheticDefaultImports": true + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", + "noEmit": true, + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true }, - "include": ["vite.config.ts"] -} + "include": [ + "vite.config.ts" + ] +} \ No newline at end of file