Skip to content

Commit 071e4f9

Browse files
authored
style: use recommended prefer-const eslint rule (#2790)
1 parent a8a4527 commit 071e4f9

File tree

14 files changed

+43
-45
lines changed

14 files changed

+43
-45
lines changed

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const typescriptRules = {
3535
'no-async-promise-executor': 'off',
3636
'no-case-declarations': 'off',
3737
'no-prototype-builtins': 'off',
38-
'prefer-const': 'off',
3938
}
4039

4140
export default [

packages/mcumgr/src/util/cbor.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ export function encode(value: any) {
2121

2222
function prepareWrite(length: number) {
2323
let newByteLength = data.byteLength;
24-
let requiredLength = offset + length;
24+
const requiredLength = offset + length;
2525
while (newByteLength < requiredLength)
2626
newByteLength <<= 1;
2727
if (newByteLength !== data.byteLength) {
28-
let oldDataView = dataView;
28+
const oldDataView = dataView;
2929
data = new ArrayBuffer(newByteLength);
3030
dataView = new DataView(data);
31-
let uint32count = (offset + 3) >> 2;
31+
const uint32count = (offset + 3) >> 2;
3232
for (let i = 0; i < uint32count; ++i)
3333
dataView.setUint32(i << 2, oldDataView.getUint32(i << 2));
3434
}
@@ -46,7 +46,7 @@ export function encode(value: any) {
4646
commitWrite(prepareWrite(1).setUint8(offset, value));
4747
}
4848
function writeUint8Array(value) {
49-
let dataView = prepareWrite(value.length);
49+
const dataView = prepareWrite(value.length);
5050
for (let i = 0; i < value.length; ++i)
5151
dataView.setUint8(offset + i, value[i]);
5252
commitWrite();
@@ -58,9 +58,9 @@ export function encode(value: any) {
5858
commitWrite(prepareWrite(4).setUint32(offset, value));
5959
}
6060
function writeUint64(value) {
61-
let low = value % POW_2_32;
62-
let high = (value - low) / POW_2_32;
63-
let dataView = prepareWrite(8);
61+
const low = value % POW_2_32;
62+
const high = (value - low) / POW_2_32;
63+
const dataView = prepareWrite(8);
6464
dataView.setUint32(offset, high);
6565
dataView.setUint32(offset + 4, low);
6666
commitWrite();
@@ -107,7 +107,7 @@ export function encode(value: any) {
107107
return writeFloat64(value);
108108

109109
case "string":
110-
let utf8data = [];
110+
const utf8data = [];
111111
for (i = 0; i < value.length; ++i) {
112112
let charCode = value.charCodeAt(i);
113113
if (charCode < 0x80) {
@@ -145,11 +145,11 @@ export function encode(value: any) {
145145
writeTypeAndLength(2, value.length);
146146
writeUint8Array(value);
147147
} else {
148-
let keys = Object.keys(value);
148+
const keys = Object.keys(value);
149149
length = keys.length;
150150
writeTypeAndLength(5, length);
151151
for (i = 0; i < length; ++i) {
152-
let key = keys[i];
152+
const key = keys[i];
153153
encodeItem(key);
154154
encodeItem(value[key]);
155155
}
@@ -162,15 +162,15 @@ export function encode(value: any) {
162162
if ("slice" in data)
163163
return data.slice(0, offset);
164164

165-
let ret = new ArrayBuffer(offset);
166-
let retView = new DataView(ret);
165+
const ret = new ArrayBuffer(offset);
166+
const retView = new DataView(ret);
167167
for (let i = 0; i < offset; ++i)
168168
retView.setUint8(i, dataView.getUint8(i));
169169
return ret;
170170
}
171171

172172
export function decode(data: any, tagger?: Function, simpleValue?: Function) {
173-
let dataView = new DataView(data);
173+
const dataView = new DataView(data);
174174
let offset = 0;
175175

176176
if (typeof tagger !== "function")
@@ -186,13 +186,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
186186
return commitRead(length, new Uint8Array(data, offset, length));
187187
}
188188
function readFloat16() {
189-
let tempArrayBuffer = new ArrayBuffer(4);
190-
let tempDataView = new DataView(tempArrayBuffer);
191-
let value = readUint16();
189+
const tempArrayBuffer = new ArrayBuffer(4);
190+
const tempDataView = new DataView(tempArrayBuffer);
191+
const value = readUint16();
192192

193-
let sign = value & 0x8000;
193+
const sign = value & 0x8000;
194194
let exponent = value & 0x7c00;
195-
let fraction = value & 0x03ff;
195+
const fraction = value & 0x03ff;
196196

197197
if (exponent === 0x7c00)
198198
exponent = 0xff << 10;
@@ -244,10 +244,10 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
244244
throw "Invalid length encoding";
245245
}
246246
function readIndefiniteStringLength(majorType) {
247-
let initialByte = readUint8();
247+
const initialByte = readUint8();
248248
if (initialByte === 0xff)
249249
return -1;
250-
let length = readLength(initialByte & 0x1f);
250+
const length = readLength(initialByte & 0x1f);
251251
if (length < 0 || (initialByte >> 5) !== majorType)
252252
throw "Invalid indefinite length element";
253253
return length;
@@ -286,9 +286,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
286286
}
287287

288288
function decodeItem() {
289-
let initialByte = readUint8();
290-
let majorType = initialByte >> 5;
291-
let additionalInformation = initialByte & 0x1f;
289+
const initialByte = readUint8();
290+
const majorType = initialByte >> 5;
291+
const additionalInformation = initialByte & 0x1f;
292292
let i;
293293
let length;
294294

@@ -314,13 +314,13 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
314314
return -1 - length;
315315
case 2:
316316
if (length < 0) {
317-
let elements = [];
317+
const elements = [];
318318
let fullArrayLength = 0;
319319
while ((length = readIndefiniteStringLength(majorType)) >= 0) {
320320
fullArrayLength += length;
321321
elements.push(readArrayBuffer(length));
322322
}
323-
let fullArray = new Uint8Array(fullArrayLength);
323+
const fullArray = new Uint8Array(fullArrayLength);
324324
let fullArrayOffset = 0;
325325
for (i = 0; i < elements.length; ++i) {
326326
fullArray.set(elements[i], fullArrayOffset);
@@ -330,7 +330,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
330330
}
331331
return readArrayBuffer(length);
332332
case 3:
333-
let utf16data = [];
333+
const utf16data = [];
334334
if (length < 0) {
335335
while ((length = readIndefiniteStringLength(majorType)) >= 0)
336336
appendUtf16Data(utf16data, length);
@@ -350,9 +350,9 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
350350
}
351351
return retArray;
352352
case 5:
353-
let retObject = {};
353+
const retObject = {};
354354
for (i = 0; i < length || length < 0 && !readBreak(); ++i) {
355-
let key = decodeItem();
355+
const key = decodeItem();
356356
retObject[key] = decodeItem();
357357
}
358358
return retObject;
@@ -374,7 +374,7 @@ export function decode(data: any, tagger?: Function, simpleValue?: Function) {
374374
}
375375
}
376376

377-
let ret = decodeItem();
377+
const ret = decodeItem();
378378
if (offset !== data.byteLength)
379379
throw "Remaining bytes";
380380
return ret;

packages/uhk-agent/src/util/backup-user-configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function getBackupUserConfigurationContent(logService: LogService,
6767
}
6868

6969
export async function getCompatibleUserConfigFromHistory(logService: LogService, uniqueId: number): Promise<BackupUserConfiguration> {
70-
let history = await loadUserConfigHistoryAsync();
70+
const history = await loadUserConfigHistoryAsync();
7171

7272
const deviceHistory = history.devices.find(device => device.uniqueId === uniqueId);
7373

packages/uhk-common/src/config-serializer/config-items/key-action/key-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export enum KeyActionId {
2828
MacroArgumentAction = 40,
2929
}
3030

31-
export let keyActionType = {
31+
export const keyActionType = {
3232
NoneAction : 'none',
3333
KeystrokeAction : 'keystroke',
3434
SwitchLayerAction : 'switchLayer',

packages/uhk-common/src/config-serializer/config-items/macro-action/macro-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export enum MacroMouseSubAction {
3636
release = 2
3737
}
3838

39-
export let macroActionType = {
39+
export const macroActionType = {
4040
KeyMacroAction : 'key',
4141
MouseButtonMacroAction : 'mouseButton',
4242
MoveMouseMacroAction : 'moveMouse',

packages/uhk-common/src/config-serializer/config-items/module-configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export class ModuleConfiguration {
280280
this.navigationModeFn4Layer = buffer.readUInt8();
281281
this.navigationModeFn5Layer = buffer.readUInt8();
282282

283-
let numberOfProperties = buffer.readUInt8();
283+
const numberOfProperties = buffer.readUInt8();
284284

285285
for(let index = 0; index < numberOfProperties; index++){
286286
const property = buffer.readUInt8();

packages/uhk-common/src/config-serializer/config-items/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class Module {
230230
getKeyActionsCount(): number {
231231
let count = 0
232232

233-
for (let keyAction of this.keyActions) {
233+
for (const keyAction of this.keyActions) {
234234
count++;
235235

236236
if (keyAction instanceof PlayMacroAction) {

packages/uhk-usb/src/uhk-hid-device.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export class UhkHidDevice {
483483

484484
while (new Date().getTime() - startTime.getTime() < waitTimeout) {
485485
iteration++;
486-
let allDevice = [];
486+
const allDevice = [];
487487
for (const vidPid of vidPidPairs) {
488488

489489
if (enumerationMode === EnumerationModes.Bootloader && device.firmwareUpgradeMethod === FIRMWARE_UPGRADE_METHODS.MCUBOOT) {

packages/uhk-usb/src/utils/convert-ms-to-duration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Duration } from '../models/duration.js';
22

33
export function convertMsToDuration(milliseconds: number): Duration {
4-
let days, hours, minutes, seconds;
4+
let hours, minutes, seconds;
55
seconds = Math.floor(milliseconds / 1000);
66
minutes = Math.floor(seconds / 60);
77
seconds = seconds % 60;
88
hours = Math.floor(minutes / 60);
99
minutes = minutes % 60;
10-
days = Math.floor(hours / 24);
10+
const days = Math.floor(hours / 24);
1111
hours = hours % 24;
1212

1313
return { days, hours, minutes, seconds };

packages/uhk-usb/src/utils/list-available-devices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function listAvailableDevices(options: ListAvailableDevicesOptions)
3535
prevDevice.state = UsbDeviceConnectionStates.Unknown;
3636
}
3737

38-
let hidDevices = options.hidDevices ?? await getUhkHidDevices();
38+
const hidDevices = options.hidDevices ?? await getUhkHidDevices();
3939
for (const hidDevice of hidDevices) {
4040
const id = `h-${hidDevice.vendorId}-${hidDevice.productId}-${hidDevice.interface}`
4141
const existingPrevDevice = prevDevices.get(id);
@@ -53,7 +53,7 @@ export async function listAvailableDevices(options: ListAvailableDevicesOptions)
5353
}
5454
}
5555

56-
let serialDevices = options.serialDevices ?? await SerialPort.list();
56+
const serialDevices = options.serialDevices ?? await SerialPort.list();
5757
for (const serialDevice of serialDevices) {
5858
const id = `s-${serialDevice.vendorId}-${serialDevice.productId}-${serialDevice.path}`
5959
const existingPrevDevice = prevDevices.get(id);

0 commit comments

Comments
 (0)