Skip to content

Commit

Permalink
update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Dec 12, 2024
1 parent 298c8a4 commit dc239c3
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 140 deletions.
10 changes: 0 additions & 10 deletions .eslintignore

This file was deleted.

53 changes: 0 additions & 53 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/get_test_infos/discover_test_dirs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile, readdir } from 'fs/promises';
import { readdir, readFile } from 'fs/promises';
import { join } from 'path';

// Recursively find directories and check for package.json with a test script
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/get_test_infos/get_test_infos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { discoverTestDirs } from './discover_test_dirs.js';
import { dirToTestInfo, TestInfo } from './dir_to_test_info.js';
import { discoverTestDirs } from './discover_test_dirs.js';

export async function getTestInfos(
dirs: string[],
Expand Down
72 changes: 72 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import eslint from '@eslint/js';
import tseslintParser from '@typescript-eslint/parser';
import prettier from 'eslint-config-prettier';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
prettier,
{
ignores: [
'docs/**',
'the_azle_book/**',
'tests/property/candid_rpc/**/src/**',
'**/.azle/**',
'**/.dfx/**',
'**/declarations/**',
'**/dfx_generate/**',
'**/dfx_generated/**',
'**/dist/**',
'**/node_modules/**',
'**/run_time_errors/**',
'**/target/**',
'**/webpack.config.js'
]
},
{
files: ['**/*.{js,mjs,cjs,ts}'],
languageOptions: {
parser: tseslintParser,
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
}
},
plugins: {
'simple-import-sort': simpleImportSort
},
rules: {
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
'func-style': [
'error',
'declaration',
{ allowArrowFunctions: true }
],
'array-callback-return': 'error',
'no-template-curly-in-string': 'error',
'prefer-template': 'error',
'no-param-reassign': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'prefer-arrow-callback': 'error',
'no-var': 'error',
'@typescript-eslint/explicit-function-return-type': ['error'],
eqeqeq: 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
],
'@typescript-eslint/ban-ts-comment': 'off',
'prefer-const': 'off', // For azle let is used to indicate mutability not only re-assignability
'no-undef': 'off', // TS compiler handles this for us
'@typescript-eslint/no-explicit-any': 'off' // TODO https://github.com/demergent-labs/azle/issues/1737
}
}
);
1 change: 0 additions & 1 deletion examples/basic_bitcoin/src/bitcoin_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ async function buildTransaction(
// rebuild the transaction, until the fee is set to the correct amount.
console.info('Building transaction...');
let totalFee = 0n;
// eslint-disable-next-line no-constant-condition
while (true) {
const transaction = buildTransactionWithFee(
ownUtxos,
Expand Down
1 change: 0 additions & 1 deletion examples/bitcoin_psbt/src/bitcoin_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ async function buildTransaction(
// rebuild the transaction, until the fee is set to the correct amount.
console.info('Building transaction...');
let totalFee = 0n;
// eslint-disable-next-line no-constant-condition
while (true) {
const transaction = buildTransactionWithFee(
ownUtxos,
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "TypeScript and JavaScript CDK for the Internet Computer",
"scripts": {
"typecheck": "tsc --noEmit",
"lint": "if [ \"$npm_config_fix\" ]; then eslint . --ext .js,.ts --cache --fix; else eslint . --ext .js,.ts --cache; fi",
"lint": "if [ \"$npm_config_fix\" ]; then eslint . --cache --fix; else eslint . --cache; fi",
"prepare": "husky",
"install": "cd dfx_extension && ./install.sh",
"test": "echo 'test'"
Expand Down Expand Up @@ -57,22 +57,26 @@
},
"devDependencies": {
"@dfinity/identity": "^2.1.3",
"@eslint/js": "^9.16.0",
"@types/deep-equal": "^1.0.4",
"@types/fs-extra": "11.0.4",
"@types/pako": "^2.0.3",
"@types/text-encoding": "^0.0.40",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"deep-equal": "^2.2.3",
"eslint": "^8.54.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint": "^9.16.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"fast-check": "^3.23.1",
"husky": "9.1.7",
"jest": "^29.7.0",
"lint-staged": "15.2.11",
"prettier": "^3.4.2",
"puppeteer": "^23.10.3",
"ts-jest": "^29.1.4"
"ts-jest": "^29.1.4",
"typescript-eslint": "^8.18.0"
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
Expand Down
2 changes: 0 additions & 2 deletions scripts/jest_isolate_modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import * as fs from 'fs';
import * as path from 'path';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function setupFileWatcher(
// TODO does not result in a 0 exit code
// TODO and look into removing the try catch?
execSyncPretty(`pkill -f ./file_watcher_loader.js || true`);
} catch (error) {
} catch {
// For some reason pkill throws even with || true
}

Expand Down
2 changes: 1 addition & 1 deletion test/property/get_actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getActor(parentDir: string, agent?: Agent): any {
delete require.cache[resolvedPathIndex];
delete require.cache[resolvedPathDid];

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { createActor } = require(`${parentDir}/dfx_generated/canister`);

return createActor(getCanisterId('canister'), {
Expand Down
2 changes: 1 addition & 1 deletion test/property/test/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO import deepEqual from 'deep-is' works for some
// TODO import { deepEqual } from 'deep-is' works for others
// TODO require seems to work for all of them
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const deepEqual = require('deep-is');

import { jsonStringify } from '../../../src/lib/stable/json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class {
async getRejectionCodeDestinationInvalid(): Promise<RejectionCode> {
try {
await call('rkp4c-7iaaa-aaaaa-aaaca-cai', 'method');
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -61,7 +61,7 @@ export default class {
paramIdlTypes: [IDL.Text],
args: ['reject']
});
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -72,7 +72,7 @@ export default class {
async getRejectionCodeCanisterError(): Promise<RejectionCode> {
try {
await call(getSomeCanisterPrincipal(), 'error');
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -86,7 +86,7 @@ export default class {
paramIdlTypes: [IDL.Text],
args: [message]
});
} catch (error) {
} catch {
// continue regardless of error
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default Canister({
} else {
await ic.call(nonexistentCanister.method);
}
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -71,7 +71,7 @@ export default Canister({
} else {
await ic.call(someCanister.reject, { args: ['reject'] });
}
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -88,7 +88,7 @@ export default Canister({
} else {
await ic.call(someCanister.error);
}
} catch (error) {
} catch {
// continue regardless of error
}

Expand All @@ -106,7 +106,7 @@ export default Canister({
} else {
await ic.call(someCanister.reject, { args: [message] });
}
} catch (error) {
} catch {
// continue regardless of error
}

Expand Down
8 changes: 4 additions & 4 deletions tests/end_to_end/http_server/tfjs/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ async function init(): Promise<void> {

tf.env().platform = {
fetch,
now: () => Number(ic.time()), // TODO time probably off (look into nano vs milli)
encode: (text) => Buffer.from(text),
decode: (bytes) => Buffer.from(bytes).toString(),
isTypedArray: ((array: any) => {
now: (): number => Number(ic.time()), // TODO time probably off (look into nano vs milli)
encode: (text: string): Buffer => Buffer.from(text),
decode: (bytes: Uint8Array): string => Buffer.from(bytes).toString(),
isTypedArray: ((array: any): boolean => {
return (array instanceof Float32Array ||
array instanceof Int32Array ||
array instanceof Uint8Array ||
Expand Down
4 changes: 2 additions & 2 deletions tests/property/ic_api/reject_code/src/caller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function getThrowErrorRejectCode(
await call(rejectorPrincipal, 'throwError', {
returnIdlType: IDL.Text
});
} catch (error) {
} catch {
return rejectCode();
}
throw new Error('This should never be thrown');
Expand All @@ -60,7 +60,7 @@ async function getRejectWithMessageRejectCode(
await call(rejectorPrincipal, 'rejectWithMessage', {
returnIdlType: IDL.Text
});
} catch (error) {
} catch {
return rejectCode();
}
throw new Error('This should never be thrown');
Expand Down
2 changes: 1 addition & 1 deletion tests/property/ic_api/reject_message/src/caller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function getRejectMessage(
returnIdlType: IDL.Text,
args: [message]
});
} catch (error) {
} catch {
return rejectMessage();
}
throw new Error('This should never be thrown');
Expand Down
12 changes: 6 additions & 6 deletions type_tests/candid/constructed/opt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import {
testCandidType(Opt(float32));
testSerializable(Opt(float32));

const testTypeMapping = Opt(float32);
const _testTypeMapping = Opt(float32);
export type TestTypeMapping = AssertType<
NotAnyAndExact<
TypeMapping<typeof testTypeMapping>,
TypeMapping<typeof _testTypeMapping>,
RequireExactlyOne<{ Some: number; None: null }>
>
>;

testCandidType(Opt(Opt(float32)));
testSerializable(Opt(Opt(float32)));

const testTypeMappingDouble = Opt(Opt(float32));
const _testTypeMappingDouble = Opt(Opt(float32));
export type TestTypeMappingDouble = AssertType<
NotAnyAndExact<
TypeMapping<typeof testTypeMappingDouble>,
TypeMapping<typeof _testTypeMappingDouble>,
RequireExactlyOne<{
Some: RequireExactlyOne<{ Some: number; None: null }>;
None: null;
Expand All @@ -45,10 +45,10 @@ export type TestTypeMappingDouble = AssertType<
testCandidType(Opt(Opt(Opt(float32))));
testSerializable(Opt(Opt(Opt(float32))));

const testTypeMappingTriple = Opt(Opt(Opt(float32)));
const _testTypeMappingTriple = Opt(Opt(Opt(float32)));
export type TestTypeMappingTriple = AssertType<
NotAnyAndExact<
TypeMapping<typeof testTypeMappingTriple>,
TypeMapping<typeof _testTypeMappingTriple>,
RequireExactlyOne<{
Some: RequireExactlyOne<{
Some: RequireExactlyOne<{ Some: number; None: null }>;
Expand Down
Loading

0 comments on commit dc239c3

Please sign in to comment.