diff --git a/.eslintrc.json b/.eslintrc.json index 938fd065..55273515 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,10 @@ { "root": true, "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.eslint.json", + "tsconfigRootDir": "./" + }, "env": { "es6": true }, "ignorePatterns": ["node_modules", "build", "coverage", "test", "jest.config.js", "tmp"], "plugins": ["import", "eslint-comments"], diff --git a/src/lib/classes/lsp7-digtal-asset.spec.ts b/src/lib/classes/lsp7-digtal-asset.spec.ts index b8c1c3bc..8814ba0f 100644 --- a/src/lib/classes/lsp7-digtal-asset.spec.ts +++ b/src/lib/classes/lsp7-digtal-asset.spec.ts @@ -1,6 +1,5 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { providers } from 'ethers'; -/// reference types="@nomiclabs/hardhat-ethers/internal/type-extensions.d.ts" /> import { ethers } from 'hardhat'; import { diff --git a/src/lib/lsp-factory.ts b/src/lib/lsp-factory.ts index 5e5aa241..6e5e73bf 100644 --- a/src/lib/lsp-factory.ts +++ b/src/lib/lsp-factory.ts @@ -57,6 +57,8 @@ export class LSPFactory { provider = new ethers.providers.Web3Provider(rpcUrlOrProvider); } else if (typeof rpcUrlOrProvider !== 'string') { provider = rpcUrlOrProvider as providers.Web3Provider | providers.JsonRpcProvider; + } else { + throw new Error('Invalid provider'); } if (!uploadProvider && privateKeyOrSigner && typeof privateKeyOrSigner === 'function') { @@ -80,18 +82,21 @@ export class LSPFactory { signer = provider.getSigner(); } } - const finishInit: Promise = chainId - ? Promise.resolve() - : this.options.provider.getNetwork().then((network) => { - this.options.chainId = network.chainId; - }); this.options = { signer, provider, uploadProvider, chainId, - finishInit, + finishInit: Promise.resolve(), }; + // Must come after because this.options will otherwise be undefined, + // but finishInit needs to have a value before we can create this.options. + // The egg came first. + this.options.finishInit = chainId + ? Promise.resolve() + : this.options.provider.getNetwork().then((network) => { + this.options.chainId = network.chainId; + }); this.UniversalProfile = new UniversalProfile(this.options); this.LSP4DigitalAssetMetadata = new LSP4DigitalAssetMetadata(this.options); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 00000000..ad3176dd --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,48 @@ +{ + "compilerOptions": { + "incremental": true, + "target": "es2020", + "outDir": "build/main", + "rootDir": ".", + "moduleResolution": "node", + "module": "commonjs", + "declaration": true, + "inlineSourceMap": true, + "sourceMap": false, + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, + "resolveJsonModule": true /* Include modules imported with .json extension. */, + + // "strict": true /* Enable all strict type-checking options. */, + + /* Strict Type-Checking Options */ + // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, + // "strictNullChecks": true /* Enable strict null checks. */, + // "strictFunctionTypes": true /* Enable strict checking of function types. */, + // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, + // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, + // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + + /* Additional Checks */ + "noUnusedLocals": false /* Report errors on unused locals. */, + "noUnusedParameters": true /* Report errors on unused parameters. */, + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + + /* Debugging Options */ + "traceResolution": false /* Report module resolution log messages. */, + "listEmittedFiles": false /* Print names of generated files part of the compilation. */, + "listFiles": false /* Print names of files part of the compilation. */, + "pretty": true /* Stylize errors and messages using color and context. */, + + /* Experimental Options */ + // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, + // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, + + "lib": ["es2017", "dom"], + "types": ["node", "jest", "@nomiclabs/hardhat-ethers"], + "typeRoots": ["node_modules/@types", "types"] + }, + "include": ["src/**/*.ts", "types/ethers-v5/**/*.ts"], + "exclude": ["node_modules/**"], + "compileOnSave": false +}