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

New eslint #1733

Merged
merged 37 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2f8cad6
Remove old eslintrc
dansteren Nov 27, 2023
d8ee261
Add eslint
dansteren Nov 27, 2023
4cbd1ff
Add eslint to pre-commit hook
dansteren Nov 27, 2023
e08be11
Configure eslint to work with prettier
dansteren Nov 27, 2023
434371c
Tweak eslint config
dansteren Nov 27, 2023
6f125c0
Enable auto-sorting of imports/exports
dansteren Nov 28, 2023
47df101
Add to CI/CD
dansteren Nov 28, 2023
4407c7f
Cache lint results on npm script
dansteren Dec 1, 2023
64a8b9a
Auto fix all file imports with
bdemann Apr 4, 2024
75e86ee
Merge pull request #1734 from demergent-labs/auto_fix_imports
lastmjs Apr 10, 2024
28728d3
Merge branch 'main' into new_eslint
lastmjs Apr 10, 2024
28cc820
fix linting for merge from main
bdemann Apr 10, 2024
93a5470
Remove useless escape characters
dansteren Nov 29, 2023
eccf642
Remove useless try/catch
dansteren Nov 29, 2023
159447d
Correct banned TS types
bdemann Apr 4, 2024
684e05b
update eslintignore
bdemann Apr 4, 2024
d54fb61
Enable no-loss-of-precision and no-namespace
bdemann Apr 4, 2024
10b0141
Enable no-prototype-builtins rule
bdemann Apr 4, 2024
86f4c0c
Enable no-empty rule
bdemann Apr 4, 2024
59b9125
Enable prefer-as-const rule
dansteren Nov 29, 2023
e0e763c
reduce no-unused vars to 26
bdemann Apr 4, 2024
5a10fa6
Resolve 3 no-var-requires problems
bdemann Apr 4, 2024
509b1e6
enable no-var rule
bdemann Apr 4, 2024
35f3dac
Count remaining problems
bdemann Apr 4, 2024
cb71341
Add func-style, array-callback-return, no-template-curly-in-string, a…
bdemann Apr 4, 2024
0294d99
Add prefer template literal rule
bdemann Apr 4, 2024
3f782ed
type fixes
bdemann Apr 5, 2024
e02e1e8
add no-param-reassign, prefer-for-of, prefer-arrow-callback, and no-v…
bdemann Apr 5, 2024
6028abb
pr_fixes
bdemann Apr 10, 2024
fa971dc
Merge pull request #1735 from demergent-labs/new_eslint_fixes
lastmjs Apr 10, 2024
2a21a51
Restore no-unused-vars and no-constant-condition rules
bdemann Apr 10, 2024
69a38f6
Restore no-var-requires rule
bdemann Apr 10, 2024
7b38bea
turn of pref-const
bdemann Apr 10, 2024
801dd16
finishing restoring recommended linting rules
bdemann Apr 10, 2024
008c70c
no-undef should be off because the ts compiler handles it for us
bdemann Apr 10, 2024
1cb7a58
ignore http-message-parser
bdemann Apr 11, 2024
5fd47ad
add info
bdemann Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docs
the_azle_book
type_tests
run_time_errors
**/webpack.config.js
dfx_generate
dfx_generated
declarations
property_tests/tests/**/src/*
dist
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

52 changes: 52 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
env: {
es2021: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
],
overrides: [
{
env: {
node: true
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script'
}
}
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: ['@typescript-eslint', 'simple-import-sort'],
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',
eqeqeq: 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_', // Ignore argument variables starting with _
varsIgnorePattern: '^_' // Ignore local variables starting with _
}
],
'@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
}
};
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ jobs:
git clone https://github.com/demergent-labs/wasmedge-quickjs
cd wasmedge-quickjs
git checkout c21ff69f442998e4cda4619166e23a9bc91418be
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
shell: bash -l {0}
run: npm run lint
- if: ${{ needs.release-candidate-deploy.outputs.should_run_tests }}
working-directory: ${{ matrix.example_directories }}
run: dfx start --clean --background --host 127.0.0.1:8000
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.dfx
.DS_Store
.eslintcache
.vscode/*
!.vscode/extensions.json
dist
Expand Down
3 changes: 2 additions & 1 deletion benchmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { execSync } from 'child_process';
import { create_csv_report } from './csv';
import { writeFileSync } from 'fs';

import { nat64 } from '../src/lib';
import { create_csv_report } from './csv';
import { create_markdown_report } from './markdown';
import { run_setup } from './setup';

Expand Down
2 changes: 1 addition & 1 deletion benchmark/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BenchmarkResult, calculate_average } from './index';
import { get_usd_cost_estimates } from './usd';
import { USDCostEstimates } from './usd/usd_cost_estimate';
import {
USAGE_CONFIG_HEAVY_QUERY_HEAVY,
USAGE_CONFIG_HEAVY_QUERY_UPDATE_EVEN,
Expand All @@ -12,6 +11,7 @@ import {
USAGE_CONFIG_MODERATE_QUERY_UPDATE_EVEN,
USAGE_CONFIG_MODERATE_UPDATE_HEAVY
} from './usd/usage_config';
import { USDCostEstimates } from './usd/usd_cost_estimate';

export function create_markdown_report(
benchmark_results: BenchmarkResult[],
Expand Down
12 changes: 6 additions & 6 deletions benchmark/usd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// TODO make this configurable per day, week, month, year etc? Or is just per year sufficient?

import {
USAGE_CONFIG_LIGHT_QUERY_UPDATE_EVEN,
USAGE_CONFIG_HEAVY_QUERY_HEAVY,
USAGE_CONFIG_HEAVY_QUERY_UPDATE_EVEN,
USAGE_CONFIG_HEAVY_UPDATE_HEAVY,
USAGE_CONFIG_LIGHT_QUERY_HEAVY,
USAGE_CONFIG_LIGHT_QUERY_UPDATE_EVEN,
USAGE_CONFIG_LIGHT_UPDATE_HEAVY,
USAGE_CONFIG_MODERATE_QUERY_UPDATE_EVEN,
USAGE_CONFIG_MODERATE_QUERY_HEAVY,
USAGE_CONFIG_MODERATE_UPDATE_HEAVY,
USAGE_CONFIG_HEAVY_QUERY_UPDATE_EVEN,
USAGE_CONFIG_HEAVY_QUERY_HEAVY,
USAGE_CONFIG_HEAVY_UPDATE_HEAVY
USAGE_CONFIG_MODERATE_QUERY_UPDATE_EVEN,
USAGE_CONFIG_MODERATE_UPDATE_HEAVY
} from './usage_config';
import { get_usd_cost_estimate, USDCostEstimates } from './usd_cost_estimate';

Expand Down
1 change: 1 addition & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('ts-node').register({
transpileOnly: true,
ignore: [`node_modules/(?!azle)`],
Expand Down
7 changes: 3 additions & 4 deletions canisters/icrc/icrc_2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { blob, nat, nat64, Null, Opt, Record, Variant } from '../../src/lib';

import {
BadFee,
BadBurn,
InsufficientFunds,
BadFee,
Duplicate,
GenericError
GenericError,
InsufficientFunds
} from './errors';
import { Account, CreatedInFuture } from './icrc_1';

Expand Down
4 changes: 2 additions & 2 deletions canisters/icrc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import {
nat,
nat8,
Opt,
Record,
query,
update,
Record,
text,
Tuple,
update,
Vec
} from '../../src/lib';
import { Account, TransferArgs, TransferResult, Value } from './icrc_1';
Expand Down
5 changes: 3 additions & 2 deletions canisters/ledger/address/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { blob, Principal } from '../../../src/lib';
import { getCrc32 } from '@dfinity/principal/lib/esm/utils/getCrc';
import { sha224 } from 'js-sha256';

import { blob, Principal } from '../../../src/lib';
import { Address } from '../index';

// TODO we need to review these heavily
Expand Down Expand Up @@ -73,6 +74,6 @@ function to32Bits(number: number): number[] {

function toHexString(byteArray: Uint8Array): string {
return Array.from(byteArray, (byte) => {
return ('0' + (byte & 0xff).toString(16)).slice(-2);
return `0${(byte & 0xff).toString(16)}`.slice(-2);
}).join('');
}
10 changes: 5 additions & 5 deletions canisters/ledger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import {
blob,
Canister,
Func,
nat,
nat8,
nat32,
nat64,
Null,
Opt,
Record,
Principal,
query,
update,
Record,
text,
Tuple,
update,
Variant,
Vec,
Principal,
Func
Vec
} from '../../src/lib';
import * as icrc from '../icrc';

Expand Down
13 changes: 7 additions & 6 deletions canisters/management/canister_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
// Some documentation changed from original work.

import {
Record,
nat8,
nat64,
Null,
Opt,
Vec,
Principal,
Record,
Variant,
nat64,
nat8,
Null
Vec
} from '../../src/lib';
import { managementCanister } from '.';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { managementCanister } from '.'; // Used for links in comments

/** Argument type of {@link managementCanister.canister_info}. */
export const CanisterInfoArgs = Record({
Expand Down
12 changes: 6 additions & 6 deletions canisters/management/canister_management.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
Record,
blob,
nat,
nat64,
Null,
Opt,
Vec,
Principal,
nat,
Record,
Variant,
Null,
blob,
nat64
Vec
} from '../../src/lib';

export const CanisterId = Principal;
Expand Down
14 changes: 7 additions & 7 deletions canisters/management/http_request.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
blob,
Record,
Func,
nat,
nat64,
Null,
Opt,
Vec,
Variant,
Record,
text,
Null,
nat64,
nat,
Func
Variant,
Vec
} from '../../src/lib';

