From c31a840918a85cff9e2c754db04049d6241852af Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 15:17:32 -0300 Subject: [PATCH 1/7] frontend: add more import rules --- .eslintrc.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index 4021046e18..256953dcfb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -61,6 +61,12 @@ module.exports = { 'simple-import-sort/exports': 'error', 'simple-import-sort/imports': 'error', 'sort-imports': 'off', + 'import/no-unresolved': 'error', + 'import/named': 'error', + 'import/default': 'error', + 'import/namespace': 'error', + 'import/no-extraneous-dependencies': 'error', + 'import/no-mutable-exports': 'error', '@typescript-eslint/no-useless-constructor': ['error'], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-shadow': ['error'], From 37025895d1d5e81d21c1a147f9212e80a96346aa Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 15:48:04 -0300 Subject: [PATCH 2/7] frontend: ignore false-positive hit of extra-parens eslint rule --- core/frontend/src/components/kraken/BackAlleyTab.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/frontend/src/components/kraken/BackAlleyTab.vue b/core/frontend/src/components/kraken/BackAlleyTab.vue index b479890ee5..cfdc96e376 100644 --- a/core/frontend/src/components/kraken/BackAlleyTab.vue +++ b/core/frontend/src/components/kraken/BackAlleyTab.vue @@ -338,7 +338,7 @@ export default Vue.extend({ return [] } - return (this.manifest as ExtensionData[]).sort( + return (this.manifest as ExtensionData[]).sort( // eslint-disable-line no-extra-parens (a, b) => (b?.repo_info?.downloads ?? 0) - (a?.repo_info?.downloads ?? 0), ) }, From f98a3809f8b61c527133c0ff5c8e0cdca5838601 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 15:49:00 -0300 Subject: [PATCH 3/7] frontend: add type-check command --- core/frontend/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/frontend/package.json b/core/frontend/package.json index c74dd58817..89f24d6cf7 100644 --- a/core/frontend/package.json +++ b/core/frontend/package.json @@ -11,7 +11,8 @@ "dev": "vite --host", "build": "NODE_ENV=production vite build", "serve": "echo 'This is a preview server for testing the built website. Please use `dev` command over `serve`.\nStarting preview server in 5 seconds..\n';sleep 5; vite preview", - "lint": "eslint --max-warnings=0 --ext .js,.vue --ignore-path .gitignore --ignore-pattern src/components/vue-tour src" + "lint": "eslint --max-warnings=0 --ext .js,.vue --ignore-path .gitignore --ignore-pattern src/components/vue-tour src", + "type-check": "tsc --noEmit" }, "dependencies": { "@google/model-viewer": "^3.0.0", From e862291e57d5f66a4644769ede40de6df4c35104 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 15:49:27 -0300 Subject: [PATCH 4/7] frontend: calibrations.ts: make it ts-friendly --- .../components/vehiclesetup/calibration.ts | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/core/frontend/src/components/vehiclesetup/calibration.ts b/core/frontend/src/components/vehiclesetup/calibration.ts index 369b067c4f..9ee27a4fc6 100644 --- a/core/frontend/src/components/vehiclesetup/calibration.ts +++ b/core/frontend/src/components/vehiclesetup/calibration.ts @@ -57,6 +57,10 @@ class Calibrator { * @param {PreflightCalibration} type */ private static start(type: PreflightCalibration): void { + const getParamValue = (mapping: Partial>): number => { + return mapping[type] ?? 0; + }; + mavlink2rest.sendMessage({ header: { system_id: 255, @@ -65,30 +69,30 @@ class Calibrator { }, message: { type: MAVLinkType.COMMAND_LONG, - param1: { + param1: getParamValue({ [PreflightCalibration.GYROSCOPE]: 1, [PreflightCalibration.GYROSCOPE_TEMPERATURE]: 3, - }[type] || 0, + }), param2: type === PreflightCalibration.MAGNETOMETER ? 1 : 0, param3: type === PreflightCalibration.PRESSURE ? 1 : 0, - param4: { + param4: getParamValue({ [PreflightCalibration.RC]: 1, [PreflightCalibration.RC_TRIM]: 2, - }[type] || 0, - param5: { + }), + param5: getParamValue({ [PreflightCalibration.ACCELEROMETER]: 1, [PreflightCalibration.BOARD_LEVEL]: 2, [PreflightCalibration.ACCELEROMETER_TEMPERATURE]: 3, [PreflightCalibration.SIMPLE_ACCELEROMETER]: 4, - }[type] || 0, - param6: { + }), + param6: getParamValue({ [PreflightCalibration.COMPASS_MOTOR_INTERFERENCE]: 1, [PreflightCalibration.AIRPSEED]: 2, - }[type] || 0, - param7: { + }), + param7: getParamValue({ [PreflightCalibration.ESC]: 1, [PreflightCalibration.BAROMETER_TEMPERATURE]: 3, - }[type] || 0, + }), command: { type: MavCmd.MAV_CMD_PREFLIGHT_CALIBRATION, }, @@ -96,7 +100,7 @@ class Calibrator { target_component: 1, confirmation: 0, }, - }) + }); } /** From 611caccd5d0461232914f09bb1336ba1b9e50384 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 15:49:50 -0300 Subject: [PATCH 5/7] update tsconfig.json --- core/frontend/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/frontend/tsconfig.json b/core/frontend/tsconfig.json index 2d1ac1dabe..baf37047f8 100644 --- a/core/frontend/tsconfig.json +++ b/core/frontend/tsconfig.json @@ -5,7 +5,7 @@ "strict": true, "jsx": "preserve", "importHelpers": true, - "moduleResolution": "bundler", + "moduleResolution": "node", "moduleDetection": "force", "skipLibCheck": true, "esModuleInterop": true, @@ -15,7 +15,6 @@ "baseUrl": ".", "experimentalDecorators": true, "types": [ - "webpack-env", "vite/client" ], "paths": { From c209e409b67bf83e76cd82a9c5fa6f059df1889e Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 17:19:42 -0300 Subject: [PATCH 6/7] Frontend: make tsc type-check happy --- core/frontend/src/one-more-time.ts | 4 ++-- .../colors/{blue_robotics.js => blue_robotics.ts} | 0 .../src/style/colors/{default.js => default.ts} | 0 core/frontend/src/style/colors/vuetify.js | 10 ---------- .../src/types/autopilot/parameter-table.ts | 2 +- core/frontend/src/types/shims-general.ts | 14 +------------- core/frontend/src/utils/ardupilot_mavlink.ts | 3 +-- 7 files changed, 5 insertions(+), 28 deletions(-) rename core/frontend/src/style/colors/{blue_robotics.js => blue_robotics.ts} (100%) rename core/frontend/src/style/colors/{default.js => default.ts} (100%) delete mode 100644 core/frontend/src/style/colors/vuetify.js diff --git a/core/frontend/src/one-more-time.ts b/core/frontend/src/one-more-time.ts index fe07c1239a..bf67e7ccd9 100644 --- a/core/frontend/src/one-more-time.ts +++ b/core/frontend/src/one-more-time.ts @@ -70,7 +70,7 @@ export class OneMoreTime { const id = setInterval(() => { // Check if object does not exist anymore or if it was destroyed by vue // eslint-disable-next-line - if (!ref.deref() || ref.deref()._isDestroyed) { + if (!ref.deref() || (ref.deref() as any)._isDestroyed) { this.stop() clearInterval(id) } @@ -131,7 +131,7 @@ export class OneMoreTime { } // Celebrate and dance so free - [Symbol.dispose](): void { + [(Symbol as any).dispose](): void { this.stop() } diff --git a/core/frontend/src/style/colors/blue_robotics.js b/core/frontend/src/style/colors/blue_robotics.ts similarity index 100% rename from core/frontend/src/style/colors/blue_robotics.js rename to core/frontend/src/style/colors/blue_robotics.ts diff --git a/core/frontend/src/style/colors/default.js b/core/frontend/src/style/colors/default.ts similarity index 100% rename from core/frontend/src/style/colors/default.js rename to core/frontend/src/style/colors/default.ts diff --git a/core/frontend/src/style/colors/vuetify.js b/core/frontend/src/style/colors/vuetify.js deleted file mode 100644 index f4246e35b7..0000000000 --- a/core/frontend/src/style/colors/vuetify.js +++ /dev/null @@ -1,10 +0,0 @@ -/* eslint-disable */ -module.exports = { - VUETIFY_PRIMARY: '#1976D2', - VUETIFY_SECONDARY: '#424242', - VUETIFY_ACCENT: '#82B1FF', - VUETIFY_SUCCESS: '#4CAF50', - VUETIFY_ERROR: '#FF5252', - VUETIFY_INFO: '#2196F3', - VUETIFY_WARNING: '#e0a600', -} diff --git a/core/frontend/src/types/autopilot/parameter-table.ts b/core/frontend/src/types/autopilot/parameter-table.ts index 0ac3d47c60..c86ffc5e13 100644 --- a/core/frontend/src/types/autopilot/parameter-table.ts +++ b/core/frontend/src/types/autopilot/parameter-table.ts @@ -148,7 +148,7 @@ export default class ParametersTable { console.log(`ignoring ${name} : ${parameter}`) continue } - this.metadata[name] = parameter + this.metadata[name] = (parameter as Metadata) } } } diff --git a/core/frontend/src/types/shims-general.ts b/core/frontend/src/types/shims-general.ts index 984a241bb5..94d6cc10ce 100644 --- a/core/frontend/src/types/shims-general.ts +++ b/core/frontend/src/types/shims-general.ts @@ -1,25 +1,13 @@ declare module '*.svg' { const value: string - export default value } declare module '*.jpg' { const value: string - export default value } declare module '*.png' { const value: string - export default value } -declare module '*.glb' { - const value: string - export default value -} - -declare module 'vue-tooltip-directive' - -declare module '@/assets/colors/default' -declare module '@/assets/colors/blue_robotics' -declare module '@/assets/colors/vuetify' +declare module 'vue-tooltip-directive' \ No newline at end of file diff --git a/core/frontend/src/utils/ardupilot_mavlink.ts b/core/frontend/src/utils/ardupilot_mavlink.ts index 9d35e2a401..7fee10040c 100644 --- a/core/frontend/src/utils/ardupilot_mavlink.ts +++ b/core/frontend/src/utils/ardupilot_mavlink.ts @@ -81,10 +81,9 @@ export function getMode(): number { } export async function setMode(mode: number, tries?: number): Promise { - tries = tries || 5 let current_try = 0 return new Promise(async (resolve, reject) => { - while (getMode() !== mode && current_try < tries) { + while (getMode() !== mode && current_try < (tries ?? 5)) { current_try += 1 mavlink2rest.sendCommandLong( MavCmd.MAV_CMD_DO_SET_MODE, From 78656bc84d6b5badf332f1a3678154f6c2bffac7 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Wed, 18 Sep 2024 17:22:31 -0300 Subject: [PATCH 7/7] CI: add typescript type-checking --- .github/workflows/test-and-deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index b7706c78d8..2c8612074b 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -62,6 +62,9 @@ jobs: - name: Bun lint run: bun --cwd ./core/frontend lint + - name: Type-checking + run: bun --cwd ./core/frontend run type-check + - name: Bun build run: bun run --cwd ./core/frontend build