From d7d48243719007edd994c71d3de1843ffbbe4227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kiss=20R=C3=B3bert?= Date: Mon, 15 Dec 2025 20:36:15 +0100 Subject: [PATCH] style: use recommended `prefer-const` eslint rule --- eslint.config.mjs | 1 - packages/mcumgr/src/util/cbor.ts | 58 +++++++++---------- .../src/util/backup-user-configuration.ts | 2 +- .../config-items/key-action/key-action.ts | 2 +- .../config-items/macro-action/macro-action.ts | 2 +- .../config-items/module-configuration.ts | 2 +- .../config-serializer/config-items/module.ts | 2 +- packages/uhk-usb/src/uhk-hid-device.ts | 2 +- .../src/utils/convert-ms-to-duration.ts | 4 +- .../src/utils/list-available-devices.ts | 4 +- .../svg-keystroke-key.component.ts | 3 +- .../monaco-editor-completion-item-provider.ts | 2 +- .../app/services/uhk80-migrator.service.ts | 2 +- .../app/store/reducers/user-configuration.ts | 2 +- 14 files changed, 43 insertions(+), 45 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 2f23c4caf46..58e7c9e46db 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -35,7 +35,6 @@ export const typescriptRules = { 'no-async-promise-executor': 'off', 'no-case-declarations': 'off', 'no-prototype-builtins': 'off', - 'prefer-const': 'off', } export default [ diff --git a/packages/mcumgr/src/util/cbor.ts b/packages/mcumgr/src/util/cbor.ts index 7ec38d54731..a0b0072be64 100644 --- a/packages/mcumgr/src/util/cbor.ts +++ b/packages/mcumgr/src/util/cbor.ts @@ -21,14 +21,14 @@ export function encode(value: any) { function prepareWrite(length: number) { let newByteLength = data.byteLength; - let requiredLength = offset + length; + const requiredLength = offset + length; while (newByteLength < requiredLength) newByteLength <<= 1; if (newByteLength !== data.byteLength) { - let oldDataView = dataView; + const oldDataView = dataView; data = new ArrayBuffer(newByteLength); dataView = new DataView(data); - let uint32count = (offset + 3) >> 2; + const uint32count = (offset + 3) >> 2; for (let i = 0; i < uint32count; ++i) dataView.setUint32(i << 2, oldDataView.getUint32(i << 2)); } @@ -46,7 +46,7 @@ export function encode(value: any) { commitWrite(prepareWrite(1).setUint8(offset, value)); } function writeUint8Array(value) { - let dataView = prepareWrite(value.length); + const dataView = prepareWrite(value.length); for (let i = 0; i < value.length; ++i) dataView.setUint8(offset + i, value[i]); commitWrite(); @@ -58,9 +58,9 @@ export function encode(value: any) { commitWrite(prepareWrite(4).setUint32(offset, value)); } function writeUint64(value) { - let low = value % POW_2_32; - let high = (value - low) / POW_2_32; - let dataView = prepareWrite(8); + const low = value % POW_2_32; + const high = (value - low) / POW_2_32; + const dataView = prepareWrite(8); dataView.setUint32(offset, high); dataView.setUint32(offset + 4, low); commitWrite(); @@ -107,7 +107,7 @@ export function encode(value: any) { return writeFloat64(value); case "string": - let utf8data = []; + const utf8data = []; for (i = 0; i < value.length; ++i) { let charCode = value.charCodeAt(i); if (charCode < 0x80) { @@ -145,11 +145,11 @@ export function encode(value: any) { writeTypeAndLength(2, value.length); writeUint8Array(value); } else { - let keys = Object.keys(value); + const keys = Object.keys(value); length = keys.length; writeTypeAndLength(5, length); for (i = 0; i < length; ++i) { - let key = keys[i]; + const key = keys[i]; encodeItem(key); encodeItem(value[key]); } @@ -162,15 +162,15 @@ export function encode(value: any) { if ("slice" in data) return data.slice(0, offset); - let ret = new ArrayBuffer(offset); - let retView = new DataView(ret); + const ret = new ArrayBuffer(offset); + const retView = new DataView(ret); for (let i = 0; i < offset; ++i) retView.setUint8(i, dataView.getUint8(i)); return ret; } export function decode(data: any, tagger?: Function, simpleValue?: Function) { - let dataView = new DataView(data); + const dataView = new DataView(data); let offset = 0; if (typeof tagger !== "function") @@ -186,13 +186,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { return commitRead(length, new Uint8Array(data, offset, length)); } function readFloat16() { - let tempArrayBuffer = new ArrayBuffer(4); - let tempDataView = new DataView(tempArrayBuffer); - let value = readUint16(); + const tempArrayBuffer = new ArrayBuffer(4); + const tempDataView = new DataView(tempArrayBuffer); + const value = readUint16(); - let sign = value & 0x8000; + const sign = value & 0x8000; let exponent = value & 0x7c00; - let fraction = value & 0x03ff; + const fraction = value & 0x03ff; if (exponent === 0x7c00) exponent = 0xff << 10; @@ -244,10 +244,10 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { throw "Invalid length encoding"; } function readIndefiniteStringLength(majorType) { - let initialByte = readUint8(); + const initialByte = readUint8(); if (initialByte === 0xff) return -1; - let length = readLength(initialByte & 0x1f); + const length = readLength(initialByte & 0x1f); if (length < 0 || (initialByte >> 5) !== majorType) throw "Invalid indefinite length element"; return length; @@ -286,9 +286,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { } function decodeItem() { - let initialByte = readUint8(); - let majorType = initialByte >> 5; - let additionalInformation = initialByte & 0x1f; + const initialByte = readUint8(); + const majorType = initialByte >> 5; + const additionalInformation = initialByte & 0x1f; let i; let length; @@ -314,13 +314,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { return -1 - length; case 2: if (length < 0) { - let elements = []; + const elements = []; let fullArrayLength = 0; while ((length = readIndefiniteStringLength(majorType)) >= 0) { fullArrayLength += length; elements.push(readArrayBuffer(length)); } - let fullArray = new Uint8Array(fullArrayLength); + const fullArray = new Uint8Array(fullArrayLength); let fullArrayOffset = 0; for (i = 0; i < elements.length; ++i) { fullArray.set(elements[i], fullArrayOffset); @@ -330,7 +330,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { } return readArrayBuffer(length); case 3: - let utf16data = []; + const utf16data = []; if (length < 0) { while ((length = readIndefiniteStringLength(majorType)) >= 0) appendUtf16Data(utf16data, length); @@ -350,9 +350,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { } return retArray; case 5: - let retObject = {}; + const retObject = {}; for (i = 0; i < length || length < 0 && !readBreak(); ++i) { - let key = decodeItem(); + const key = decodeItem(); retObject[key] = decodeItem(); } return retObject; @@ -374,7 +374,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) { } } - let ret = decodeItem(); + const ret = decodeItem(); if (offset !== data.byteLength) throw "Remaining bytes"; return ret; diff --git a/packages/uhk-agent/src/util/backup-user-configuration.ts b/packages/uhk-agent/src/util/backup-user-configuration.ts index e81b8a1d12d..5fbd56ac7e0 100644 --- a/packages/uhk-agent/src/util/backup-user-configuration.ts +++ b/packages/uhk-agent/src/util/backup-user-configuration.ts @@ -67,7 +67,7 @@ export async function getBackupUserConfigurationContent(logService: LogService, } export async function getCompatibleUserConfigFromHistory(logService: LogService, uniqueId: number): Promise { - let history = await loadUserConfigHistoryAsync(); + const history = await loadUserConfigHistoryAsync(); const deviceHistory = history.devices.find(device => device.uniqueId === uniqueId); diff --git a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts index bdcc7d264c3..1fa812c8d5a 100644 --- a/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts @@ -28,7 +28,7 @@ export enum KeyActionId { MacroArgumentAction = 40, } -export let keyActionType = { +export const keyActionType = { NoneAction : 'none', KeystrokeAction : 'keystroke', SwitchLayerAction : 'switchLayer', diff --git a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts index 47672b6a86d..23d2b817bbd 100644 --- a/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts +++ b/packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts @@ -36,7 +36,7 @@ export enum MacroMouseSubAction { release = 2 } -export let macroActionType = { +export const macroActionType = { KeyMacroAction : 'key', MouseButtonMacroAction : 'mouseButton', MoveMouseMacroAction : 'moveMouse', diff --git a/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts b/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts index 072614e7d36..ea4f3a4f0aa 100644 --- a/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts +++ b/packages/uhk-common/src/config-serializer/config-items/module-configuration.ts @@ -280,7 +280,7 @@ export class ModuleConfiguration { this.navigationModeFn4Layer = buffer.readUInt8(); this.navigationModeFn5Layer = buffer.readUInt8(); - let numberOfProperties = buffer.readUInt8(); + const numberOfProperties = buffer.readUInt8(); for(let index = 0; index < numberOfProperties; index++){ const property = buffer.readUInt8(); diff --git a/packages/uhk-common/src/config-serializer/config-items/module.ts b/packages/uhk-common/src/config-serializer/config-items/module.ts index 6d187b5654b..613a9d37275 100644 --- a/packages/uhk-common/src/config-serializer/config-items/module.ts +++ b/packages/uhk-common/src/config-serializer/config-items/module.ts @@ -230,7 +230,7 @@ export class Module { getKeyActionsCount(): number { let count = 0 - for (let keyAction of this.keyActions) { + for (const keyAction of this.keyActions) { count++; if (keyAction instanceof PlayMacroAction) { diff --git a/packages/uhk-usb/src/uhk-hid-device.ts b/packages/uhk-usb/src/uhk-hid-device.ts index 9d3186b12a3..1ad079fd678 100644 --- a/packages/uhk-usb/src/uhk-hid-device.ts +++ b/packages/uhk-usb/src/uhk-hid-device.ts @@ -483,7 +483,7 @@ export class UhkHidDevice { while (new Date().getTime() - startTime.getTime() < waitTimeout) { iteration++; - let allDevice = []; + const allDevice = []; for (const vidPid of vidPidPairs) { if (enumerationMode === EnumerationModes.Bootloader && device.firmwareUpgradeMethod === FIRMWARE_UPGRADE_METHODS.MCUBOOT) { diff --git a/packages/uhk-usb/src/utils/convert-ms-to-duration.ts b/packages/uhk-usb/src/utils/convert-ms-to-duration.ts index 9da1cba105f..9345c38b6bf 100644 --- a/packages/uhk-usb/src/utils/convert-ms-to-duration.ts +++ b/packages/uhk-usb/src/utils/convert-ms-to-duration.ts @@ -1,13 +1,13 @@ import { Duration } from '../models/duration.js'; export function convertMsToDuration(milliseconds: number): Duration { - let days, hours, minutes, seconds; + let hours, minutes, seconds; seconds = Math.floor(milliseconds / 1000); minutes = Math.floor(seconds / 60); seconds = seconds % 60; hours = Math.floor(minutes / 60); minutes = minutes % 60; - days = Math.floor(hours / 24); + const days = Math.floor(hours / 24); hours = hours % 24; return { days, hours, minutes, seconds }; diff --git a/packages/uhk-usb/src/utils/list-available-devices.ts b/packages/uhk-usb/src/utils/list-available-devices.ts index 93b106b0fc6..52ede0899fa 100644 --- a/packages/uhk-usb/src/utils/list-available-devices.ts +++ b/packages/uhk-usb/src/utils/list-available-devices.ts @@ -35,7 +35,7 @@ export async function listAvailableDevices(options: ListAvailableDevicesOptions) prevDevice.state = UsbDeviceConnectionStates.Unknown; } - let hidDevices = options.hidDevices ?? await getUhkHidDevices(); + const hidDevices = options.hidDevices ?? await getUhkHidDevices(); for (const hidDevice of hidDevices) { const id = `h-${hidDevice.vendorId}-${hidDevice.productId}-${hidDevice.interface}` const existingPrevDevice = prevDevices.get(id); @@ -53,7 +53,7 @@ export async function listAvailableDevices(options: ListAvailableDevicesOptions) } } - let serialDevices = options.serialDevices ?? await SerialPort.list(); + const serialDevices = options.serialDevices ?? await SerialPort.list(); for (const serialDevice of serialDevices) { const id = `s-${serialDevice.vendorId}-${serialDevice.productId}-${serialDevice.path}` const existingPrevDevice = prevDevices.get(id); diff --git a/packages/uhk-web/src/app/components/svg/keys/svg-keystroke-key/svg-keystroke-key.component.ts b/packages/uhk-web/src/app/components/svg/keys/svg-keystroke-key/svg-keystroke-key.component.ts index 63c098dc485..9db4b57ab52 100644 --- a/packages/uhk-web/src/app/components/svg/keys/svg-keystroke-key/svg-keystroke-key.component.ts +++ b/packages/uhk-web/src/app/components/svg/keys/svg-keystroke-key/svg-keystroke-key.component.ts @@ -91,8 +91,7 @@ export class SvgKeystrokeKeyComponent implements OnChanges { if (this.labelSource) { this.labelType = 'icon'; } else { - let newLabelSource: string[]; - newLabelSource = this.mapper.scanCodeToText(scancode, this.keystrokeAction.type); + const newLabelSource = this.mapper.scanCodeToText(scancode, this.keystrokeAction.type); if (newLabelSource) { if (this.secondaryText && newLabelSource.length === 2) { if (isRectangleAsSecondaryRole || bottomSideMode) { diff --git a/packages/uhk-web/src/app/services/monaco-editor-completion-item-provider.ts b/packages/uhk-web/src/app/services/monaco-editor-completion-item-provider.ts index 601cfb7cba3..15d95c96be8 100644 --- a/packages/uhk-web/src/app/services/monaco-editor-completion-item-provider.ts +++ b/packages/uhk-web/src/app/services/monaco-editor-completion-item-provider.ts @@ -75,7 +75,7 @@ export class MonacoEditorCompletionItemProvider implements monaco.languages.Comp } const monacoSuggestions: monaco.languages.CompletionItem[] = nelaSuggestions.map(it => { - let kind = this.guessKind(it.suggestion, it.originRule); + const kind = this.guessKind(it.suggestion, it.originRule); return { insertText: it.text(), diff --git a/packages/uhk-web/src/app/services/uhk80-migrator.service.ts b/packages/uhk-web/src/app/services/uhk80-migrator.service.ts index 93132e5c650..7bcbea99e21 100644 --- a/packages/uhk-web/src/app/services/uhk80-migrator.service.ts +++ b/packages/uhk-web/src/app/services/uhk80-migrator.service.ts @@ -44,7 +44,7 @@ export class Uhk80MigratorService implements OnDestroy { return userConfig; } - let hasConfiguredExcessKey = this.hasUhk80ConfiguredExcessKey(userConfig); + const hasConfiguredExcessKey = this.hasUhk80ConfiguredExcessKey(userConfig); if (hasConfiguredExcessKey) { return userConfig; diff --git a/packages/uhk-web/src/app/store/reducers/user-configuration.ts b/packages/uhk-web/src/app/store/reducers/user-configuration.ts index 03f1c705057..4e4d41f0c38 100644 --- a/packages/uhk-web/src/app/store/reducers/user-configuration.ts +++ b/packages/uhk-web/src/app/store/reducers/user-configuration.ts @@ -1306,7 +1306,7 @@ function generateName(items: { name: string }[], name: string) { function generateMacroId(macros: Macro[]) { let newId = 0; - let usedMacroIds = new Set(); + const usedMacroIds = new Set(); macros.forEach((macro: Macro) => { if (macro.id > newId) {