Skip to content

Commit

Permalink
Update linter setup
Browse files Browse the repository at this point in the history
  • Loading branch information
krzkaczor committed Jul 3, 2021
1 parent 5e2234d commit 5f351fc
Show file tree
Hide file tree
Showing 64 changed files with 539 additions and 484 deletions.
69 changes: 5 additions & 64 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ module.exports = {
es6: true,
},
extends: ['typestrict'],
plugins: ['no-only-tests', 'import'],
plugins: ['no-only-tests', 'simple-import-sort', 'unused-imports', 'import'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
},
rules: {
//: "this gets inlined into a package eslint, so it means: use current package's package.info or the one at the project root"
// this gets inlined into a package eslint, so it means: use current package's package.info or the one at the project root
'import/no-extraneous-dependencies': ['error', { packageDir: ['./', '../../'] }],
'@typescript-eslint/no-unused-vars': ['off'],
'unused-imports/no-unused-imports-ts': 'error',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'accessor-pairs': 'error',
Expand Down Expand Up @@ -53,7 +55,6 @@ module.exports = {
'no-extra-bind': 'error',
'no-extra-boolean-cast': 'error',
'no-extra-parens': ['error', 'functions'],
'no-fallthrough': 'error',
'no-floating-decimal': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
Expand All @@ -71,25 +72,7 @@ module.exports = {
],
'no-lone-blocks': 'error',
'no-misleading-character-class': 'error',
'no-mixed-operators': [
'error',
{
allowSamePrecedence: true,
groups: [
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||'],
['in', 'instanceof'],
],
},
],
'no-multi-str': 'error',
'no-multiple-empty-lines': [
'error',
{
max: 1,
maxEOF: 0,
},
],
'no-negated-in-lhs': 'error',
'no-new': 'error',
'no-new-func': 'error',
Expand All @@ -102,7 +85,6 @@ module.exports = {
'no-octal-escape': 'error',
'no-path-concat': 'error',
'no-proto': 'error',
'no-prototype-builtins': 'error',
'no-redeclare': [
'error',
{
Expand Down Expand Up @@ -139,37 +121,12 @@ module.exports = {
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-with': 'error',
'object-curly-spacing': ['error', 'always'],
'object-property-newline': [
'error',
{
allowMultiplePropertiesPerLine: true,
},
],
'one-var': [
'error',
{
initialized: 'never',
},
],
'operator-linebreak': [
'error',
'after',
{
overrides: {
':': 'before',
'?': 'before',
},
},
],
'padded-blocks': [
'error',
{
blocks: 'never',
classes: 'never',
switches: 'never',
},
],
'prefer-const': [
'error',
{
Expand All @@ -178,30 +135,14 @@ module.exports = {
],
'prefer-promise-reject-errors': 'error',
'symbol-description': 'error',
'unicode-bom': ['error', 'never'],
'use-isnan': 'error',
'valid-typeof': [
'error',
{
requireStringLiterals: true,
},
],
'wrap-iife': [
'error',
'any',
{
functionPrototypeMethods: true,
},
],
yoda: ['error', 'never'],
'no-only-tests/no-only-tests': 'error',
},
overrides: [
{
files: ['test/**/*.{js,ts,tsx}'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
"@typescript-eslint/eslint-plugin": "4.15.1",
"@typescript-eslint/parser": "4.15.1",
"earljs": "^0.1.10",
"eslint": "^6.8.0",
"eslint-config-typestrict": "^1.0.0",
"eslint": "^7.29.0",
"eslint-config-typestrict": "^1.0.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-sonarjs": "^0.5.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonarjs": "^0.8.0-125",
"eslint-plugin-unused-imports": "^1.1.1",
"mocha": "^8.2.0",
"prettier": "^2.1.2",
"solc": "^0.6.4",
Expand Down
9 changes: 5 additions & 4 deletions packages/hardhat/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import './type-extensions'

import fsExtra from 'fs-extra'
import { TASK_CLEAN, TASK_COMPILE, TASK_COMPILE_SOLIDITY_COMPILE_JOBS } from 'hardhat/builtin-tasks/task-names'
import { extendConfig, task, subtask } from 'hardhat/config'
import { extendConfig, subtask, task } from 'hardhat/config'
import { getFullyQualifiedName } from 'hardhat/utils/contract-names'
import _, { uniq } from 'lodash'
import { runTypeChain, glob } from 'typechain'
import { glob, runTypeChain } from 'typechain'

import { getDefaultTypechainConfig } from './config'
import { TASK_TYPECHAIN } from './constants'
import './type-extensions'

const taskArgsStore: { noTypechain: boolean; fullRebuild: boolean } = { noTypechain: false, fullRebuild: false }

Expand All @@ -17,7 +18,7 @@ extendConfig((config) => {

task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
.addFlag('noTypechain', 'Skip Typechain compilation')
.setAction(async ({ noTypechain }: { global: boolean; noTypechain: boolean }, { config }, runSuper) => {
.setAction(async ({ noTypechain }: { global: boolean; noTypechain: boolean }, _, runSuper) => {
// just save task arguments for later b/c there is no easier way to access them in subtask
taskArgsStore.noTypechain = noTypechain!!

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// We load the plugin here.
import { HardhatUserConfig } from 'hardhat/types'

import '../../../src/index'

import { HardhatUserConfig } from 'hardhat/types'

const config: HardhatUserConfig = {
solidity: '0.7.3',
defaultNetwork: 'hardhat',
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/test/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-invalid-this */
import { expect, Mock, mockFn } from 'earljs'
import { copyFileSync, existsSync, promises as fsPromises, readFileSync } from 'fs'
import { join } from 'path'
import { existsSync, promises as fsPromises, copyFileSync, readFileSync } from 'fs'
import rimraf from 'rimraf'

import { useEnvironment } from './helpers'
import rimraf from 'rimraf'

describe('Typechain x Hardhat', function () {
this.timeout(120_000)
Expand Down
8 changes: 5 additions & 3 deletions packages/target-ethers-v4-test/test/DataTypesInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { typedAssert, q18, IsExact, AssertTrue } from 'test-utils'
import { expect } from 'earljs'
import { BigNumber, formatBytes32String } from 'ethers/utils'
import { AssertTrue, IsExact, q18, typedAssert } from 'test-utils'
import { Awaited } from 'ts-essentials'
import { expect } from 'earljs'

import { createNewBlockchain, deployContract } from './common'
import { DataTypesInput } from '../types/DataTypesInput'
import { createNewBlockchain, deployContract } from './common'

describe('DataTypesInput', () => {
let contract!: DataTypesInput
Expand Down Expand Up @@ -77,11 +77,13 @@ describe('DataTypesInput', () => {
// NOTE: typesAssert is too simple to tests type compatibility here so we can't use it
it('generates correct types for tuples', () => {
type ViewTupleType = Awaited<ReturnType<typeof contract.input_tuple>>
//eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<IsExact<ViewTupleType, [BigNumber, BigNumber]>>
})

it('generates correct types for structs', () => {
type ViewStructType = Awaited<ReturnType<typeof contract.input_struct>>
//eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<
IsExact<ViewStructType, [BigNumber, BigNumber] & { uint256_0: BigNumber; uint256_1: BigNumber }>
>
Expand Down
4 changes: 2 additions & 2 deletions packages/target-ethers-v4-test/test/Overload.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigNumber } from 'ethers/utils'
import { typedAssert } from 'test-utils'

import { createNewBlockchain, deployContract } from './common'
import { Overloads } from '../types/Overloads'
import { BigNumber } from 'ethers/utils'
import { createNewBlockchain, deployContract } from './common'

describe('Overloads', () => {
let contract: Overloads
Expand Down
2 changes: 1 addition & 1 deletion packages/target-ethers-v4-test/test/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcProvider } from 'ethers/providers'
import { ethers } from 'ethers'
import { JsonRpcProvider } from 'ethers/providers'
import { loadContract } from 'test-utils'

const ganache = require('ganache-cli')
Expand Down
1 change: 1 addition & 0 deletions packages/target-ethers-v4/src/codegen/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FunctionDeclaration, FunctionDocumentation, getSignatureForFn } from 'typechain'

import { generateInputTypes, generateOutputTypes } from './types'

interface GenerateFunctionOptions {
Expand Down
12 changes: 7 additions & 5 deletions packages/target-ethers-v4/src/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
EventDeclaration,
FunctionDeclaration,
} from 'typechain'
import { generateInputType, generateInputTypes } from './types'
import { codegenFunctions } from './functions'

import { FACTORY_POSTFIX } from '../common'
import { codegenFunctions } from './functions'
import { reservedKeywords } from './reserved-keywords'
import { generateInputType, generateInputTypes } from './types'

export function codegenContractTypings(contract: Contract) {
const template = `
Expand Down Expand Up @@ -76,10 +77,11 @@ export function codegenContractTypings(contract: Contract) {

export function codegenContractFactory(contract: Contract, abi: any, bytecode?: BytecodeWithLinkReferences): string {
const constructorArgs =
(contract.constructor && contract.constructor[0] ? generateInputTypes(contract.constructor[0].inputs) : '') +
(contract.constructor[0] ? generateInputTypes(contract.constructor[0].inputs) : '') +
'overrides?: TransactionOverrides'
const constructorArgNamesWithoutOverrides =
contract.constructor && contract.constructor[0] ? generateParamNames(contract.constructor[0].inputs) : ''
const constructorArgNamesWithoutOverrides = contract.constructor[0]
? generateParamNames(contract.constructor[0].inputs)
: ''
const constructorArgNames = constructorArgNamesWithoutOverrides
? `${constructorArgNamesWithoutOverrides}, overrides`
: 'overrides'
Expand Down
2 changes: 1 addition & 1 deletion packages/target-ethers-v4/src/codegen/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvmType, EvmOutputType, TupleType, AbiParameter, AbiOutputParameter } from 'typechain'
import { AbiOutputParameter, AbiParameter, EvmOutputType, EvmType, TupleType } from 'typechain'

export function generateInputTypes(input: Array<AbiParameter>): string {
if (input.length === 0) {
Expand Down
19 changes: 11 additions & 8 deletions packages/target-ethers-v4/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join, resolve } from 'path'
import { readFileSync } from 'fs'
import { join, resolve } from 'path'
import { Dictionary } from 'ts-essentials'
import {
BytecodeWithLinkReferences,
Expand Down Expand Up @@ -28,11 +28,14 @@ export default class Ethers extends TypeChainTarget {
name = 'Ethers'

private readonly outDirAbs: string
private readonly contractCache: Dictionary<{
abi: any
contract: Contract
}> = {}
private readonly bytecodeCache: Dictionary<BytecodeWithLinkReferences> = {}
private readonly contractCache: Dictionary<
| {
abi: any
contract: Contract
}
| undefined
> = {}
private readonly bytecodeCache: Dictionary<BytecodeWithLinkReferences | undefined> = {}

constructor(config: Config) {
super(config)
Expand Down Expand Up @@ -68,7 +71,7 @@ export default class Ethers extends TypeChainTarget {
}

if (this.contractCache[name]) {
const { contract, abi } = this.contractCache[name]
const { contract, abi } = this.contractCache[name]!
delete this.contractCache[name]
return [this.genContractFactoryFile(contract, abi, bytecode)]
} else {
Expand Down Expand Up @@ -114,7 +117,7 @@ export default class Ethers extends TypeChainTarget {
// For each contract that doesn't have bytecode (it's either abstract, or only ABI was provided)
// generate a simplified factory, that allows to interact with deployed contract instances.
const abstractFactoryFiles = Object.keys(this.contractCache).map((contractName) => {
const { contract, abi } = this.contractCache[contractName]
const { contract, abi } = this.contractCache[contractName]!
return {
path: join(this.outDirAbs, 'factories', `${contract.name}${FACTORY_POSTFIX}.ts`),
contents: codegenAbstractContractFactory(contract, abi),
Expand Down
16 changes: 9 additions & 7 deletions packages/target-ethers-v5-test/test/DataTypesInput.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { typedAssert, q18, AssertTrue, IsExact } from 'test-utils'
import { ethers, BigNumber } from 'ethers'
import { expect } from 'earljs'
import { Awaited } from 'earljs/dist/mocks/types'
import { BigNumber, ethers } from 'ethers'
import { AssertTrue, IsExact, q18, typedAssert } from 'test-utils'

import { createNewBlockchain, deployContract } from './common'
import { DataTypesInput } from '../types/DataTypesInput'
import { Awaited } from 'earljs/dist/mocks/types'
import { expect } from 'earljs'
import { createNewBlockchain, deployContract } from './common'

describe('DataTypesInput', () => {
let contract!: DataTypesInput
Expand Down Expand Up @@ -80,12 +80,14 @@ describe('DataTypesInput', () => {
// NOTE: typesAssert is too simple to tests type compatibility here so we can't use it
it('generates correct types for tuples', () => {
type ViewTupleType = Awaited<ReturnType<typeof contract.input_tuple>>
type t1 = AssertTrue<IsExact<ViewTupleType, [BigNumber, BigNumber]>>
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<IsExact<ViewTupleType, [BigNumber, BigNumber]>>
})

it('generates correct types for structs', () => {
type ViewStructType = Awaited<ReturnType<typeof contract.input_struct>>
type t1 = AssertTrue<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type _t1 = AssertTrue<
IsExact<ViewStructType, [BigNumber, BigNumber] & { uint256_0: BigNumber; uint256_1: BigNumber }>
>
})
Expand Down
8 changes: 4 additions & 4 deletions packages/target-ethers-v5-test/test/Events.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BigNumber, ethers } from 'ethers'
import { typedAssert } from 'test-utils'
import { ethers, BigNumber } from 'ethers'

import { createNewBlockchain, deployContract } from './common'
import { Events } from '../types/Events'
import { createNewBlockchain, deployContract } from './common'

describe('Events', () => {
let contract!: Events
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('Events', () => {

it('contract.on', async () => {
const filter = contract.filters.Event1(null, null)
const results = await contract.queryFilter(filter)
await contract.queryFilter(filter)

contract.on(filter, (a, b, c) => {
typedAssert(a, BigNumber.from(1))
Expand All @@ -67,7 +67,7 @@ describe('Events', () => {

it('contract.once', async () => {
const filter = contract.filters.Event1(null, null)
const results = await contract.queryFilter(filter)
await contract.queryFilter(filter)

contract.once(filter, (a, b, c) => {
typedAssert(a, BigNumber.from(1))
Expand Down
Loading

0 comments on commit 5f351fc

Please sign in to comment.