From c4b4108eca9e8b52b7e80020f474e4ba950f07f6 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Sun, 6 Apr 2025 14:47:49 +0100 Subject: [PATCH] :wrench: improving typechecker and lint local performance (#4710) --- .devcontainer/devcontainer.json | 17 +++--- .gitignore | 3 + .prettierignore | 29 ++++++++++ README.md | 2 +- docker-compose.yml | 1 - eslint.config.mjs | 12 +++- package.json | 9 ++- packages/desktop-client/README.md | 3 + .../bin/remove-untranslated-languages | 6 +- packages/desktop-client/globals.d.ts | 1 - packages/desktop-client/src/fonts.scss | 2 +- packages/desktop-electron/.babelrc | 4 +- packages/desktop-electron/loading.html | 6 +- .../default-budget-template/metadata.json | 7 ++- .../loot-core/src/types/server-handlers.d.ts | 5 +- packages/loot-core/tsconfig.api.json | 27 +++++---- .../sync-server/src/app-gocardless/README.md | 3 + tsconfig.json | 1 + upcoming-release-notes/4710.md | 6 ++ yarn.lock | 56 +------------------ 20 files changed, 99 insertions(+), 101 deletions(-) create mode 100644 upcoming-release-notes/4710.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 14ff776221..f9ccba93f2 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,14 +1,11 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose { - "name": "Actual development", - "dockerComposeFile": [ - "../docker-compose.yml", - "docker-compose.yml" - ], - // Alternatively: - // "image": "mcr.microsoft.com/devcontainers/typescript-node:0-16", - "service": "actual-development", - "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", - "postCreateCommand": "yarn install" + "name": "Actual development", + "dockerComposeFile": ["../docker-compose.yml", "docker-compose.yml"], + // Alternatively: + // "image": "mcr.microsoft.com/devcontainers/typescript-node:0-16", + "service": "actual-development", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "postCreateCommand": "yarn install" } diff --git a/.gitignore b/.gitignore index 6df9858b40..8a714340c1 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ package.tgz # Fly.io configuration fly.toml + +# TypeScript cache +build/ diff --git a/.prettierignore b/.prettierignore index 2faa2ef87d..bfdf11b887 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,30 @@ sync_pb.* +packages/api/app/bundle.api.js +packages/api/app/stats.json +packages/api/dist +packages/api/@types +packages/api/migrations +packages/crdt/dist +packages/component-library/src/icons/**/* +packages/desktop-client/bundle.browser.js +packages/desktop-client/build/ +packages/desktop-client/locale/ +packages/desktop-client/build-electron/ +packages/desktop-client/build-stats/ +packages/desktop-client/public/kcab/ +packages/desktop-client/public/data/ +packages/desktop-client/**/node_modules/* +packages/desktop-client/node_modules/ +packages/desktop-client/test-results/ +packages/desktop-client/playwright-report/ +packages/desktop-electron/client-build/ +packages/desktop-electron/build/ +packages/desktop-electron/dist/ +packages/import-ynab4/**/node_modules/* +packages/import-ynab5/**/node_modules/* +packages/loot-core/**/node_modules/* +packages/loot-core/**/lib-dist/* +packages/loot-core/**/proto/* +.yarn/* +.github/* +upcoming-release-notes/* diff --git a/README.md b/README.md index 1c65695f01..4886a8eb80 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ To add new feature requests, open a new Issue of the "Feature Request" type. ### Translation -Make Actual Budget accessible to more people by helping with the [Internationalization](https://actualbudget.org/docs/contributing/i18n/) of Actual. We are using a crowd sourcing tool to manage the translations, see our [Weblate Project](https://hosted.weblate.org/projects/actualbudget/). Weblate proudly supports open-source software projects through their [Libre plan](https://weblate.org/en/hosting/#libre). +Make Actual Budget accessible to more people by helping with the [Internationalization](https://actualbudget.org/docs/contributing/i18n/) of Actual. We are using a crowd sourcing tool to manage the translations, see our [Weblate Project](https://hosted.weblate.org/projects/actualbudget/). Weblate proudly supports open-source software projects through their [Libre plan](https://weblate.org/en/hosting/#libre). Translation status diff --git a/docker-compose.yml b/docker-compose.yml index 91c62a9161..e2e1d83659 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,4 +15,3 @@ services: volumes: - '.:/app' restart: 'no' - diff --git a/eslint.config.mjs b/eslint.config.mjs index 89ea5abb41..816b5b96c3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,7 +5,6 @@ import globals from 'globals'; import pluginImport from 'eslint-plugin-import'; import pluginJSXA11y from 'eslint-plugin-jsx-a11y'; -import pluginPrettier from 'eslint-plugin-prettier/recommended'; import pluginReact from 'eslint-plugin-react'; import pluginReactHooks from 'eslint-plugin-react-hooks'; import pluginRulesDir from 'eslint-plugin-rulesdir'; @@ -90,6 +89,7 @@ export default [ { ignores: [ 'packages/api/app/bundle.api.js', + 'packages/api/app/stats.json', 'packages/api/dist', 'packages/api/@types', 'packages/api/migrations', @@ -145,7 +145,6 @@ export default [ }, pluginReact.configs.flat.recommended, pluginReact.configs.flat['jsx-runtime'], - pluginPrettier, ...pluginTypescript.configs.recommended, pluginImport.flatConfigs.recommended, { @@ -529,7 +528,7 @@ export default [ sourceType: 'module', parserOptions: { - project: [path.join(__dirname, './tsconfig.json')], + projectService: true, ecmaFeatures: { jsx: true, }, @@ -549,6 +548,13 @@ export default [ // 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477) 'no-undef': 'off', + // TypeScript already handles these (https://typescript-eslint.io/troubleshooting/typed-linting/performance/#eslint-plugin-import) + 'import/named': 'off', + 'import/namespace': 'off', + 'import/default': 'off', + 'import/no-named-as-default-member': 'off', + 'import/no-unresolved': 'off', + // Add TypeScript specific rules (and turn off ESLint equivalents) '@typescript-eslint/consistent-type-assertions': 'warn', 'no-array-constructor': 'off', diff --git a/package.json b/package.json index c60d1cd197..fff5363581 100644 --- a/package.json +++ b/package.json @@ -45,10 +45,10 @@ "vrt:docker": "./bin/run-vrt", "rebuild-electron": "./node_modules/.bin/electron-rebuild -f -m ./packages/loot-core", "rebuild-node": "yarn workspace loot-core rebuild", - "lint": "eslint . --max-warnings 0", - "lint:verbose": "DEBUG=eslint:cli-engine eslint . --max-warnings 0", + "lint": "prettier --check . && eslint . --max-warnings 0", + "lint:fix": "prettier --check --write . && eslint . --max-warnings 0 --fix", "install:server": "yarn workspaces focus @actual-app/sync-server --production", - "typecheck": "yarn tsc && tsc-strict", + "typecheck": "yarn tsc --incremental && tsc-strict", "jq": "./node_modules/node-jq/bin/jq", "prepare": "husky" }, @@ -61,7 +61,6 @@ "eslint-import-resolver-typescript": "^4.2.2", "eslint-plugin-import": "^2.31.0", "eslint-plugin-jsx-a11y": "^6.10.2", - "eslint-plugin-prettier": "5.2.3", "eslint-plugin-react": "^7.37.4", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-rulesdir": "^0.2.2", @@ -85,7 +84,7 @@ "node": ">=18.0.0" }, "lint-staged": { - "*.{js,jsx,ts,tsx,md,json}": "prettier --write" + "*.{js,jsx,ts,tsx,md,json,yml}": "prettier --write" }, "packageManager": "yarn@4.7.0", "browserslist": [ diff --git a/packages/desktop-client/README.md b/packages/desktop-client/README.md index e87bbc222f..b22016d9bc 100644 --- a/packages/desktop-client/README.md +++ b/packages/desktop-client/README.md @@ -39,6 +39,7 @@ HTTPS=true yarn start ``` or using the dev container: + ``` HTTPS=true docker compose up --build ``` @@ -82,6 +83,7 @@ E2E_START_URL=https://ip:port yarn vrt You can also run the tests against a remote server by passing the URL: Run in standardized docker container: + ```sh E2E_START_URL=https://my-remote-server.com yarn vrt:docker @@ -90,6 +92,7 @@ E2E_START_URL=https://my-remote-server.com yarn vrt:docker ``` Run locally: + ```sh E2E_START_URL=https://my-remote-server.com yarn vrt ``` diff --git a/packages/desktop-client/bin/remove-untranslated-languages b/packages/desktop-client/bin/remove-untranslated-languages index 79a093888d..b3ff4c15f6 100755 --- a/packages/desktop-client/bin/remove-untranslated-languages +++ b/packages/desktop-client/bin/remove-untranslated-languages @@ -20,7 +20,7 @@ const processTranslations = () => { console.log(`en.json has ${enKeysCount} keys.`); - files.forEach((file) => { + files.forEach(file => { if (file === 'en.json' || path.extname(file) !== '.json') return; if (file.startsWith('en-')) { @@ -34,7 +34,9 @@ const processTranslations = () => { // Calculate the percentage of keys present compared to en.json const percentage = (fileKeysCount / enKeysCount) * 100; - console.log(`${file} has ${fileKeysCount} keys (${percentage.toFixed(2)}%).`); + console.log( + `${file} has ${fileKeysCount} keys (${percentage.toFixed(2)}%).`, + ); if (percentage < 50) { fs.unlinkSync(filePath); diff --git a/packages/desktop-client/globals.d.ts b/packages/desktop-client/globals.d.ts index 2b7573a126..fe760e575c 100644 --- a/packages/desktop-client/globals.d.ts +++ b/packages/desktop-client/globals.d.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line import/no-unresolved import { type CSSObject } from '@emotion/css/dist/declarations/src/create-instance'; // Allow images to be imported diff --git a/packages/desktop-client/src/fonts.scss b/packages/desktop-client/src/fonts.scss index cd47daca1a..85079b5193 100644 --- a/packages/desktop-client/src/fonts.scss +++ b/packages/desktop-client/src/fonts.scss @@ -3,4 +3,4 @@ ); @include variable.default; -@import "@fontsource/redacted-script"; +@import '@fontsource/redacted-script'; diff --git a/packages/desktop-electron/.babelrc b/packages/desktop-electron/.babelrc index 93ef664b75..4e5240d9c9 100644 --- a/packages/desktop-electron/.babelrc +++ b/packages/desktop-electron/.babelrc @@ -1,5 +1,3 @@ { - plugins: [ - 'babel-plugin-transform-es2015-modules-commonjs' - ] + "plugins": ["babel-plugin-transform-es2015-modules-commonjs"] } diff --git a/packages/desktop-electron/loading.html b/packages/desktop-electron/loading.html index 67e3718ef9..4660d58ef3 100644 --- a/packages/desktop-electron/loading.html +++ b/packages/desktop-electron/loading.html @@ -1,4 +1,4 @@ - + -
- Waiting for development server... -
+
Waiting for development server...
diff --git a/packages/loot-core/src/mocks/files/default-budget-template/metadata.json b/packages/loot-core/src/mocks/files/default-budget-template/metadata.json index f216d86b5e..0aef258c7c 100644 --- a/packages/loot-core/src/mocks/files/default-budget-template/metadata.json +++ b/packages/loot-core/src/mocks/files/default-budget-template/metadata.json @@ -1 +1,6 @@ -{"id":"Default-Test-Db","budgetName":"Default Test Db","budgetVersion":"0.0.1","isCached":true} +{ + "id": "Default-Test-Db", + "budgetName": "Default Test Db", + "budgetVersion": "0.0.1", + "isCached": true +} diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts index 1fc2ffc271..c2d1905df4 100644 --- a/packages/loot-core/src/types/server-handlers.d.ts +++ b/packages/loot-core/src/types/server-handlers.d.ts @@ -1,11 +1,10 @@ import { Backup } from '../server/backups'; import { RemoteFile } from '../server/cloud-storage'; import { Message } from '../server/sync'; +import { QueryState } from '../shared/query'; import { Budget } from './budget'; import { OpenIdConfig } from './models/openid'; -// eslint-disable-next-line import/no-unresolved -import { Query } from './query'; import { EmptyObject } from './util'; export interface ServerHandlers { @@ -20,7 +19,7 @@ export interface ServerHandlers { }) => Promise<{ filters: unknown[] }>; // eslint-disable-next-line @typescript-eslint/no-explicit-any - query: (query: Query) => Promise<{ data: any; dependencies: string[] }>; + query: (query: QueryState) => Promise<{ data: any; dependencies: string[] }>; 'key-make': (arg: { password; diff --git a/packages/loot-core/tsconfig.api.json b/packages/loot-core/tsconfig.api.json index 5ffe224f8c..6e6c7fd521 100644 --- a/packages/loot-core/tsconfig.api.json +++ b/packages/loot-core/tsconfig.api.json @@ -1,12 +1,17 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "declaration": true, - "emitDeclarationOnly": true, - "allowJs": false, - "noEmit": false, - }, - "include": ["./typings", "./src/server/*"], - "exclude": ["**/node_modules/*", "**/build/*", "**/lib-dist/*", "./src/server/bench.ts"], - } \ No newline at end of file + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "declaration": true, + "emitDeclarationOnly": true, + "allowJs": false, + "noEmit": false + }, + "include": ["./typings", "./src/server/*"], + "exclude": [ + "**/node_modules/*", + "**/build/*", + "**/lib-dist/*", + "./src/server/bench.ts" + ] +} diff --git a/packages/sync-server/src/app-gocardless/README.md b/packages/sync-server/src/app-gocardless/README.md index b24bd3f519..985b9a4ab4 100644 --- a/packages/sync-server/src/app-gocardless/README.md +++ b/packages/sync-server/src/app-gocardless/README.md @@ -164,13 +164,16 @@ If the default bank integration does not work for you, you can integrate a new b 7. Remember to add tests for new bank integration in ## normalizeTransaction + This is the most commonly used override as it allows you to change the data that is returned to the client. Please follow the following patterns when implementing a custom normalizeTransaction method: + 1. If you need to edit the values of transaction fields (excluding the transaction amount) do not mutate the original transaction object. Instead, create a shallow copy and make your changes there. 2. End the function by returning the result of calling the fallback normalizeTransaction method from integration-bank.js E.g. + ```js import Fallback from './integration-bank.js'; diff --git a/tsconfig.json b/tsconfig.json index 16e4bf2cf9..6daceeecec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -42,6 +42,7 @@ }, "include": ["packages/**/*", "bin/*.ts"], "exclude": [ + "**/.*/", "node_modules", "**/node_modules/*", "**/build/*", diff --git a/upcoming-release-notes/4710.md b/upcoming-release-notes/4710.md new file mode 100644 index 0000000000..c9ab2d7b91 --- /dev/null +++ b/upcoming-release-notes/4710.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [MatissJanis] +--- + +improving typechecker and lint local performance diff --git a/yarn.lock b/yarn.lock index b1df6b80ee..71a94852ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3075,13 +3075,6 @@ __metadata: languageName: node linkType: hard -"@pkgr/core@npm:^0.1.0": - version: 0.1.1 - resolution: "@pkgr/core@npm:0.1.1" - checksum: 10/6f25fd2e3008f259c77207ac9915b02f1628420403b2630c92a07ff963129238c9262afc9e84344c7a23b5cc1f3965e2cd17e3798219f5fd78a63d144d3cceba - languageName: node - linkType: hard - "@playwright/test@npm:1.41.2": version: 1.41.2 resolution: "@playwright/test@npm:1.41.2" @@ -7081,7 +7074,6 @@ __metadata: eslint-import-resolver-typescript: "npm:^4.2.2" eslint-plugin-import: "npm:^2.31.0" eslint-plugin-jsx-a11y: "npm:^6.10.2" - eslint-plugin-prettier: "npm:5.2.3" eslint-plugin-react: "npm:^7.37.4" eslint-plugin-react-hooks: "npm:^5.2.0" eslint-plugin-rulesdir: "npm:^0.2.2" @@ -10950,26 +10942,6 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-prettier@npm:5.2.3": - version: 5.2.3 - resolution: "eslint-plugin-prettier@npm:5.2.3" - dependencies: - prettier-linter-helpers: "npm:^1.0.0" - synckit: "npm:^0.9.1" - peerDependencies: - "@types/eslint": ">=8.0.0" - eslint: ">=8.0.0" - eslint-config-prettier: "*" - prettier: ">=3.0.0" - peerDependenciesMeta: - "@types/eslint": - optional: true - eslint-config-prettier: - optional: true - checksum: 10/6444a0b89f3e2a6b38adce69761133f8539487d797f1655b3fa24f93a398be132c4f68f87041a14740b79202368d5782aa1dffd2bd7a3ea659f263d6796acf15 - languageName: node - linkType: hard - "eslint-plugin-react-hooks@npm:^5.2.0": version: 5.2.0 resolution: "eslint-plugin-react-hooks@npm:5.2.0" @@ -11499,13 +11471,6 @@ __metadata: languageName: node linkType: hard -"fast-diff@npm:^1.1.2": - version: 1.2.0 - resolution: "fast-diff@npm:1.2.0" - checksum: 10/f62419b3d770f201d51c3ee8c4443b752b3ba2d548a6639026b7e09a08203ed2699a8d1fe21efcb8c5186135002d5d2916c12a687cac63785626456a92915adc - languageName: node - linkType: hard - "fast-equals@npm:^4.0.3": version: 4.0.3 resolution: "fast-equals@npm:4.0.3" @@ -17394,15 +17359,6 @@ __metadata: languageName: node linkType: hard -"prettier-linter-helpers@npm:^1.0.0": - version: 1.0.0 - resolution: "prettier-linter-helpers@npm:1.0.0" - dependencies: - fast-diff: "npm:^1.1.2" - checksum: 10/00ce8011cf6430158d27f9c92cfea0a7699405633f7f1d4a45f07e21bf78e99895911cbcdc3853db3a824201a7c745bd49bfea8abd5fb9883e765a90f74f8392 - languageName: node - linkType: hard - "prettier@npm:^2.8.7": version: 2.8.8 resolution: "prettier@npm:2.8.8" @@ -20190,16 +20146,6 @@ __metadata: languageName: node linkType: hard -"synckit@npm:^0.9.1": - version: 0.9.1 - resolution: "synckit@npm:0.9.1" - dependencies: - "@pkgr/core": "npm:^0.1.0" - tslib: "npm:^2.6.2" - checksum: 10/bff3903976baf8b699b5483228116d70223781a93b17c70e685c277ee960cdfd1a09cb5a741e6a9ec35e2428f14f4664baec41ccc99a598f267608b2a54f529b - languageName: node - linkType: hard - "tapable@npm:^2.1.1, tapable@npm:^2.2.0": version: 2.2.1 resolution: "tapable@npm:2.2.1" @@ -20716,7 +20662,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.0.3, tslib@npm:^2.3.0, tslib@npm:^2.4.0, tslib@npm:^2.6.2": +"tslib@npm:^2.0.3, tslib@npm:^2.3.0, tslib@npm:^2.4.0": version: 2.6.2 resolution: "tslib@npm:2.6.2" checksum: 10/bd26c22d36736513980091a1e356378e8b662ded04204453d353a7f34a4c21ed0afc59b5f90719d4ba756e581a162ecbf93118dc9c6be5acf70aa309188166ca