Skip to content

Commit

Permalink
Fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuddi authored and rileystephens28 committed May 21, 2024
1 parent 04d6c90 commit 4e40c8c
Show file tree
Hide file tree
Showing 49 changed files with 210 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"_build-dist": "rollup -c && uglifyjs ./dist/quais.js -o ./dist/quais.min.js && uglifyjs ./dist/quais.umd.js -o ./dist/quais.umd.min.js && uglifyjs ./dist/wordlists-extra.js -o ./dist/wordlists-extra.min.js",
"_dist-stats": "gzip -k9f -S '.gz' ./dist/quais.min.js && gzip -k9f -S '.gz' ./dist/quais.umd.min.js && gzip -k9f -S '.gz' ./dist/wordlists-extra.min.js && du -hs ./dist/*.gz && echo '' && du -hs ./dist/*.js",
"auto-build": "npm run build -- -w",
"lint": "eslint src.ts/**/*.ts",
"lint": "eslint src.ts/**/*.ts --fix",
"build": "tsc --project tsconfig.esm.json",
"build-all": "npm run build && npm run build-commonjs",
"build-clean": "npm run clean && npm run build && npm run build-all && npm run _build-dist && npm run _dist-stats",
Expand Down
9 changes: 7 additions & 2 deletions src.ts/_admin/test-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CDPSession {
this.#id = 1;
this.#resp = new Map();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.#exit = (status: number) => {};
this.#done = new Promise((resolve) => {
this.#exit = resolve;
Expand All @@ -80,6 +81,7 @@ export class CDPSession {
this.#target = '';
this.#session = '';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const readyOpen: Promise<void> = new Promise((resolve, reject) => {
this.websocket.onopen = async () => {
resolve();
Expand Down Expand Up @@ -133,6 +135,7 @@ export class CDPSession {
}
console.log(text);
//console.log(msg.params.message.text, `${ msg.params.message.url }:${ msg.params.message.line }`);
// eslint-disable-next-line no-empty
} else if (msg.method === 'Target.attachedToTarget') {
} else {
console.log(`WARN: Unhandled event - ${JSON.stringify(msg)}`);
Expand Down Expand Up @@ -199,7 +202,7 @@ const TestData = (function () {
return [String(data.length), zlib.deflateRawSync(data).toString('base64')].join(',');
}

let data: Array<string> = [];
const data: Array<string> = [];
data.push(`import { quais } from "/index.js";`);
data.push(`import { inflate } from "/static/tiny-inflate.js";`);
data.push(`const fs = new Map();`);
Expand Down Expand Up @@ -322,6 +325,7 @@ export function start(_root: string, options: Options): Promise<Server> {
}
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise((resolve, reject) => {
server.listen(options.port, () => {
console.log(`Server running on: http://localhost:${options.port}`);
Expand Down Expand Up @@ -351,7 +355,8 @@ export function start(_root: string, options: Options): Promise<Server> {
const args = ['--headless', '--disable-gpu', '--remote-debugging-port=8022'];
const browser = child_process.spawn(cmd, args);

let url: string = await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const url: string = await new Promise((resolve, reject) => {
browser.stdout.on('data', (data) => {
console.log('OUT', data.toString());
});
Expand Down
4 changes: 3 additions & 1 deletion src.ts/_admin/update-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type PresentVersion = {
{
const content = fs.readFileSync(resolve('CHANGELOG.md')).toString();
for (const line of content.split('\n')) {
let match = line.match(/^ethers\/v(\S+)\s/);
const match = line.match(/^ethers\/v(\S+)\s/);
if (match) {
present.push({ version: match[1], body: [line] });
} else {
Expand Down Expand Up @@ -188,12 +188,14 @@ type PresentVersion = {
let line = ` - ${change.message} (`;
line += change.issues
.map((i) => {
// eslint-disable-next-line no-useless-escape
return `[#${i}](https:/\/github.com/ethers-io/ethers.js/issues/${i})`;
})
.join(', ');
if (change.issues.length) {
line += '; ';
}
// eslint-disable-next-line no-useless-escape
line += `[${change.commit.substring(0, 7)}](https:/\/github.com/ethers-io/ethers.js/commit/${change.commit})).`;
output.push(line);
}
Expand Down
2 changes: 2 additions & 0 deletions src.ts/_tests/create-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export function getProvider(provider: string, network: string): null | AbstractP
return null;
}

// TODO: `newtork` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function checkProvider(provider: string, network: string): boolean {
const creator = getCreator(provider);
return creator != null;
Expand Down
8 changes: 8 additions & 0 deletions src.ts/_tests/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ describe('Test Typed Contract Interaction', function () {
'int248',
'int256',
],
// TODO: `type` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
valueFunc: (type: string) => {
return 42;
},
Expand Down Expand Up @@ -333,18 +335,24 @@ describe('Test Typed Contract Interaction', function () {
},
{
types: ['bool'],
// TODO: `type` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
valueFunc: (type: string) => {
return true;
},
},
{
types: ['address'],
// TODO: `type` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
valueFunc: (type: string) => {
return '0x643aA0A61eADCC9Cc202D1915D942d35D005400C';
},
},
{
types: ['string'],
// TODO: `type` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
valueFunc: (type: string) => {
return 'someString';
},
Expand Down
2 changes: 2 additions & 0 deletions src.ts/_tests/test-crypto-algoswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ describe('test registration', function () {
it('prevents swapping after locked', function () {
lock();

// TODO: `params` and `hijackTag` are not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
tests.forEach(({ name, params, hijackTag, algorithm }) => {
assert.throws(
function () {
Expand Down
4 changes: 4 additions & 0 deletions src.ts/_tests/test-provider-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function createProvider(testFunc: ProcessRequest): JsonRpcProvider {
};

const req = new FetchRequest('http://localhost:8082/');
// TODO: `signal` is not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
req.getUrlFunc = async (_req, signal) => {
const req = JSON.parse(_req.hasBody() ? toUtf8String(_req.body) : '');

Expand Down Expand Up @@ -161,6 +163,8 @@ describe('Ensure Catchable Errors', function () {
// A provider which is mocked to return a "missing v"
// in getTransaction

// TODO: `blockNumber` and `params` are not used, remove or re-write
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const provider = createProvider((method, params, blockNumber) => {
switch (method) {
case 'quai_sendTransaction':
Expand Down
28 changes: 18 additions & 10 deletions src.ts/_tests/test-providers-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function equals(name: string, actual: any, expected: any): void {
assert.ok(false, name + ' - actual object null');
}

let keys: { [key: string]: boolean } = {};
const keys: { [key: string]: boolean } = {};
Object.keys(expected).forEach((key) => {
keys[key] = true;
});
Expand Down Expand Up @@ -100,7 +100,7 @@ async function sendTransaction(to: string) {
do {
typeValue = getTxType(wallet.address, to);
const gas = await getRPCGasPrice(process.env.CYPRUS1URL);
let tx: {
const tx: {
from: string;
to: string;
value: any;
Expand Down Expand Up @@ -142,6 +142,8 @@ async function sendTransaction(to: string) {
}

async function fetchRPCBlock(blockNumber: string | null) {
// TODO: this is supposedly an un-needed try-catch, consider revising
// eslint-disable-next-line no-useless-catch
try {
let response;
do {
Expand Down Expand Up @@ -232,10 +234,11 @@ describe('Test Provider Block operations', function () {
});

it('should fetch block by number', async function () {
let responseBlock = (await providerC1.getBlock('0,0', '0xA')) as quais.Block;
const responseBlock = (await providerC1.getBlock('0,0', '0xA')) as quais.Block;
assert.ok(responseBlock != null, 'block != null');

let { provider, ...formatBlock } = {
// TODO: `provider` is not used, remove?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { provider, ...formatBlock } = {
...responseBlock,
transactions: responseBlock.transactions,
extTransactions: responseBlock.extTransactions,
Expand All @@ -245,10 +248,11 @@ describe('Test Provider Block operations', function () {

it('should fetch block by hash', async function () {
assert.ok(block.hash != null, 'block.hash != null');
let responseBlock = (await providerC1.getBlock('0,0', block.hash)) as quais.Block;
const responseBlock = (await providerC1.getBlock('0,0', block.hash)) as quais.Block;
assert.ok(responseBlock != null, 'block != null');

let { provider, ...formatBlock } = {
// TODO: `provider` is not used, remove?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { provider, ...formatBlock } = {
...responseBlock,
transactions: responseBlock.transactions,
extTransactions: responseBlock.extTransactions,
Expand Down Expand Up @@ -293,7 +297,9 @@ describe('Test Transaction operations', function () {
type: receipt.type,
};
const receiptResponse = await providerC1.getTransactionReceipt(internalTx.hash);
let { provider, ...receiptResult } = {
// TODO: `provider` is not used, remove?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { provider, ...receiptResult } = {
...receiptResponse,
logs: receiptResponse?.logs,
};
Expand Down Expand Up @@ -343,7 +349,9 @@ describe('Test Transaction operations', function () {
type: Number(receipt.type),
};
const receiptResponse = await providerC1.getTransactionReceipt(internalToExternalTx.hash);
let { provider, ...receiptResult } = {
// TODO: `provider` is not used, remove?
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { provider, ...receiptResult } = {
...receiptResponse,
logs: receiptResponse?.logs,
};
Expand Down
8 changes: 4 additions & 4 deletions src.ts/_tests/test-wordlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Check Wordlists', function () {
const tests = loadTests<TestCaseWordlist>('wordlists');

tests.forEach((test) => {
let wordlist = wordlists[test.locale];
const wordlist = wordlists[test.locale];
if (wordlist == null) {
return;
}
Expand All @@ -20,7 +20,7 @@ describe('Check Wordlists', function () {

let check = '';
for (let i = 0; i < 2048; i++) {
let word = wordlist.getWord(i);
const word = wordlist.getWord(i);
check += word + '\n';
assert.equal(word, words[i]);
assert.equal(wordlist.getWordIndex(word), i);
Expand All @@ -31,7 +31,7 @@ describe('Check Wordlists', function () {
});

tests.forEach((test) => {
let wordlist = wordlists[test.locale];
const wordlist = wordlists[test.locale];
if (wordlist == null) {
return;
}
Expand All @@ -53,7 +53,7 @@ describe('Check Wordlists', function () {
});

tests.forEach((test) => {
let wordlist = wordlists[test.locale];
const wordlist = wordlists[test.locale];
if (wordlist == null) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src.ts/_tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import zlib from 'zlib';
const root = (function () {
let root = process.cwd();

// eslint-disable-next-line no-constant-condition
while (true) {
if (fs.existsSync(path.join(root, 'output'))) {
return root;
Expand Down
7 changes: 4 additions & 3 deletions src.ts/abi/abi-coder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class AbiCoder {
// u?int[0-9]*
let match = param.type.match(paramTypeNumber);
if (match) {
let size = parseInt(match[2] || '256');
const size = parseInt(match[2] || '256');
assertArgument(
size !== 0 && size <= 256 && size % 8 === 0,
'invalid ' + match[1] + ' bit length',
Expand All @@ -170,7 +170,7 @@ export class AbiCoder {
// bytes[0-9]+
match = param.type.match(paramTypeBytes);
if (match) {
let size = parseInt(match[1]);
const size = parseInt(match[1]);
assertArgument(size !== 0 && size <= 32, 'invalid bytes length', 'param', param);
return new FixedBytesCoder(size, param.name);
}
Expand Down Expand Up @@ -219,7 +219,8 @@ export class AbiCoder {
*
* @param {(string | ParamType)[]} types - Array of parameter types.
* @param {BytesLike} data - The ABI data to decode.
* @param {boolean} [loose=false] - Enable loose decoding. Default is `false` Default is `false`
* @param {boolean} [loose=false] - Enable loose decoding. Default is `false` Default is `false` Default is `false`
* Default is `false`
*
* @returns {Result} The decoded values.
*/
Expand Down
16 changes: 10 additions & 6 deletions src.ts/abi/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ function lex(text: string): TokenString {
throw new Error(`invalid token ${token} at ${offset}: ${message}`);
};

let brackets: Array<number> = [];
let commas: Array<number> = [];
const brackets: Array<number> = [];
const commas: Array<number> = [];

let offset = 0;
while (offset < text.length) {
Expand All @@ -362,7 +362,7 @@ function lex(text: string): TokenString {
};
tokens.push(token);

let type = SimpleTokens[cur[0]] || '';
const type = SimpleTokens[cur[0]] || '';
if (type) {
token.type = type;
token.text = cur[0];
Expand Down Expand Up @@ -440,7 +440,7 @@ function lex(text: string): TokenString {

// Check only one of `allowed` is in `set`
function allowSingle(set: ReadonlySet<string>, allowed: ReadonlySet<string>): void {
let included: Array<string> = [];
const included: Array<string> = [];
for (const key in allowed.keys()) {
if (set.has(key)) {
included.push(key);
Expand Down Expand Up @@ -468,6 +468,7 @@ function consumeName(type: string, tokens: TokenString): string {
// ...all keywords matching allowed, returning the keywords
function consumeKeywords(tokens: TokenString, allowed?: ReadonlySet<string>): ReadonlySet<string> {
const keywords: Set<string> = new Set();
// eslint-disable-next-line no-constant-condition
while (true) {
const keyword = tokens.peekType('KEYWORD');

Expand All @@ -487,7 +488,7 @@ function consumeKeywords(tokens: TokenString, allowed?: ReadonlySet<string>): Re

// ...all visibility keywords, returning the coalesced mutability
function consumeMutability(tokens: TokenString): 'payable' | 'nonpayable' | 'view' | 'pure' {
let modifiers = consumeKeywords(tokens, KwVisib);
const modifiers = consumeKeywords(tokens, KwVisib);

// Detect conflicting modifiers
allowSingle(modifiers, setify('constant payable nonpayable'.split(' ')));
Expand Down Expand Up @@ -794,6 +795,7 @@ export class ParamType {
if (this.arrayLength !== -1 && value.length !== this.arrayLength) {
throw new Error('array is wrong length');
}
// eslint-disable-next-line @typescript-eslint/no-this-alias
const _this = this;
return value.map((v) => _this.arrayChildren.walk(v, process));
}
Expand All @@ -805,6 +807,7 @@ export class ParamType {
if (value.length !== this.components.length) {
throw new Error('array is wrong length');
}
// eslint-disable-next-line @typescript-eslint/no-this-alias
const _this = this;
return value.map((v, i) => _this.components[i].walk(v, process));
}
Expand Down Expand Up @@ -977,7 +980,7 @@ export class ParamType {

let type = obj.type;

let arrayMatch = type.match(regexArrayType);
const arrayMatch = type.match(regexArrayType);
if (arrayMatch) {
const arrayLength = parseInt(arrayMatch[2] || '-1');
const arrayChildren = ParamType.from({
Expand Down Expand Up @@ -1053,6 +1056,7 @@ export abstract class Fragment {
// Try parsing JSON...
try {
Fragment.from(JSON.parse(obj));
// eslint-disable-next-line no-empty
} catch (e) {}

// ...otherwise, use the human-readable lexer
Expand Down
Loading

0 comments on commit 4e40c8c

Please sign in to comment.