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

chore: set up eslint-plugin-simple-import-sort and eslint-plugin-import #2086

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
41 changes: 38 additions & 3 deletions config/eslint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'implicit-dependencies', 'import', 'prettier'],
plugins: [
'@typescript-eslint',
'implicit-dependencies',
'import',
'prettier',
'simple-import-sort',
],
env: {
es2020: true,
node: true,
Expand All @@ -13,7 +19,12 @@ module.exports = {
'typedoc.js',
'karma.conf.js',
],
extends: ['typestrict', 'eslint:recommended'],
extends: [
'typestrict',
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
rules: {
'no-console': 'warn',
'no-debugger': 'error',
Expand Down Expand Up @@ -46,7 +57,31 @@ module.exports = {
'@typescript-eslint/no-redeclare': ['error'],
'@typescript-eslint/restrict-plus-operands': 'off',
'import/no-default-export' : ['error'],
'@typescript-eslint/strict-boolean-expressions': ['error']
'@typescript-eslint/strict-boolean-expressions': ['error'],
'simple-import-sort/exports': 'error',
'import/default': 'error',
'import/export': 'error',
'import/exports-last': 'off', // TODO: set to `warn` for fixing and then `error`
'import/extensions': 'off',
'import/first': 'error',
'import/group-exports': 'off',
'import/named': 'error',
'import/namespace': 'error',
'import/no-absolute-path': 'error',
'import/no-anonymous-default-export': 'error',
'import/no-cycle': 'off', // TODO: set to `warn` for fixing and then `error`
'import/no-deprecated': 'off', // TODO: set to `warn` for fixing and then `error`
'import/no-duplicates': 'error',
'import/no-dynamic-require': 'off',
'import/no-extraneous-dependencies': 'error',
'import/no-mutable-exports': 'error',
'import/no-namespace': 'off',
'import/no-self-import': 'error',
'import/no-unresolved': 'off',
'import/no-unused-modules': 'error',
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',
'import/order': 'error',
},
parserOptions: {
sourceType: 'module',
Expand Down
27 changes: 21 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"eslint-plugin-implicit-dependencies": "^1.0.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.5.0",
"husky": "^4.2.5",
"nyc-report-lcov-absolute": "^1.0.0",
Expand Down
19 changes: 10 additions & 9 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Trie } from '@ethereumjs/trie'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { arrToBufArr, bufArrToArr, KECCAK256_RLP, bufferToHex, isTruthy } from '@ethereumjs/util'
import { RLP } from 'rlp'
import { Common, ConsensusType } from '@ethereumjs/common'
import { Trie } from '@ethereumjs/trie'
import {
TransactionFactory,
TypedTransaction,
TxOptions,
Capability,
FeeMarketEIP1559Transaction,
Transaction,
Capability,
TransactionFactory,
TxOptions,
TypedTransaction,
} from '@ethereumjs/tx'
import { arrToBufArr, bufArrToArr, bufferToHex, isTruthy, KECCAK256_RLP } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { RLP } from 'rlp'

import { BlockHeader } from './header'
import { BlockData, BlockOptions, JsonBlock, BlockBuffer } from './types'
import { BlockBuffer, BlockData, BlockOptions, JsonBlock } from './types'

/**
* An object that represents the block.
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/from-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TransactionFactory, TypedTransaction, TxData } from '@ethereumjs/tx'
import { toBuffer, setLengthLeft, isTruthy } from '@ethereumjs/util'
import { Block, BlockOptions } from './index'
import { numberToHex } from './helpers'
import { TransactionFactory, TxData, TypedTransaction } from '@ethereumjs/tx'
import { isTruthy, setLengthLeft, toBuffer } from '@ethereumjs/util'

import { blockHeaderFromRpc } from './header-from-rpc'
import { numberToHex } from './helpers'
import { Block, BlockOptions } from './index'

function normalizeTxParams(_txParams: any) {
const txParams = Object.assign({}, _txParams)
Expand Down
5 changes: 3 additions & 2 deletions packages/block/src/header-from-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { isTruthy } from '@ethereumjs/util'

import { BlockHeader } from './header'
import { BlockOptions } from './types'
import { numberToHex } from './helpers'
import { isTruthy } from '@ethereumjs/util'
import { BlockOptions } from './types'

/**
* Creates a new block header object from Ethereum JSON RPC.
Expand Down
13 changes: 7 additions & 6 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
Chain,
CliqueConfig,
Common,
ConsensusAlgorithm,
ConsensusType,
Hardfork,
CliqueConfig,
} from '@ethereumjs/common'
import { keccak256 } from 'ethereum-cryptography/keccak'
import {
Address,
arrToBufArr,
Expand All @@ -18,17 +17,19 @@ import {
bufferToHex,
ecrecover,
ecsign,
KECCAK256_RLP_ARRAY,
isFalsy,
isTruthy,
KECCAK256_RLP,
KECCAK256_RLP_ARRAY,
toType,
TypeOutput,
zeros,
isTruthy,
isFalsy,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { RLP } from 'rlp'

import { CLIQUE_EXTRA_SEAL, CLIQUE_EXTRA_VANITY } from './clique'
import { BlockHeaderBuffer, BlockOptions, HeaderData, JsonHeader } from './types'
import { CLIQUE_EXTRA_VANITY, CLIQUE_EXTRA_SEAL } from './clique'

interface HeaderCache {
hash: Buffer | undefined
Expand Down
5 changes: 3 additions & 2 deletions packages/block/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AddressLike, BigIntLike, BufferLike } from '@ethereumjs/util'
import { Common } from '@ethereumjs/common'
import { TxData, JsonTx, AccessListEIP2930TxData, FeeMarketEIP1559TxData } from '@ethereumjs/tx'
import { AccessListEIP2930TxData, FeeMarketEIP1559TxData, JsonTx, TxData } from '@ethereumjs/tx'
import { AddressLike, BigIntLike, BufferLike } from '@ethereumjs/util'

import { BlockHeader } from './header'

/**
Expand Down
17 changes: 9 additions & 8 deletions packages/block/test/block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import * as tape from 'tape'
// explicitly import util, needed for karma-typescript bundling
// eslint-disable-next-line @typescript-eslint/no-unused-vars, simple-import-sort/imports
import util from 'util'

import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { NestedUint8Array, toBuffer, zeros } from '@ethereumjs/util'
import { RLP } from 'rlp'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import * as tape from 'tape'

import { Block, BlockBuffer } from '../src'
import { blockFromRpc } from '../src/from-rpc'
import * as testnetMerge from './testdata/testnetMerge.json'
import * as testDataGenesis from './testdata/genesishashestest.json'
import * as testDataPreLondon from './testdata/testdata_pre-london.json'
import * as testDataPreLondon2 from './testdata/testdata_pre-london-2.json'
import * as testDataGenesis from './testdata/genesishashestest.json'
import * as testDataFromRpcGoerli from './testdata/testdata-from-rpc-goerli.json'

// explicitly import util, needed for karma-typescript bundling
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import util from 'util'
import * as testnetMerge from './testdata/testnetMerge.json'

tape('[Block]: block functions', function (t) {
t.test('should test block initialization', function (st) {
Expand Down
5 changes: 3 additions & 2 deletions packages/block/test/clique.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as tape from 'tape'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Address } from '@ethereumjs/util'
import * as tape from 'tape'

import { BlockHeader } from '../src/header'

tape('[Header]: Clique PoA Functionality', function (t) {
const common = new Common({ chain: Chain.Rinkeby, hardfork: Hardfork.Chainstart })
Expand Down
3 changes: 2 additions & 1 deletion packages/block/test/difficulty.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as tape from 'tape'
import { Chain, Common } from '@ethereumjs/common'
import { bufferToInt } from '@ethereumjs/util'
import * as tape from 'tape'

import { Block } from '../src'

function runDifficultyTests(
Expand Down
7 changes: 4 additions & 3 deletions packages/block/test/eip1559block.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as tape from 'tape'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Block } from '../src/block'
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx'
import * as tape from 'tape'

import { Block } from '../src/block'
import { BlockHeader } from '../src/header'

// Test data from Besu (retrieved via Discord)
// Older version at https://github.com/abdelhamidbakhta/besu/blob/bf54b6c0b40d3015fc85ff9b078fbc26592d80c0/ethereum/core/src/test/resources/org/hyperledger/besu/ethereum/core/fees/basefee-test.json
Expand Down
5 changes: 3 additions & 2 deletions packages/block/test/from-rpc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as tape from 'tape'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Transaction } from '@ethereumjs/tx'
import * as tape from 'tape'

import { blockFromRpc } from '../src/from-rpc'
import { blockHeaderFromRpc } from '../src/header-from-rpc'
import * as blockData from './testdata/testdata-from-rpc.json'
import * as blockDataDifficultyAsInteger from './testdata/testdata-from-rpc-difficulty-as-integer.json'
import * as testDataFromRpcGoerliLondon from './testdata/testdata-from-rpc-goerli-london.json'
import * as blockDataWithUncles from './testdata/testdata-from-rpc-with-uncles.json'
import * as uncleBlockData from './testdata/testdata-from-rpc-with-uncles_uncle-block-data.json'
import * as testDataFromRpcGoerliLondon from './testdata/testdata-from-rpc-goerli-london.json'

tape('[fromRPC]: block #2924874', function (t) {
const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul })
Expand Down
9 changes: 5 additions & 4 deletions packages/block/test/header.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as tape from 'tape'
import { Address, toBuffer, zeros, KECCAK256_RLP, KECCAK256_RLP_ARRAY } from '@ethereumjs/util'
import { Chain, CliqueConfig, Common, Hardfork } from '@ethereumjs/common'
import { Address, KECCAK256_RLP, KECCAK256_RLP_ARRAY, toBuffer, zeros } from '@ethereumjs/util'
import { RLP } from 'rlp'
import { Chain, Common, CliqueConfig, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import * as tape from 'tape'

import { Block } from '../src'
import { BlockHeader } from '../src/header'
const blocksMainnet = require('./testdata/blocks_mainnet.json')
const blocksGoerli = require('./testdata/blocks_goerli.json')

Expand Down
5 changes: 3 additions & 2 deletions packages/block/test/mergeBlock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as tape from 'tape'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { BlockHeader } from '../src/header'
import { Address, KECCAK256_RLP, KECCAK256_RLP_ARRAY, zeros } from '@ethereumjs/util'
import * as tape from 'tape'

import { Block } from '../src/block'
import { BlockHeader } from '../src/header'

const common = new Common({
chain: Chain.Mainnet,
Expand Down
3 changes: 2 additions & 1 deletion packages/block/test/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { bufArrToArr, isTruthy } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { RLP } from 'rlp'

import { Block, BlockHeader } from '../src'

/**
Expand Down
Loading