Skip to content

Commit a6c7ccd

Browse files
committed
style: allow @typescript-eslint/no-unsafe-argument eslint rule
1 parent e0ba58e commit a6c7ccd

57 files changed

Lines changed: 167 additions & 110 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ jobs:
3535
- name: Install dependencies
3636
run: npm install
3737

38-
- name: Run linters
39-
run: npm run lint
40-
4138
- name: Run Build
4239
run: npm run build
4340

41+
# For linting need some build time generated file
42+
- name: Run linters
43+
run: npm run lint
44+
4445
- name: Run Build Web
4546
run: npm run build:web
4647

eslint.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const globalIgnores = [
1212

1313
export const typescriptRules = {
1414
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
15-
'@typescript-eslint/no-unsafe-argument': 'off',
1615
'@typescript-eslint/no-unsafe-assignment': 'off',
1716
'@typescript-eslint/no-unsafe-call': 'off',
1817
'@typescript-eslint/no-unsafe-enum-comparison': 'off',

packages/kboot/src/kboot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class KBoot {
172172
} catch (error) {
173173
logger(`Reset command error message: "${error.message}"`);
174174

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

178178
await this.close()

packages/mcumgr/src/mcumgr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class McuManager {
126126
async sendCommand<T>(op: MGMT_OP_TYPE, group: MGMT_GROUP_TYPE, id: MGMT_OPERATION_TYPE, data?: unknown): Promise<NmpResponse<T>> {
127127
logger('Start send command: %o', {op, group, id, data});
128128

129-
let encodedData = [];
129+
let encodedData: number[] = [];
130130
if (typeof data !== 'undefined') {
131131
// the command data is cbor encoded
132132
const buffer = cbor.encode(data);

packages/mcumgr/src/util/cbor.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function encode(value: unknown) {
1919
let lastLength: number;
2020
let offset = 0;
2121

22-
function prepareWrite(length: number) {
22+
function prepareWrite(length: number): DataView {
2323
let newByteLength = data.byteLength;
2424
const requiredLength = offset + length;
2525
while (newByteLength < requiredLength)
@@ -39,33 +39,33 @@ export function encode(value: unknown) {
3939
function commitWrite(_?: unknown) {
4040
offset += lastLength;
4141
}
42-
function writeFloat64(value) {
42+
function writeFloat64(value: number): void {
4343
commitWrite(prepareWrite(8).setFloat64(offset, value));
4444
}
45-
function writeUint8(value) {
45+
function writeUint8(value: number): void {
4646
commitWrite(prepareWrite(1).setUint8(offset, value));
4747
}
48-
function writeUint8Array(value) {
48+
function writeUint8Array(value: number[] | Uint8Array): void {
4949
const dataView = prepareWrite(value.length);
5050
for (let i = 0; i < value.length; ++i)
5151
dataView.setUint8(offset + i, value[i]);
5252
commitWrite();
5353
}
54-
function writeUint16(value) {
54+
function writeUint16(value: number): void {
5555
commitWrite(prepareWrite(2).setUint16(offset, value));
5656
}
57-
function writeUint32(value) {
57+
function writeUint32(value: number): void {
5858
commitWrite(prepareWrite(4).setUint32(offset, value));
5959
}
60-
function writeUint64(value) {
60+
function writeUint64(value: number): void {
6161
const low = value % POW_2_32;
6262
const high = (value - low) / POW_2_32;
6363
const dataView = prepareWrite(8);
6464
dataView.setUint32(offset, high);
6565
dataView.setUint32(offset + 4, low);
6666
commitWrite();
6767
}
68-
function writeTypeAndLength(type, length) {
68+
function writeTypeAndLength(type: number, length: number): void {
6969
if (length < 24) {
7070
writeUint8(type << 5 | length);
7171
} else if (length < 0x100) {
@@ -83,8 +83,9 @@ export function encode(value: unknown) {
8383
}
8484
}
8585

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

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

110111
case "string": {
111-
const utf8data = [];
112+
const utf8data: number[] = [];
112113
for (i = 0; i < value.length; ++i) {
113114
let charCode = value.charCodeAt(i);
114115
if (charCode < 0x80) {
@@ -137,7 +138,7 @@ export function encode(value: unknown) {
137138
}
138139

139140
default: {
140-
let length;
141+
let length: number;
141142
if (Array.isArray(value)) {
142143
length = value.length;
143144
writeTypeAndLength(4, length);
@@ -147,7 +148,7 @@ export function encode(value: unknown) {
147148
writeTypeAndLength(2, value.length);
148149
writeUint8Array(value);
149150
} else {
150-
const keys = Object.keys(value);
151+
const keys = Object.keys(value as Record<string, unknown>);
151152
length = keys.length;
152153
writeTypeAndLength(5, length);
153154
for (i = 0; i < length; ++i) {
@@ -181,11 +182,11 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
181182
if (typeof simpleValue !== "function")
182183
simpleValue = function() { return undefined; };
183184

184-
function commitRead(length, value) {
185+
function commitRead<T extends number | Uint8Array>(length: number, value: T): T {
185186
offset += length;
186187
return value;
187188
}
188-
function readArrayBuffer(length) {
189+
function readArrayBuffer(length: number): Uint8Array {
189190
return commitRead(length, new Uint8Array(data, offset, length));
190191
}
191192
function readFloat16() {
@@ -207,22 +208,22 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
207208
tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13);
208209
return tempDataView.getFloat32(0);
209210
}
210-
function readFloat32() {
211+
function readFloat32(): number {
211212
return commitRead(4, dataView.getFloat32(offset));
212213
}
213-
function readFloat64() {
214+
function readFloat64(): number {
214215
return commitRead(8, dataView.getFloat64(offset));
215216
}
216-
function readUint8() {
217+
function readUint8(): number {
217218
return commitRead(1, dataView.getUint8(offset));
218219
}
219-
function readUint16() {
220+
function readUint16(): number {
220221
return commitRead(2, dataView.getUint16(offset));
221222
}
222-
function readUint32() {
223+
function readUint32(): number {
223224
return commitRead(4, dataView.getUint32(offset));
224225
}
225-
function readUint64() {
226+
function readUint64(): number {
226227
return readUint32() * POW_2_32 + readUint32();
227228
}
228229
function readBreak() {
@@ -231,7 +232,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
231232
offset += 1;
232233
return true;
233234
}
234-
function readLength(additionalInformation) {
235+
function readLength(additionalInformation: number): number {
235236
if (additionalInformation < 24)
236237
return additionalInformation;
237238
if (additionalInformation === 24)
@@ -246,7 +247,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
246247
return -1;
247248
throw "Invalid length encoding";
248249
}
249-
function readIndefiniteStringLength(majorType) {
250+
function readIndefiniteStringLength(majorType: number): number {
250251
const initialByte = readUint8();
251252
if (initialByte === 0xff)
252253
return -1;
@@ -256,7 +257,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
256257
return length;
257258
}
258259

259-
function appendUtf16Data(utf16data, length) {
260+
function appendUtf16Data(utf16data: Array<number>, length: number): void {
260261
for (let i = 0; i < length; ++i) {
261262
let value = readUint8();
262263
if (value & 0x80) {
@@ -292,8 +293,8 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
292293
const initialByte = readUint8();
293294
const majorType = initialByte >> 5;
294295
const additionalInformation = initialByte & 0x1f;
295-
let i;
296-
let length;
296+
let i: number;
297+
let length: number;
297298

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

322323
case 2: {
323324
if (length < 0) {
324-
const elements = [];
325+
const elements: Uint8Array[] = [];
325326
let fullArrayLength = 0;
326327
while ((length = readIndefiniteStringLength(majorType)) >= 0) {
327328
fullArrayLength += length;
@@ -339,7 +340,7 @@ export function decode(data: ArrayBuffer | SharedArrayBuffer, tagger?: Function,
339340
}
340341

341342
case 3: {
342-
const utf16data = [];
343+
const utf16data: number[] = [];
343344
if (length < 0) {
344345
while ((length = readIndefiniteStringLength(majorType)) >= 0)
345346
appendUtf16Data(utf16data, length);

packages/test-serializer/test/test-convert-user-config-npm-script.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import path from 'node:path';
44
import { after, before, describe, it } from 'node:test';
55

66
describe('convert-user-config-to-bin npm script', () => {
7-
let rootDirPath;
8-
let tmpDirPath;
9-
let tmpConfigPath;
7+
let rootDirPath: string;
8+
let tmpDirPath: string;
9+
let tmpConfigPath: string;
1010

1111
before(() => {
1212
rootDirPath = path.join(import.meta.dirname, '..', '..', '..');

packages/uhk-agent/src/services/app.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ export class AppService extends MainServiceBase {
1515
private rootDir: string) {
1616
super(logService, win);
1717

18+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1819
ipcMain.on(IpcEvents.app.getAppStartInfo, this.handleAppStartInfo.bind(this));
20+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1921
ipcMain.on(IpcEvents.app.exit, this.exit.bind(this));
22+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2023
ipcMain.on(IpcEvents.app.openConfigFolder, this.openConfigFolder.bind(this));
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
2125
ipcMain.on(IpcEvents.app.openUrl, this.openUrl.bind(this));
22-
ipcMain.handle(IpcEvents.app.getConfig, async (event, key) => {
26+
ipcMain.handle(IpcEvents.app.getConfig, async (event, key: string) => {
2327
logService.misc(`[AppService] get-config: ${key}`);
2428

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

2933
return config;
3034
});
31-
ipcMain.handle(IpcEvents.app.setConfig, async (event, key, value) => {
35+
ipcMain.handle(IpcEvents.app.setConfig, async (event, key: string, value: never) => {
3236
logService.misc(`[AppService] set-config of "${key}": ${value}`);
3337
await settings.set(key, value);
3438
});

packages/uhk-agent/src/services/device.service.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
UHK_80_DEVICE,
4848
UHK_80_DEVICE_LEFT,
4949
UHK_DEVICE_IDS,
50+
UHK_DEVICE_IDS_TYPE,
5051
UHK_DONGLE,
5152
UHK_MODULE_IDS,
5253
UHK_MODULES,
@@ -210,6 +211,7 @@ export class DeviceService {
210211
});
211212
});
212213

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

215217
ipcMain.on(IpcEvents.device.isRightHalfZephyrLoggingEnabled, (...args) => {
@@ -257,6 +259,7 @@ export class DeviceService {
257259
});
258260
});
259261

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

262265
ipcMain.on(IpcEvents.device.startDonglePairing, (...args) => {
@@ -314,8 +317,11 @@ export class DeviceService {
314317
});
315318
});
316319

320+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
317321
ipcMain.on(IpcEvents.device.getUserConfigFromHistory, this.getUserConfigFromHistory.bind(this));
322+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
318323
ipcMain.on(IpcEvents.device.deleteUserConfigHistory, this.deleteUserConfigHistory.bind(this));
324+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
319325
ipcMain.on(IpcEvents.device.loadUserConfigHistory, this.loadUserConfigFromHistory.bind(this));
320326

321327
logService.misc('[DeviceService] init success');
@@ -834,8 +840,8 @@ export class DeviceService {
834840
try {
835841
await this.stopPollUhkDevice();
836842
const arg = args[0];
837-
const userConfig = arg.userConfig;
838-
const deviceId = arg.deviceId;
843+
const userConfig: Object = arg.userConfig;
844+
const deviceId: UHK_DEVICE_IDS_TYPE = arg.deviceId;
839845
const firmwarePathData: TmpFirmware = getDefaultFirmwarePath(this.rootDir);
840846
const packageJson = await getFirmwarePackageJson(firmwarePathData);
841847

@@ -944,7 +950,10 @@ export class DeviceService {
944950
}
945951
}
946952

947-
public async deleteHostConnection(event: Electron.IpcMainEvent, args): Promise<void> {
953+
public async deleteHostConnection(
954+
event: Electron.IpcMainEvent,
955+
args: [{ isConnectedDongleAddress: boolean, index: number, address: string }]
956+
): Promise<void> {
948957
const {isConnectedDongleAddress, index, address} = args[0];
949958
this.logService.misc('[DeviceService] delete host connection', { isConnectedDongleAddress, index, address });
950959

@@ -1010,7 +1019,7 @@ export class DeviceService {
10101019
event.sender.send(IpcEvents.device.eraseBleSettingsReply, response);
10111020
}
10121021

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

10161025
try {
@@ -1381,7 +1390,7 @@ export class DeviceService {
13811390
return Promise.resolve();
13821391
}
13831392

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

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

13971406
event.sender.send(IpcEvents.device.deleteUserConfigHistoryReply, response);

packages/uhk-agent/src/services/logger.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class ElectronLogService extends LogService {
3131

3232
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3333
error(...args: any[]): void {
34+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
3435
log.error(...args);
3536
}
3637

@@ -40,6 +41,7 @@ export class ElectronLogService extends LogService {
4041
return;
4142
}
4243

44+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
4345
this.log(...args);
4446
}
4547

@@ -49,9 +51,9 @@ export class ElectronLogService extends LogService {
4951
return;
5052
}
5153

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

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

8184
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8285
protected log(...args: any[]): void {
86+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8387
log.log(...args);
8488
}
8589
}

0 commit comments

Comments
 (0)