Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ jobs:
- name: Install dependencies
run: npm install

- name: Run linters
run: npm run lint

- name: Run Build
run: npm run build

# For linting need some build time generated file
- name: Run linters
run: npm run lint

- name: Run Build Web
run: npm run build:web

Expand Down
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const globalIgnores = [

export const typescriptRules = {
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/kboot/src/kboot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class KBoot {
} catch (error) {
logger(`Reset command error message: "${error.message}"`);

if (RESET_IGNORED_ERRORS.includes(error.message)) {
if (RESET_IGNORED_ERRORS.includes(error.message as string)) {
logger('Ignoring missing response from reset command.');

await this.close()
Expand Down
2 changes: 1 addition & 1 deletion packages/mcumgr/src/mcumgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class McuManager {
async sendCommand<T>(op: MGMT_OP_TYPE, group: MGMT_GROUP_TYPE, id: MGMT_OPERATION_TYPE, data?: unknown): Promise<NmpResponse<T>> {
logger('Start send command: %o', {op, group, id, data});

let encodedData = [];
let encodedData: number[] = [];
if (typeof data !== 'undefined') {
// the command data is cbor encoded
const buffer = cbor.encode(data);
Expand Down
57 changes: 29 additions & 28 deletions packages/mcumgr/src/util/cbor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function encode(value: unknown) {
let lastLength: number;
let offset = 0;

function prepareWrite(length: number) {
function prepareWrite(length: number): DataView {
let newByteLength = data.byteLength;
const requiredLength = offset + length;
while (newByteLength < requiredLength)
Expand All @@ -39,33 +39,33 @@ export function encode(value: unknown) {
function commitWrite(_?: unknown) {
offset += lastLength;
}
function writeFloat64(value) {
function writeFloat64(value: number): void {
commitWrite(prepareWrite(8).setFloat64(offset, value));
}
function writeUint8(value) {
function writeUint8(value: number): void {
commitWrite(prepareWrite(1).setUint8(offset, value));
}
function writeUint8Array(value) {
function writeUint8Array(value: number[] | Uint8Array): void {
const dataView = prepareWrite(value.length);
for (let i = 0; i < value.length; ++i)
dataView.setUint8(offset + i, value[i]);
commitWrite();
}
function writeUint16(value) {
function writeUint16(value: number): void {
commitWrite(prepareWrite(2).setUint16(offset, value));
}
function writeUint32(value) {
function writeUint32(value: number): void {
commitWrite(prepareWrite(4).setUint32(offset, value));
}
function writeUint64(value) {
function writeUint64(value: number): void {
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();
}
function writeTypeAndLength(type, length) {
function writeTypeAndLength(type: number, length: number): void {
if (length < 24) {
writeUint8(type << 5 | length);
} else if (length < 0x100) {
Expand All @@ -83,8 +83,9 @@ export function encode(value: unknown) {
}
}

function encodeItem(value) {
let i;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function encodeItem(value: any): void {
let i: number;

if (value === false)
return writeUint8(0xf4);
Expand All @@ -108,7 +109,7 @@ export function encode(value: unknown) {
}

case "string": {
const utf8data = [];
const utf8data: number[] = [];
for (i = 0; i < value.length; ++i) {
let charCode = value.charCodeAt(i);
if (charCode < 0x80) {
Expand Down Expand Up @@ -137,7 +138,7 @@ export function encode(value: unknown) {
}

default: {
let length;
let length: number;
if (Array.isArray(value)) {
length = value.length;
writeTypeAndLength(4, length);
Expand All @@ -147,7 +148,7 @@ export function encode(value: unknown) {
writeTypeAndLength(2, value.length);
writeUint8Array(value);
} else {
const keys = Object.keys(value);
const keys = Object.keys(value as Record<string, unknown>);
length = keys.length;
writeTypeAndLength(5, length);
for (i = 0; i < length; ++i) {
Expand Down Expand Up @@ -181,11 +182,11 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
if (typeof simpleValue !== "function")
simpleValue = function() { return undefined; };

function commitRead(length, value) {
function commitRead<T extends number | Uint8Array>(length: number, value: T): T {
offset += length;
return value;
}
function readArrayBuffer(length) {
function readArrayBuffer(length: number): Uint8Array {
return commitRead(length, new Uint8Array(data, offset, length));
}
function readFloat16() {
Expand All @@ -207,22 +208,22 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13);
return tempDataView.getFloat32(0);
}
function readFloat32() {
function readFloat32(): number {
return commitRead(4, dataView.getFloat32(offset));
}
function readFloat64() {
function readFloat64(): number {
return commitRead(8, dataView.getFloat64(offset));
}
function readUint8() {
function readUint8(): number {
return commitRead(1, dataView.getUint8(offset));
}
function readUint16() {
function readUint16(): number {
return commitRead(2, dataView.getUint16(offset));
}
function readUint32() {
function readUint32(): number {
return commitRead(4, dataView.getUint32(offset));
}
function readUint64() {
function readUint64(): number {
return readUint32() * POW_2_32 + readUint32();
}
function readBreak() {
Expand All @@ -231,7 +232,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
offset += 1;
return true;
}
function readLength(additionalInformation) {
function readLength(additionalInformation: number): number {
if (additionalInformation < 24)
return additionalInformation;
if (additionalInformation === 24)
Expand All @@ -246,7 +247,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
return -1;
throw "Invalid length encoding";
}
function readIndefiniteStringLength(majorType) {
function readIndefiniteStringLength(majorType: number): number {
const initialByte = readUint8();
if (initialByte === 0xff)
return -1;
Expand All @@ -256,7 +257,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
return length;
}

function appendUtf16Data(utf16data, length) {
function appendUtf16Data(utf16data: Array<number>, length: number): void {
for (let i = 0; i < length; ++i) {
let value = readUint8();
if (value & 0x80) {
Expand Down Expand Up @@ -292,8 +293,8 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
const initialByte = readUint8();
const majorType = initialByte >> 5;
const additionalInformation = initialByte & 0x1f;
let i;
let length;
let i: number;
let length: number;

if (majorType === 7) {
switch (additionalInformation) {
Expand Down Expand Up @@ -321,7 +322,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,

case 2: {
if (length < 0) {
const elements = [];
const elements: Uint8Array[] = [];
let fullArrayLength = 0;
while ((length = readIndefiniteStringLength(majorType)) >= 0) {
fullArrayLength += length;
Expand All @@ -339,7 +340,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
}

case 3: {
const utf16data = [];
const utf16data: number[] = [];
if (length < 0) {
while ((length = readIndefiniteStringLength(majorType)) >= 0)
appendUtf16Data(utf16data, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import path from 'node:path';
import { after, before, describe, it } from 'node:test';

describe('convert-user-config-to-bin npm script', () => {
let rootDirPath;
let tmpDirPath;
let tmpConfigPath;
let rootDirPath: string;
let tmpDirPath: string;
let tmpConfigPath: string;

before(() => {
rootDirPath = path.join(import.meta.dirname, '..', '..', '..');
Expand Down
8 changes: 6 additions & 2 deletions packages/uhk-agent/src/services/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ export class AppService extends MainServiceBase {
private rootDir: string) {
super(logService, win);

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.app.getAppStartInfo, this.handleAppStartInfo.bind(this));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.app.exit, this.exit.bind(this));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.app.openConfigFolder, this.openConfigFolder.bind(this));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.app.openUrl, this.openUrl.bind(this));
ipcMain.handle(IpcEvents.app.getConfig, async (event, key) => {
ipcMain.handle(IpcEvents.app.getConfig, async (event, key: string) => {
logService.misc(`[AppService] get-config: ${key}`);

const config = await settings.get(key);
Expand All @@ -28,7 +32,7 @@ export class AppService extends MainServiceBase {

return config;
});
ipcMain.handle(IpcEvents.app.setConfig, async (event, key, value) => {
ipcMain.handle(IpcEvents.app.setConfig, async (event, key: string, value: never) => {
logService.misc(`[AppService] set-config of "${key}": ${value}`);
await settings.set(key, value);
});
Expand Down
21 changes: 15 additions & 6 deletions packages/uhk-agent/src/services/device.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
UHK_80_DEVICE,
UHK_80_DEVICE_LEFT,
UHK_DEVICE_IDS,
UHK_DEVICE_IDS_TYPE,
UHK_DONGLE,
UHK_MODULE_IDS,
UHK_MODULES,
Expand Down Expand Up @@ -210,6 +211,7 @@ export class DeviceService {
});
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.device.toggleI2cDebugging, this.toggleI2cDebugging.bind(this));

ipcMain.on(IpcEvents.device.isRightHalfZephyrLoggingEnabled, (...args) => {
Expand Down Expand Up @@ -257,6 +259,7 @@ export class DeviceService {
});
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.device.startConnectionPoller, this.startPollUhkDevice.bind(this));

ipcMain.on(IpcEvents.device.startDonglePairing, (...args) => {
Expand Down Expand Up @@ -314,8 +317,11 @@ export class DeviceService {
});
});

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.device.getUserConfigFromHistory, this.getUserConfigFromHistory.bind(this));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.device.deleteUserConfigHistory, this.deleteUserConfigHistory.bind(this));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ipcMain.on(IpcEvents.device.loadUserConfigHistory, this.loadUserConfigFromHistory.bind(this));

logService.misc('[DeviceService] init success');
Expand Down Expand Up @@ -834,8 +840,8 @@ export class DeviceService {
try {
await this.stopPollUhkDevice();
const arg = args[0];
const userConfig = arg.userConfig;
const deviceId = arg.deviceId;
const userConfig: Object = arg.userConfig;
const deviceId: UHK_DEVICE_IDS_TYPE = arg.deviceId;
const firmwarePathData: TmpFirmware = getDefaultFirmwarePath(this.rootDir);
const packageJson = await getFirmwarePackageJson(firmwarePathData);

Expand Down Expand Up @@ -944,7 +950,10 @@ export class DeviceService {
}
}

public async deleteHostConnection(event: Electron.IpcMainEvent, args): Promise<void> {
public async deleteHostConnection(
event: Electron.IpcMainEvent,
args: [{ isConnectedDongleAddress: boolean, index: number, address: string }]
): Promise<void> {
const {isConnectedDongleAddress, index, address} = args[0];
this.logService.misc('[DeviceService] delete host connection', { isConnectedDongleAddress, index, address });

Expand Down Expand Up @@ -1010,7 +1019,7 @@ export class DeviceService {
event.sender.send(IpcEvents.device.eraseBleSettingsReply, response);
}

public async execShellCommand(_: Electron.IpcMainEvent, [command]): Promise<void> {
public async execShellCommand(_: Electron.IpcMainEvent, [command]: [string]): Promise<void> {
this.logService.misc(`[DeviceService] execute shell command (escaped): ${escapeZephyrControlChars(command)}`);

try {
Expand Down Expand Up @@ -1381,7 +1390,7 @@ export class DeviceService {
return Promise.resolve();
}

private async getUserConfigFromHistory(event: Electron.IpcMainEvent, [filename]): Promise<void> {
private async getUserConfigFromHistory(event: Electron.IpcMainEvent, [filename]: [string]): Promise<void> {
const response: UploadFileData = {
filename,
data: await getUserConfigFromHistoryAsync(filename),
Expand All @@ -1391,7 +1400,7 @@ export class DeviceService {
event.sender.send(IpcEvents.device.getUserConfigFromHistoryReply, response);
}

private async deleteUserConfigHistory(event: Electron.IpcMainEvent, [deviceUniqueId]): Promise<void> {
private async deleteUserConfigHistory(event: Electron.IpcMainEvent, [deviceUniqueId]: [number]): Promise<void> {
const response = await deleteUserConfigHistory(deviceUniqueId);

event.sender.send(IpcEvents.device.deleteUserConfigHistoryReply, response);
Expand Down
8 changes: 6 additions & 2 deletions packages/uhk-agent/src/services/logger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ElectronLogService extends LogService {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
error(...args: any[]): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
log.error(...args);
}

Expand All @@ -40,6 +41,7 @@ export class ElectronLogService extends LogService {
return;
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.log(...args);
}

Expand All @@ -49,9 +51,9 @@ export class ElectronLogService extends LogService {
return;
}

if (LOG_WRITE_REG_EXP.test(args[0])) {
if (LOG_WRITE_REG_EXP.test(args[0] as string)) {
this.log('%c' + args.join(' '), 'color:blue');
} else if (LOG_READ_REG_EXP.test(args[0])) {
} else if (LOG_READ_REG_EXP.test(args[0] as string)) {
let errorCodeStartIndex = 0;
let errorCodeEndIndex = 2;

Expand All @@ -66,6 +68,7 @@ export class ElectronLogService extends LogService {
this.log('%c' + args.join(' '), 'color:red');
}
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.log(...args);
}
}
Expand All @@ -80,6 +83,7 @@ export class ElectronLogService extends LogService {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
protected log(...args: any[]): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
log.log(...args);
}
}
Loading
Loading