Skip to content

Commit

Permalink
chore: add tslint strict-comparisons and no-implicit-coercion (#78)
Browse files Browse the repository at this point in the history
* chore: add tslint strict-comparisons rule

* fix: tslint:strict-comparisons issues

* chore: update .prettierignore

* fix: only apply tslint rule to src

* fix: audit-ci by bumping async

* refactor config to removed repeated info

* add no implicit conercion linter rule and fix errors

* version bump

* Revert "refactor config to removed repeated info"

This reverts commit 7288a81.

* add lint to test cases and use isDefined util

* Add isdefined utility method

Co-authored-by: fredlacs <[email protected]>
  • Loading branch information
gzeoneth and fredlacs authored Jun 13, 2022
1 parent a5bd104 commit d2a999a
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 23 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
},
overrides: [
{
// this config is run against test files (same as the one bellow but not limited to `src` folder)
files: ['*.ts', '*.tsx'],
parser: '@typescript-eslint/parser',
extends: [
Expand All @@ -45,6 +46,44 @@ module.exports = {
caughtErrorsIgnorePattern: '^_',
},
],
'no-implicit-coercion': 'error',
},
},
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
plugins: ['@typescript-eslint', 'prettier', '@typescript-eslint/tslint'],
rules: {
'no-empty-pattern': 'warn',
'prettier/prettier': ['error', { singleQuote: true }],
'@typescript-eslint/member-delimiter-style': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/no-non-null-assertion': ['off'],
'@typescript-eslint/ban-ts-comment': ['warn'],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/tslint/config': [
'error',
{
rules: { 'strict-comparisons': true },
},
],
'no-implicit-coercion': 'error',
},
},
],
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build/**
cache/**
dist/**
src/lib/abi/**
.nyc_output
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arbitrum/sdk",
"version": "1.1.7",
"version": "1.1.8",
"description": "Typescript library client-side interactions with Arbitrum",
"author": "Offchain Labs, Inc.",
"license": "Apache-2.0",
Expand Down Expand Up @@ -55,15 +55,16 @@
"typechain": "7.0.0"
},
"devDependencies": {
"arb-bridge-eth": "0.7.7",
"arb-bridge-peripherals": "1.0.10",
"arbos-precompiles": "1.0.2",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@types/chai": "^4.2.11",
"@types/mocha": "^9.0.0",
"@types/prompts": "^2.0.14",
"@typescript-eslint/eslint-plugin": "^5.14.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.27.1",
"@typescript-eslint/parser": "^5.14.0",
"arb-bridge-eth": "0.7.7",
"arb-bridge-peripherals": "1.0.10",
"arbos-precompiles": "1.0.2",
"audit-ci": "^5.1.2",
"axios": "^0.21.3",
"chai": "^4.2.0",
Expand All @@ -78,6 +79,7 @@
"prettier": "^2.3.2",
"prettier-plugin-solidity": "^1.0.0-beta.17",
"prompts": "^2.4.2",
"tslint": "^6.1.3",
"typedoc": "^0.21.5",
"typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.2.2",
Expand Down
5 changes: 3 additions & 2 deletions scripts/instantiate_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../src/lib/dataEntities/networks'
import { Signer } from 'ethers'
import { AdminErc20Bridger } from '../src/lib/assetBridger/erc20Bridger'
import { isDefined } from '../src/lib/utils/lib'

dotenv.config()

Expand Down Expand Up @@ -72,8 +73,8 @@ export const instantiateBridge = (

networkID = defaultNetworkId
}
const isL1 = !!l1Networks[networkID]
const isL2 = !!l2Networks[networkID]
const isL1 = isDefined(l1Networks[networkID])
const isL2 = isDefined(l2Networks[networkID])
if (!isL1 && !isL2) {
throw new Error(`Unrecognized network ID: ${networkID}`)
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/dataEntities/signerOrProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Provider } from '@ethersproject/abstract-provider'
import { Signer } from '@ethersproject/abstract-signer'
import { ArbTsError, MissingProviderArbTsError } from '../dataEntities/errors'
import { isDefined } from '../utils/lib'

export type SignerOrProvider = Signer | Provider

Expand Down Expand Up @@ -43,7 +44,7 @@ export class SignerProviderUtils {
public static signerHasProvider(
signer: Signer
): signer is Signer & { provider: Provider } {
return !!signer.provider
return isDefined(signer.provider)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/lib/message/L2Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
L2ToL1MessageWriter,
} from './L2ToL1Message'
import { getRawArbTransactionReceipt } from '../..'
import { isDefined } from '../utils/lib'

export interface L2ContractTransaction extends ContractTransaction {
wait(confirmations?: number): Promise<L2TransactionReceipt>
Expand Down Expand Up @@ -136,7 +137,7 @@ export class L2TransactionReceipt implements TransactionReceipt {

// Data is made available in batches, if the batch info is
// available then so is the tx data
return !!arbReceipt?.l1InboxBatchInfo
return isDefined(arbReceipt?.l1InboxBatchInfo)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils/arbProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ const getBatch = async (

// find the batch containing the seq number
const batch = events.filter(
b => b.event.firstMessageNum <= seqNum && b.event.newMessageCount > seqNum
b =>
b.event.firstMessageNum.lte(seqNum) && b.event.newMessageCount.gt(seqNum)
)[0]

if (!batch) return null
Expand Down
2 changes: 1 addition & 1 deletion src/lib/utils/byte_serialize_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const formatPrimative = (value: PrimativeType) => {
return toUint(value ? 1 : 0, 1)
} else if (
typeof value === 'number' ||
+value ||
Number(value) ||
BigNumber.isBigNumber(value)
) {
return toUint(value, 32)
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils/lib.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const wait = (ms: number): Promise<void> =>
new Promise(res => setTimeout(res, ms))

export const isDefined = (val: unknown): boolean =>
typeof val !== 'undefined' && val !== null
Loading

0 comments on commit d2a999a

Please sign in to comment.