Skip to content

Commit

Permalink
Merge pull request #1080 from minuteos/feat/migrate-to-eslint
Browse files Browse the repository at this point in the history
ESLint: next batch of rule fixes
  • Loading branch information
haneefdm authored Jan 18, 2025
2 parents ea3fb4b + d236580 commit 3e6bb5f
Show file tree
Hide file tree
Showing 46 changed files with 134 additions and 3,276 deletions.
35 changes: 20 additions & 15 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export default tseslint.config(

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

'@stylistic/indent-binary-ops': 'off', // this is a weird rule
'@stylistic/max-len': ['error', {
Expand All @@ -64,25 +69,25 @@ export default tseslint.config(
// the following rules are being heavily violated in the current codebase,
// we should work on being able to enable them...
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off', // 742 instances
'@typescript-eslint/no-unsafe-call': 'off', // 432 instances
'@typescript-eslint/no-unsafe-assignment': 'off', // 429 instances
'@typescript-eslint/no-unsafe-argument': 'off', // 401 instances
'@typescript-eslint/no-explicit-any': 'off', // 226 instances
'@typescript-eslint/no-unused-vars': 'off', // 204 instances
'@typescript-eslint/no-unsafe-return': 'off', // 83 instances
'@typescript-eslint/no-misused-promises': 'off', // 57 instances
'@typescript-eslint/no-floating-promises': 'off', // 55 instances
'no-useless-escape': 'off', // 38 instances
'@typescript-eslint/prefer-promise-reject-errors': 'off', // 36 instances
'no-async-promise-executor': 'off', // 29 instances
'@typescript-eslint/no-require-imports': 'off', // 24 instances
'no-cond-assign': 'off', // 21 instances
'@typescript-eslint/require-await': 'off', // 11 instances
'@typescript-eslint/no-unsafe-member-access': 'off', // 655 instances
'@typescript-eslint/no-unsafe-call': 'off', // 381 instances
'@typescript-eslint/no-unsafe-assignment': 'off', // 354 instances
'@typescript-eslint/no-unsafe-argument': 'off', // 309 instances
'@typescript-eslint/no-explicit-any': 'off', // 187 instances
'@typescript-eslint/no-unused-vars': 'off', // 169 instances
'@typescript-eslint/no-misused-promises': 'off', // 53 instances
'@typescript-eslint/no-floating-promises': 'off', // 48 instances
'no-async-promise-executor': 'off', // 25 instances
}
},
{
files: ['**/*.{js,mjs}'],
extends: [tseslint.configs.disableTypeChecked],
},
{
files: ['**/*.js'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
}
}
);
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3046,7 +3046,6 @@
"description": "ARM Cortex-M GDB Debugger support for VSCode",
"devDependencies": {
"@stylistic/eslint-plugin": "^2.13.0",
"@types/binary-parser": "^1.5.5",
"@types/mocha": "^10.0.10",
"@types/node": "16.x",
"@types/vscode": "^1.69.0",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const MIError: MIErrorConstructor = class MIError {
public readonly source: string;
public constructor(message: string, source: string) {
Object.defineProperty(this, 'name', {
get: () => (this.constructor as any).name
get: () => this.constructor.name
});
Object.defineProperty(this, 'message', {
get: () => message
Expand Down
4 changes: 2 additions & 2 deletions src/backend/disasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class GdbDisassembler {
const regex = RegExp(/^[0-9]+\s+([^\s])\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+([^\r\n]*)/mgi);
// Num Enb Low Addr High Addr Attrs
// 1 y 0x10000000 0x10100000 flash blocksize 0x200 nocache
while (match = regex.exec(str)) {
while ((match = regex.exec(str))) {
const [flag, lowAddr, highAddr, attrsStr] = match.slice(1, 5);
if (flag === 'y') {
const nHighAddr = parseInt(highAddr);
Expand Down Expand Up @@ -499,7 +499,7 @@ export class GdbDisassembler {
const endAddress = range.qEnd;
const validationAddr = range.verify;
// To annotate questionable instructions. Too lazy to do on per instruction basis
return new Promise<DisassemblyReturn | Error>(async (resolve) => {
return new Promise<DisassemblyReturn | Error>((resolve) => {
let iter = 0;
const maxTries = Math.ceil((this.maxInstrSize - this.minInstrSize) / this.instrMultiple);
const doWork = () => {
Expand Down
42 changes: 21 additions & 21 deletions src/backend/gdb_expansion.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MINode } from './mi_parse';

const resultRegex = /^([a-zA-Z_\-][a-zA-Z0-9_\-]*|\[\d+\])\s*=\s*/;
const variableRegex = /^[a-zA-Z_\-][a-zA-Z0-9_\-]*/;
const errorRegex = /^\<.+?\>/;
const resultRegex = /^([a-zA-Z_-][a-zA-Z0-9_-]*|\[\d+\])\s*=\s*/;
const variableRegex = /^[a-zA-Z_-][a-zA-Z0-9_-]*/;
const errorRegex = /^<.+?>/;
const referenceStringRegex = /^(0x[0-9a-fA-F]+\s*)"/;
const referenceRegex = /^0x[0-9a-fA-F]+/;
const nullpointerRegex = /^0x0+\b/;
Expand All @@ -18,13 +18,13 @@ export function isExpandable(value: string): number {
if (value[0] === '{') { return 1; } // object
if (value.startsWith('true')) { return 0; }
if (value.startsWith('false')) { return 0; }
if (match = nullpointerRegex.exec(value)) { return 0; }
if (match = referenceStringRegex.exec(value)) { return 0; }
if (match = referenceRegex.exec(value)) { return 2; } // reference
if (match = charRegex.exec(value)) { return 0; }
if (match = numberRegex.exec(value)) { return 0; }
if (match = variableRegex.exec(value)) { return 0; }
if (match = errorRegex.exec(value)) { return 0; }
if ((match = nullpointerRegex.exec(value))) { return 0; }
if ((match = referenceStringRegex.exec(value))) { return 0; }
if ((match = referenceRegex.exec(value))) { return 2; } // reference
if ((match = charRegex.exec(value))) { return 0; }
if ((match = numberRegex.exec(value))) { return 0; }
if ((match = variableRegex.exec(value))) { return 0; }
if ((match = errorRegex.exec(value))) { return 0; }
return 0;
}

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

function parseTupleOrList() {
function parseTupleOrList(): unknown {
value = value.trim();
if (value[0] !== '{') {
return undefined;
Expand All @@ -101,7 +101,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
value = value.substr(3).trim();
if (value[0] === '}') {
value = value.substr(1).trim();
return '<...>' as any;
return '<...>';
}
}
const eqPos = value.indexOf('=');
Expand Down Expand Up @@ -136,7 +136,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
if (result) {
const results = [];
results.push(result);
while (result = parseCommaResult(true)) {
while ((result = parseCommaResult(true))) {
results.push(result);
}
value = value.substr(1).trim(); // }
Expand All @@ -146,7 +146,7 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
return undefined;
};

function parsePrimitive() {
function parsePrimitive(): unknown {
let primitive: any;
let match;
value = value.trim();
Expand All @@ -158,26 +158,26 @@ export function expandValue(variableCreate: (value: string | object, opts?: { ar
} else if (value.startsWith('false')) {
primitive = 'false';
value = value.substr(5).trim();
} else if (match = nullpointerRegex.exec(value)) {
} else if ((match = nullpointerRegex.exec(value))) {
primitive = '<nullptr>';
value = value.substr(match[0].length).trim();
} else if (match = referenceStringRegex.exec(value)) {
} else if ((match = referenceStringRegex.exec(value))) {
value = value.substr(match[1].length).trim();
primitive = parseCString();
} else if (match = referenceRegex.exec(value)) {
} else if ((match = referenceRegex.exec(value))) {
primitive = '*' + match[0];
value = value.substr(match[0].length).trim();
} else if (match = charRegex.exec(value)) {
} else if ((match = charRegex.exec(value))) {
primitive = match[1];
value = value.substr(match[0].length - 1);
primitive += ' ' + parseCString();
} else if (match = numberRegex.exec(value)) {
} else if ((match = numberRegex.exec(value))) {
primitive = match[0];
value = value.substr(match[0].length).trim();
} else if (match = variableRegex.exec(value)) {
} else if ((match = variableRegex.exec(value))) {
primitive = match[0];
value = value.substr(match[0].length).trim();
} else if (match = errorRegex.exec(value)) {
} else if ((match = errorRegex.exec(value))) {
primitive = match[0];
value = value.substr(match[0].length).trim();
} else {
Expand Down
24 changes: 0 additions & 24 deletions src/backend/linux/console.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function escape(str: string) {
return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
}

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

Expand Down Expand Up @@ -908,7 +908,7 @@ export class MI2 extends EventEmitter implements IBackend {

const thFr = ((threadId !== undefined) && (frameId !== undefined)) ? `--thread ${threadId} --frame ${frameId}` : '';
const createResp = await this.sendCommand(`var-create ${thFr} ${name} ${scope} "${expression}"`);
let overrideVal = null;
let overrideVal: string = null;
if (fmt && name !== '-') {
const formatResp = await this.sendCommand(`var-set-format ${name} ${MI2.FORMAT_SPEC_MAP[fmt]}`);
overrideVal = formatResp.result('value');
Expand Down
22 changes: 11 additions & 11 deletions src/backend/mi_parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MINode implements MIInfo {
if (!start) {
return undefined;
}
const pathRegex = /^\.?([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
const pathRegex = /^\.?([a-zA-Z_-][a-zA-Z0-9_-]*)/;
const indexRegex = /^\[(\d+)\](?:$|\.)/;
path = path.trim();
if (!path) { return start; }
Expand Down Expand Up @@ -136,11 +136,11 @@ export class MINode implements MIInfo {
}

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

export function parseMI(output: string): MINode {
Expand Down Expand Up @@ -195,7 +195,7 @@ export function parseMI(output: string): MINode {
remaining = remaining.substr(1);
stringEnd++;
}
let str;
let str: string;
try {
str = parseString(output.substr(0, stringEnd));
} catch (e) {
Expand All @@ -205,7 +205,7 @@ export function parseMI(output: string): MINode {
return str;
};

function parseTupleOrList() {
function parseTupleOrList(): unknown[] {
if (output[0] !== '{' && output[0] !== '[') {
return undefined;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ export function parseMI(output: string): MINode {
if (result) {
const results = [];
results.push(result);
while (result = parseCommaResult()) {
while ((result = parseCommaResult())) {
results.push(result);
}
output = output.substr(1); // }
Expand All @@ -243,7 +243,7 @@ export function parseMI(output: string): MINode {
return undefined;
};

function parseValue() {
function parseValue(): unknown {
if (output[0] === '"') {
return parseCString();
} else if (output[0] === '{' || output[0] === '[') {
Expand Down Expand Up @@ -281,7 +281,7 @@ export function parseMI(output: string): MINode {

let match;

while (match = outOfBandRecordRegex.exec(output)) {
while ((match = outOfBandRecordRegex.exec(output))) {
output = output.substr(match[0].length);
if (match[1] && token === undefined && match[1] !== 'undefined') {
token = parseInt(match[1]);
Expand All @@ -297,7 +297,7 @@ export function parseMI(output: string): MINode {
output: []
};
let result;
while (result = parseCommaResult()) {
while ((result = parseCommaResult())) {
asyncRecord.output.push(result);
}
outOfBandRecord.push(asyncRecord);
Expand All @@ -313,7 +313,7 @@ export function parseMI(output: string): MINode {
output = output.replace(newlineRegex, '');
}

if (match = resultRecordRegex.exec(output)) {
if ((match = resultRecordRegex.exec(output))) {
output = output.substr(match[0].length);
if (match[1] && token === undefined) {
token = parseInt(match[1]);
Expand All @@ -323,7 +323,7 @@ export function parseMI(output: string): MINode {
results: []
};
let result;
while (result = parseCommaResult()) {
while ((result = parseCommaResult())) {
resultRecords.results.push(result);
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GDBDebugSession } from '../gdb';
import { hexFormat } from '../frontend/utils';
import { MINode } from './mi_parse';

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

private rttSymbol;
private rttSymbol: SymbolInformation;
public readonly rttSymbolName = '_SEGGER_RTT';
private addSymbol(sym: SymbolInformation) {
if ((sym.length === 0) && /^\$[atdbfpm]$/.test(sym.name)) {
Expand Down
4 changes: 2 additions & 2 deletions src/bmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class BMPServerController extends EventEmitter implements GDBServerContro
}

public attachCommands(): string[] {
const commands = [];
const commands: string[] = [];
return commands;
}

Expand All @@ -76,7 +76,7 @@ export class BMPServerController extends EventEmitter implements GDBServerContro
}

public swoAndRTTCommands(): string[] {
const commands = [];
const commands: string[] = [];
if (this.args.swoConfig.enabled) {
const swocommands = this.SWOConfigurationCommands();
commands.push(...swocommands);
Expand Down
Loading

0 comments on commit 3e6bb5f

Please sign in to comment.