export const HttpHeader = Record({
Expand Down
4 changes: 2 additions & 2 deletions dfx/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
import { HttpAgent } from '@dfinity/agent';
import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
import { execSync } from 'child_process';

export function getCanisterId(canisterName: string): string {
return execSync(
Expand Down
1 change: 1 addition & 0 deletions examples/apollo_server/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { getTests } from './tests';

const canisterId = getCanisterId('apollo_server');
Expand Down
2 changes: 1 addition & 1 deletion examples/async_await/src/async_await.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blob, Canister, ic, serialize, update, Void } from 'azle';
import { blob, Canister, ic, update, Void } from 'azle';
import { managementCanister } from 'azle/canisters/management';

export default Canister({
Expand Down
1 change: 1 addition & 0 deletions examples/async_await/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { createActor } from './dfx_generated/async_await';
import { get_tests } from './tests';

Expand Down
3 changes: 2 additions & 1 deletion examples/async_await/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActorSubclass } from '@dfinity/agent';
import { Test } from 'azle/test';

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

export function get_tests(
async_await_canister: ActorSubclass<_SERVICE>
Expand Down
1 change: 1 addition & 0 deletions examples/audio_and_video/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { getTests } from './tests';

const canisterId = getCanisterId('backend');
Expand Down
2 changes: 1 addition & 1 deletion examples/audio_recorder/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
blob,
Canister,
ic,
Err,
ic,
nat64,
Ok,
Opt,
Expand Down
1 change: 1 addition & 0 deletions examples/audio_recorder/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { createActor } from '../test/dfx_generated/audio_recorder';
import { get_tests } from './tests';

Expand Down
3 changes: 2 additions & 1 deletion examples/audio_recorder/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActorSubclass } from '@dfinity/agent';
import { ok, Test } from 'azle/test';

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

// TODO to be more thorough we could test all of the error cases as well

Expand Down
1 change: 1 addition & 0 deletions examples/autoreload/test/pretest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execSync } from 'child_process';
import { writeFileSync } from 'fs';

import { originalServerTs } from './tests';

async function pretest() {
Expand Down
1 change: 1 addition & 0 deletions examples/autoreload/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getCanisterId } from 'azle/dfx';
import { runTests } from 'azle/test';

import { getTests } from './tests';

const canisterId = getCanisterId('autoreload');
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_bitcoin/src/bitcoin_api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-nocheck

import { blob, ic, match, nat64, Opt, Vec } from 'azle';
import { managementCanister } from 'azle/canisters/management';
import {
BitcoinNetwork,
GetUtxosResult,
MillisatoshiPerByte
} from 'azle/canisters/management/bitcoin';
import { managementCanister } from 'azle/canisters/management';

// The fees for the various bitcoin endpoints.
const GET_BALANCE_COST_CYCLES: nat64 = 100_000_000n;
Expand Down
3 changes: 2 additions & 1 deletion examples/basic_bitcoin/src/bitcoin_wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! * Support for address types that aren't P2PKH.
//! * Caching spent UTXOs so that they are not reused in future transactions.
//! * Option to set the fee.
import { blob, ic, nat64, match, Result, Vec } from 'azle';
import { blob, ic, match, nat64, Result, Vec } from 'azle';
import {
BitcoinNetwork,
MillisatoshiPerByte,
Expand Down Expand Up @@ -137,6 +137,7 @@ async function buildTransaction(
// rebuild the transaction, until the fee is set to the correct amount.
console.log('Building transaction...');
let totalFee = 0n;
// eslint-disable-next-line no-constant-condition
while (true) {
const transaction = match(
buildTransactionWithFee(
Expand Down
Loading
Loading