Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint fixes #1460

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ the_azle_book
type_tests
run_time_errors
**/webpack.config.js
dfx_generate
dfx_generated
declarations
property_tests/tests/**/src/*
28 changes: 12 additions & 16 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
// TODO: These rules should be enabled, but we had offenses when we enabled ESLint.
// This is tech-debt. We should go through and re-enable these at some point.
const temporarilyDisabledRules = {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-as-const': 'off',
'no-constant-condition': 'off',
'no-empty': 'off',
'no-prototype-builtins': 'off',
'no-undef': 'off',
'no-useless-catch': 'off',
'no-useless-escape': 'off',
'no-var': 'off',
'prefer-const': 'off'
'@typescript-eslint/ban-ts-comment': 'off', // 39 problems
'@typescript-eslint/no-explicit-any': 'off', // 321 problems
'@typescript-eslint/no-unused-vars': 'off', // 33 problems
'@typescript-eslint/no-var-requires': 'off', // 8 problems
'no-constant-condition': 'off', // 1 problem
'no-undef': 'off', // 11 problems
'no-var': 'off', // 6 problems
'prefer-const': 'off' // 137 problems
};

module.exports = {
Expand Down Expand Up @@ -49,6 +41,10 @@ module.exports = {
rules: {
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_' }
],
...temporarilyDisabledRules
}
};
2 changes: 1 addition & 1 deletion examples/bitcoin/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCanisterId, ok, runTests, Test } from 'azle/test';
import { getCanisterId, runTests, Test } from 'azle/test';

import { bitcoinCli } from './bitcoin_cli';
import { createActor } from './dfx_generated/bitcoin';
Expand Down
4 changes: 2 additions & 2 deletions examples/bitcoin/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Test } from 'azle/test';
// import { Test } from 'azle/test';

import { _SERVICE } from './dfx_generated/bitcoin/bitcoin.did';
// import { _SERVICE } from './dfx_generated/bitcoin/bitcoin.did';
// import { ActorSubclass } from '@dfinity/agent';

// export function get_tests(update_canister: ActorSubclass<_SERVICE>): Test[] {
Expand Down
2 changes: 1 addition & 1 deletion examples/canister/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { _SERVICE } from './dfx_generated/canister/canister.did';

// TODO these tests should be rewritten to use @dfinity/agent once this issue is resolved: https://github.com/dfinity/agent-js/issues/702
// TODO this issue also needs to be resolved: https://forum.dfinity.org/t/services-wont-deserialize-properly-if-functions-arent-in-alphabetical-order/20885
export function getTests(canister: ActorSubclass<_SERVICE>): Test[] {
export function getTests(_canister: ActorSubclass<_SERVICE>): Test[] {
return [
{
name: 'canisterParam',
Expand Down
2 changes: 0 additions & 2 deletions examples/ckbtc/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ export function getTests(): Test[] {
return { Err: Object.keys(updateBalanceResult.Err)[0] };
}

const okValue = updateBalanceResult.Ok;

return { Ok: true };
}
},
Expand Down
17 changes: 8 additions & 9 deletions examples/guard_functions/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ActorSubclass } from '@dfinity/agent';
import { AgentError } from '@dfinity/agent/lib/cjs/errors';
import { Test } from 'azle/test';
import { execSync } from 'child_process';

import { _SERVICE } from './dfx_generated/guard_functions/guard_functions.did';

Expand Down Expand Up @@ -82,8 +81,8 @@ export function getTests(
name: 'tightlyGuarded',
test: async () => {
try {
const result =
await guardFunctionsCanister.tightlyGuarded();
await guardFunctionsCanister.tightlyGuarded();

return {
Err: 'Expected tightlyGuarded function to throw'
};
Expand All @@ -100,8 +99,8 @@ export function getTests(
name: 'errorStringGuarded',
test: async () => {
try {
const result =
await guardFunctionsCanister.errorStringGuarded();
await guardFunctionsCanister.errorStringGuarded();

return {
Err: 'Expected errorStringGuarded function to throw'
};
Expand All @@ -118,8 +117,8 @@ export function getTests(
name: 'customErrorGuarded',
test: async () => {
try {
const result =
await guardFunctionsCanister.customErrorGuarded();
await guardFunctionsCanister.customErrorGuarded();

return {
Err: 'Expected customErrorGuarded function to throw'
};
Expand All @@ -136,8 +135,8 @@ export function getTests(
name: 'nonStringErrValueGuarded',
test: async () => {
try {
const result =
await guardFunctionsCanister.nonStringErrValueGuarded();
await guardFunctionsCanister.nonStringErrValueGuarded();

return {
Err: 'Expected nonStringErrValueGuarded function to throw'
};
Expand Down
20 changes: 6 additions & 14 deletions examples/ic_api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,13 @@ export default Canister({
// }

// returns the argument data as bytes.
argDataRaw: query(
[blob, int8, bool, text],
blob,
(arg1, arg2, arg3, arg4) => {
return ic.argDataRaw();
}
),
argDataRaw: query([blob, int8, bool, text], blob, () => {
dansteren marked this conversation as resolved.
Show resolved Hide resolved
return ic.argDataRaw();
}),
// returns the length of the argument data in bytes
argDataRawSize: query(
[blob, int8, bool, text],
nat32,
(arg1, arg2, arg3, arg4) => {
return ic.argDataRawSize();
}
),
argDataRawSize: query([blob, int8, bool, text], nat32, () => {
return ic.argDataRawSize();
}),
// returns the principal of the identity that called this function
caller: query([], Principal, () => {
return ic.caller();
Expand Down
5 changes: 2 additions & 3 deletions examples/inspect_message/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getTests(
name: 'not calling `ic.acceptMessage` in inspectMessage',
test: async () => {
try {
const result = await inspectMessageCanister.inaccessible();
await inspectMessageCanister.inaccessible();
return {
Ok: false
};
Expand All @@ -44,8 +44,7 @@ export function getTests(
name: 'throwing in `inspectMessage`',
test: async () => {
try {
const result =
await inspectMessageCanister.alsoInaccessible();
await inspectMessageCanister.alsoInaccessible();

return {
Ok: false
Expand Down
6 changes: 3 additions & 3 deletions examples/ledger_canister/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActorSubclass } from '@dfinity/agent';
import { Principal } from '@dfinity/principal';
import { ok, Test } from 'azle/test';
import { Test } from 'azle/test';
import { execSync } from 'child_process';

import { _SERVICE } from './dfx_generated/ledger_canister/ledger_canister.did';
Expand Down Expand Up @@ -194,7 +194,7 @@ function getTransferErrorTests(
name: 'deploy icpLedger',
prep: async () => {
execSync(
`dfx deploy icp_ledger --argument=\'(record {minting_account = "\'$(dfx ledger account-id)\'"; initial_values = vec {}; send_whitelist = vec {}})\'`,
`dfx deploy icp_ledger --argument='(record {minting_account = "'$(dfx ledger account-id)'"; initial_values = vec {}; send_whitelist = vec {}})'`,
{
stdio: 'inherit'
}
Expand Down Expand Up @@ -261,7 +261,7 @@ function getTransferErrorTests(
name: 'deploy icpLedger',
prep: async () => {
execSync(
`dfx deploy icp_ledger --argument=\'(record {minting_account = "\'$(dfx ledger account-id)\'"; initial_values = vec { record { "\'$(dfx ledger account-id --of-canister ledger_canister)\'"; record { e8s=100_000_000_000 } }; }; send_whitelist = vec {}})\'`,
`dfx deploy icp_ledger --argument='(record {minting_account = "'$(dfx ledger account-id)'"; initial_values = vec { record { "'$(dfx ledger account-id --of-canister ledger_canister)'"; record { e8s=100_000_000_000 } }; }; send_whitelist = vec {}})'`,
{
stdio: 'inherit'
}
Expand Down
9 changes: 1 addition & 8 deletions examples/list_of_lists/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
name: 'listOfEmpty test',
test: async () => {
try {
const result = await listOfListsCanister.listOfEmpty();
await listOfListsCanister.listOfEmpty();
} catch (error) {
return {
Ok: (error as any).message.startsWith('Call failed')
Expand Down Expand Up @@ -238,13 +238,6 @@ export function getTests(listOfListsCanister: ActorSubclass<_SERVICE>): Test[] {
const expectedResult = [[[Principal.fromText('aaaaa-aa')]]];
const result =
await listOfListsCanister.listOfPrincipal(expectedResult);
const principalEq = (a: any, b: any) => {
return (
'toText' in a &&
'toText' in b &&
a.toText() === b.toText()
);
};

return {
Ok:
Expand Down
21 changes: 7 additions & 14 deletions examples/management_canister/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {
const canisterId =
await managementCanister.getCreatedCanisterId();

const executeUpdateSettingsResult =
await managementCanister.executeUpdateSettings(canisterId);
await managementCanister.executeUpdateSettings(canisterId);

const getCanisterStatusResult =
await managementCanister.getCanisterStatus({
Expand Down Expand Up @@ -75,8 +74,7 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {

const cyclesBefore = statusBefore.cycles;

const depositCyclesResult =
await managementCanister.executeDepositCycles(canisterId);
await managementCanister.executeDepositCycles(canisterId);

const statusAfter = await managementCanister.getCanisterStatus({
canister_id: canisterId
Expand All @@ -95,8 +93,7 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {
const canisterId =
await managementCanister.getCreatedCanisterId();

const executeUninstallCodeResult =
await managementCanister.executeUninstallCode(canisterId);
await managementCanister.executeUninstallCode(canisterId);

const getCanisterStatusResult =
await managementCanister.getCanisterStatus({
Expand All @@ -116,8 +113,7 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {
const canisterId =
await managementCanister.getCreatedCanisterId();

const executeStopCanisterResult =
await managementCanister.executeStopCanister(canisterId);
await managementCanister.executeStopCanister(canisterId);

const getCanisterStatusResult =
await managementCanister.getCanisterStatus({
Expand Down Expand Up @@ -150,8 +146,7 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {
};
}

const executeStartCanisterResult =
await managementCanister.executeStartCanister(canisterId);
await managementCanister.executeStartCanister(canisterId);

const getCanisterStatusAfterResult =
await managementCanister.getCanisterStatus({
Expand Down Expand Up @@ -219,11 +214,9 @@ export function getTests(managementCanister: ActorSubclass<_SERVICE>): Test[] {
const canisterId =
await managementCanister.getCreatedCanisterId();

const executeStopCanisterResult =
await managementCanister.executeStopCanister(canisterId);
await managementCanister.executeStopCanister(canisterId);

const executeDeleteCanisterResult =
await managementCanister.executeDeleteCanister(canisterId);
await managementCanister.executeDeleteCanister(canisterId);

return {
Ok: true
Expand Down
2 changes: 1 addition & 1 deletion examples/motoko_examples/simple-to-do/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ export default Canister({
// );
// ```
// See: https://github.com/demergent-labs/azle/issues/574
todos = new Map([...todos].filter(([key, value]) => !value.completed));
todos = new Map([...todos].filter(([_key, value]) => !value.completed));
})
});
2 changes: 1 addition & 1 deletion examples/notify_raw/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActorSubclass } from '@dfinity/agent';
import { ok, Test } from 'azle/test';
import { Test } from 'azle/test';

import { _SERVICE as CANISTER1_SERVICE } from './dfx_generated/canister1/canister1.did';
import { _SERVICE as CANISTER2_SERVICE } from './dfx_generated/canister2/canister2.did';
Expand Down
6 changes: 2 additions & 4 deletions examples/primitive_types/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export function getTests(
name: 'getEmpty',
test: async () => {
try {
const result = await primitiveTypesCanister.getEmpty();
await primitiveTypesCanister.getEmpty();
} catch (error) {
return {
Ok: (error as any).message.startsWith('Call failed')
Expand All @@ -514,9 +514,7 @@ export function getTests(
name: 'printEmpty',
test: async () => {
try {
const result = await primitiveTypesCanister.printEmpty(
undefined as never
);
await primitiveTypesCanister.printEmpty(undefined as never);
} catch (error) {
return {
Ok: ((error as any).message as string).includes(
Expand Down
16 changes: 12 additions & 4 deletions examples/rejections/src/rejections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,36 @@ export default Canister({
getRejectionCodeDestinationInvalid: update([], RejectionCode, async () => {
try {
await ic.call(nonexistentCanister.method);
} catch (error) {}
} catch (error) {
// continue regardless of error
}

return ic.rejectCode();
}),
getRejectionCodeCanisterReject: update([], RejectionCode, async () => {
try {
await ic.call(someCanister.reject, { args: ['reject'] });
} catch (error) {}
} catch (error) {
// continue regardless of error
}

return ic.rejectCode();
}),
getRejectionCodeCanisterError: update([], RejectionCode, async () => {
try {
await ic.call(someCanister.error);
} catch (error) {}
} catch (error) {
// continue regardless of error
}

return ic.rejectCode();
}),
getRejectionMessage: update([text], text, async (message: text) => {
try {
await ic.call(someCanister.reject, { args: [message] });
} catch (error) {}
} catch (error) {
// continue regardless of error
}

return ic.rejectMessage();
})
Expand Down
Loading
Loading