Skip to content

Commit 3e6bb5f

Browse files
authored
Merge pull request #1080 from minuteos/feat/migrate-to-eslint
ESLint: next batch of rule fixes
2 parents ea3fb4b + d236580 commit 3e6bb5f

Some content is hidden

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

46 files changed

+134
-3276
lines changed

eslint.config.mjs

+20-15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export default tseslint.config(
3939

4040
rules: {
4141
'@typescript-eslint/no-base-to-string': 'off', // 1 instance
42+
'@typescript-eslint/prefer-promise-reject-errors': ['error', {
43+
// for catch (e) { reject(e); } scenarios, until promises are refactored
44+
allowThrowingAny: true,
45+
allowThrowingUnknown: true,
46+
}],
4247

4348
'@stylistic/indent-binary-ops': 'off', // this is a weird rule
4449
'@stylistic/max-len': ['error', {
@@ -64,25 +69,25 @@ export default tseslint.config(
6469
// the following rules are being heavily violated in the current codebase,
6570
// we should work on being able to enable them...
6671
rules: {
67-
'@typescript-eslint/no-unsafe-member-access': 'off', // 742 instances
68-
'@typescript-eslint/no-unsafe-call': 'off', // 432 instances
69-
'@typescript-eslint/no-unsafe-assignment': 'off', // 429 instances
70-
'@typescript-eslint/no-unsafe-argument': 'off', // 401 instances
71-
'@typescript-eslint/no-explicit-any': 'off', // 226 instances
72-
'@typescript-eslint/no-unused-vars': 'off', // 204 instances
73-
'@typescript-eslint/no-unsafe-return': 'off', // 83 instances
74-
'@typescript-eslint/no-misused-promises': 'off', // 57 instances
75-
'@typescript-eslint/no-floating-promises': 'off', // 55 instances
76-
'no-useless-escape': 'off', // 38 instances
77-
'@typescript-eslint/prefer-promise-reject-errors': 'off', // 36 instances
78-
'no-async-promise-executor': 'off', // 29 instances
79-
'@typescript-eslint/no-require-imports': 'off', // 24 instances
80-
'no-cond-assign': 'off', // 21 instances
81-
'@typescript-eslint/require-await': 'off', // 11 instances
72+
'@typescript-eslint/no-unsafe-member-access': 'off', // 655 instances
73+
'@typescript-eslint/no-unsafe-call': 'off', // 381 instances
74+
'@typescript-eslint/no-unsafe-assignment': 'off', // 354 instances
75+
'@typescript-eslint/no-unsafe-argument': 'off', // 309 instances
76+
'@typescript-eslint/no-explicit-any': 'off', // 187 instances
77+
'@typescript-eslint/no-unused-vars': 'off', // 169 instances
78+
'@typescript-eslint/no-misused-promises': 'off', // 53 instances
79+
'@typescript-eslint/no-floating-promises': 'off', // 48 instances
80+
'no-async-promise-executor': 'off', // 25 instances
8281
}
8382
},
8483
{
8584
files: ['**/*.{js,mjs}'],
8685
extends: [tseslint.configs.disableTypeChecked],
8786
},
87+
{
88+
files: ['**/*.js'],
89+
rules: {
90+
'@typescript-eslint/no-require-imports': 'off',
91+
}
92+
}
8893
);

package-lock.json

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,6 @@
30463046
"description": "ARM Cortex-M GDB Debugger support for VSCode",
30473047
"devDependencies": {
30483048
"@stylistic/eslint-plugin": "^2.13.0",
3049-
"@types/binary-parser": "^1.5.5",
30503049
"@types/mocha": "^10.0.10",
30513050
"@types/node": "16.x",
30523051
"@types/vscode": "^1.69.0",

src/backend/backend.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const MIError: MIErrorConstructor = class MIError {
184184
public readonly source: string;
185185
public constructor(message: string, source: string) {
186186
Object.defineProperty(this, 'name', {
187-
get: () => (this.constructor as any).name
187+
get: () => this.constructor.name
188188
});
189189
Object.defineProperty(this, 'message', {
190190
get: () => message

src/backend/disasm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class GdbDisassembler {
298298
const regex = RegExp(/^[0-9]+\s+([^\s])\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+([^\r\n]*)/mgi);
299299
// Num Enb Low Addr High Addr Attrs
300300
// 1 y 0x10000000 0x10100000 flash blocksize 0x200 nocache
301-
while (match = regex.exec(str)) {
301+
while ((match = regex.exec(str))) {
302302
const [flag, lowAddr, highAddr, attrsStr] = match.slice(1, 5);
303303
if (flag === 'y') {
304304
const nHighAddr = parseInt(highAddr);
@@ -499,7 +499,7 @@ export class GdbDisassembler {
499499
const endAddress = range.qEnd;
500500
const validationAddr = range.verify;
501501
// To annotate questionable instructions. Too lazy to do on per instruction basis
502-
return new Promise<DisassemblyReturn | Error>(async (resolve) => {
502+
return new Promise<DisassemblyReturn | Error>((resolve) => {
503503
let iter = 0;
504504
const maxTries = Math.ceil((this.maxInstrSize - this.minInstrSize) / this.instrMultiple);
505505
const doWork = () => {

src/backend/gdb_expansion.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { MINode } from './mi_parse';
22

3-
const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;
4-
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
5-
const errorRegex = /^\<.+?\>/;
3+
const resultRegex = /^([a-zA-Z_-][a-zA-Z0-9_-]*|\[\d+\])\s*=\s*/;
4+
const variableRegex = /^[a-zA-Z_-][a-zA-Z0-9_-]*/;
5+
const errorRegex = /^<.+?>/;
66
const referenceStringRegex = /^(0x[0-9a-fA-F]+\s*)"/;
77
const referenceRegex = /^0x[0-9a-fA-F]+/;
88
const nullpointerRegex = /^0x0+\b/;
@@ -18,13 +18,13 @@ export function isExpandable(value: string): number {
1818
if (value[0] === '{') { return 1; } // object
1919
if (value.startsWith('true')) { return 0; }
2020
if (value.startsWith('false')) { return 0; }
21-
if (match = nullpointerRegex.exec(value)) { return 0; }
22-
if (match = referenceStringRegex.exec(value)) { return 0; }
23-
if (match = referenceRegex.exec(value)) { return 2; } // reference
24-
if (match = charRegex.exec(value)) { return 0; }
25-
if (match = numberRegex.exec(value)) { return 0; }
26-
if (match = variableRegex.exec(value)) { return 0; }
27-
if (match = errorRegex.exec(value)) { return 0; }
21+
if ((match = nullpointerRegex.exec(value))) { return 0; }
22+
if ((match = referenceStringRegex.exec(value))) { return 0; }
23+
if ((match = referenceRegex.exec(value))) { return 2; } // reference
24+
if ((match = charRegex.exec(value))) { return 0; }
25+
if ((match = numberRegex.exec(value))) { return 0; }
26+
if ((match = variableRegex.exec(value))) { return 0; }
27+
if ((match = errorRegex.exec(value))) { return 0; }
2828
return 0;
2929
}
3030

@@ -86,7 +86,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
8686
return prefix + namespace;
8787
};
8888

89-
function parseTupleOrList() {
89+
function parseTupleOrList(): unknown {
9090
value = value.trim();
9191
if (value[0] !== '{') {
9292
return undefined;
@@ -101,7 +101,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
101101
value = value.substr(3).trim();
102102
if (value[0] === '}') {
103103
value = value.substr(1).trim();
104-
return '<...>' as any;
104+
return '<...>';
105105
}
106106
}
107107
const eqPos = value.indexOf('=');
@@ -136,7 +136,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
136136
if (result) {
137137
const results = [];
138138
results.push(result);
139-
while (result = parseCommaResult(true)) {
139+
while ((result = parseCommaResult(true))) {
140140
results.push(result);
141141
}
142142
value = value.substr(1).trim(); // }
@@ -146,7 +146,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
146146
return undefined;
147147
};
148148

149-
function parsePrimitive() {
149+
function parsePrimitive(): unknown {
150150
let primitive: any;
151151
let match;
152152
value = value.trim();
@@ -158,26 +158,26 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
158158
} else if (value.startsWith('false')) {
159159
primitive = 'false';
160160
value = value.substr(5).trim();
161-
} else if (match = nullpointerRegex.exec(value)) {
161+
} else if ((match = nullpointerRegex.exec(value))) {
162162
primitive = '<nullptr>';
163163
value = value.substr(match[0].length).trim();
164-
} else if (match = referenceStringRegex.exec(value)) {
164+
} else if ((match = referenceStringRegex.exec(value))) {
165165
value = value.substr(match[1].length).trim();
166166
primitive = parseCString();
167-
} else if (match = referenceRegex.exec(value)) {
167+
} else if ((match = referenceRegex.exec(value))) {
168168
primitive = '*' + match[0];
169169
value = value.substr(match[0].length).trim();
170-
} else if (match = charRegex.exec(value)) {
170+
} else if ((match = charRegex.exec(value))) {
171171
primitive = match[1];
172172
value = value.substr(match[0].length - 1);
173173
primitive += ' ' + parseCString();
174-
} else if (match = numberRegex.exec(value)) {
174+
} else if ((match = numberRegex.exec(value))) {
175175
primitive = match[0];
176176
value = value.substr(match[0].length).trim();
177-
} else if (match = variableRegex.exec(value)) {
177+
} else if ((match = variableRegex.exec(value))) {
178178
primitive = match[0];
179179
value = value.substr(match[0].length).trim();
180-
} else if (match = errorRegex.exec(value)) {
180+
} else if ((match = errorRegex.exec(value))) {
181181
primitive = match[0];
182182
value = value.substr(match[0].length).trim();
183183
} else {

src/backend/linux/console.ts

-24
This file was deleted.

src/backend/mi2/mi2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function escape(str: string) {
3232
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
3333
}
3434

35-
const nonOutput = /^(?:\d*|undefined)[\*\+\=]|[\~\@\&\^]/;
35+
const nonOutput = /^(?:\d*|undefined)[*+=]|[~@&^]/;
3636
const gdbMatch = /(?:\d*|undefined)\(gdb\)/;
3737
const numRegex = /\d+/;
3838

@@ -908,7 +908,7 @@ export class MI2 extends EventEmitter implements IBackend {
908908

909909
const thFr = ((threadId !== undefined) && (frameId !== undefined)) ? `--thread ${threadId} --frame ${frameId}` : '';
910910
const createResp = await this.sendCommand(`var-create ${thFr} ${name} ${scope} "${expression}"`);
911-
let overrideVal = null;
911+
let overrideVal: string = null;
912912
if (fmt && name !== '-') {
913913
const formatResp = await this.sendCommand(`var-set-format ${name} ${MI2.FORMAT_SPEC_MAP[fmt]}`);
914914
overrideVal = formatResp.result('value');

src/backend/mi_parse.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class MINode implements MIInfo {
6262
if (!start) {
6363
return undefined;
6464
}
65-
const pathRegex = /^\.?([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
65+
const pathRegex = /^\.?([a-zA-Z_-][a-zA-Z0-9_-]*)/;
6666
const indexRegex = /^\[(\d+)\](?:$|\.)/;
6767
path = path.trim();
6868
if (!path) { return start; }
@@ -136,11 +136,11 @@ export class MINode implements MIInfo {
136136
}
137137

138138
const tokenRegex = /^\d+/;
139-
const outOfBandRecordRegex = /^(?:(\d*|undefined)([\*\+\=])|([\~\@\&]))/;
139+
const outOfBandRecordRegex = /^(?:(\d*|undefined)([*+=])|([~@&]))/;
140140
const resultRecordRegex = /^(\d*)\^(done|running|connected|error|exit)/;
141141
const newlineRegex = /^\r\n?/;
142142
const endRegex = /^\(gdb\)\r\n?/;
143-
const variableRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
143+
const variableRegex = /^([a-zA-Z_-][a-zA-Z0-9_-]*)/;
144144
const asyncClassRegex = /^(.*?),/;
145145

146146
export function parseMI(output: string): MINode {
@@ -195,7 +195,7 @@ export function parseMI(output: string): MINode {
195195
remaining = remaining.substr(1);
196196
stringEnd++;
197197
}
198-
let str;
198+
let str: string;
199199
try {
200200
str = parseString(output.substr(0, stringEnd));
201201
} catch (e) {
@@ -205,7 +205,7 @@ export function parseMI(output: string): MINode {
205205
return str;
206206
};
207207

208-
function parseTupleOrList() {
208+
function parseTupleOrList(): unknown[] {
209209
if (output[0] !== '{' && output[0] !== '[') {
210210
return undefined;
211211
}
@@ -233,7 +233,7 @@ export function parseMI(output: string): MINode {
233233
if (result) {
234234
const results = [];
235235
results.push(result);
236-
while (result = parseCommaResult()) {
236+
while ((result = parseCommaResult())) {
237237
results.push(result);
238238
}
239239
output = output.substr(1); // }
@@ -243,7 +243,7 @@ export function parseMI(output: string): MINode {
243243
return undefined;
244244
};
245245

246-
function parseValue() {
246+
function parseValue(): unknown {
247247
if (output[0] === '"') {
248248
return parseCString();
249249
} else if (output[0] === '{' || output[0] === '[') {
@@ -281,7 +281,7 @@ export function parseMI(output: string): MINode {
281281

282282
let match;
283283

284-
while (match = outOfBandRecordRegex.exec(output)) {
284+
while ((match = outOfBandRecordRegex.exec(output))) {
285285
output = output.substr(match[0].length);
286286
if (match[1] && token === undefined && match[1] !== 'undefined') {
287287
token = parseInt(match[1]);
@@ -297,7 +297,7 @@ export function parseMI(output: string): MINode {
297297
output: []
298298
};
299299
let result;
300-
while (result = parseCommaResult()) {
300+
while ((result = parseCommaResult())) {
301301
asyncRecord.output.push(result);
302302
}
303303
outOfBandRecord.push(asyncRecord);
@@ -313,7 +313,7 @@ export function parseMI(output: string): MINode {
313313
output = output.replace(newlineRegex, '');
314314
}
315315

316-
if (match = resultRecordRegex.exec(output)) {
316+
if ((match = resultRecordRegex.exec(output))) {
317317
output = output.substr(match[0].length);
318318
if (match[1] && token === undefined) {
319319
token = parseInt(match[1]);
@@ -323,7 +323,7 @@ export function parseMI(output: string): MINode {
323323
results: []
324324
};
325325
let result;
326-
while (result = parseCommaResult()) {
326+
while ((result = parseCommaResult())) {
327327
resultRecords.results.push(result);
328328
}
329329

src/backend/symbols.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { GDBDebugSession } from '../gdb';
99
import { hexFormat } from '../frontend/utils';
1010
import { MINode } from './mi_parse';
1111

12-
const OBJDUMP_SYMBOL_RE = RegExp(/^([0-9a-f]{8})\s([lg\ !])([w\ ])([C\ ])([W\ ])([I\ ])([dD\ ])([FfO\ ])\s(.*?)\t([0-9a-f]+)\s(.*)$/);
12+
const OBJDUMP_SYMBOL_RE = RegExp(/^([0-9a-f]{8})\s([lg !])([w ])([C ])([W ])([I ])([dD ])([FfO ])\s(.*?)\t([0-9a-f]+)\s(.*)$/);
1313
const NM_SYMBOL_RE = RegExp(/^([0-9a-f]+).*\t(.+):[0-9]+/); // For now, we only need two things
1414
const debugConsoleLogging = false;
1515
const TYPE_MAP: { [id: string]: SymbolType } = {
@@ -305,7 +305,7 @@ export class SymbolTable {
305305
});
306306
}
307307

308-
private rttSymbol;
308+
private rttSymbol: SymbolInformation;
309309
public readonly rttSymbolName = '_SEGGER_RTT';
310310
private addSymbol(sym: SymbolInformation) {
311311
if ((sym.length === 0) && /^\$[atdbfpm]$/.test(sym.name)) {

src/bmp.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class BMPServerController extends EventEmitter implements GDBServerContro
6464
}
6565

6666
public attachCommands(): string[] {
67-
const commands = [];
67+
const commands: string[] = [];
6868
return commands;
6969
}
7070

@@ -76,7 +76,7 @@ export class BMPServerController extends EventEmitter implements GDBServerContro
7676
}
7777

7878
public swoAndRTTCommands(): string[] {
79-
const commands = [];
79+
const commands: string[] = [];
8080
if (this.args.swoConfig.enabled) {
8181
const swocommands = this.SWOConfigurationCommands();
8282
commands.push(...swocommands);

0 commit comments

Comments
 (0)