Skip to content

Commit

Permalink
tsconfig and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Aug 16, 2024
1 parent 3a6e3b9 commit f861976
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ node_modules
dist
dist-ssr
*.local
tsconfig.tsbuildinfo

# Editor directories and files
.idea
Expand Down
50 changes: 50 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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`.",
},
],
},
],
},
},
)
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
Expand Down
33 changes: 33 additions & 0 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
33 changes: 4 additions & 29 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down
23 changes: 19 additions & 4 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit f861976

Please sign in to comment.