1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

more strict linting & typing

This commit is contained in:
Matthias Kretschmann 2020-08-19 12:33:51 +02:00
parent 94bc2295f2
commit 9ea7ed70bd
Signed by: m
GPG Key ID: 606EEEF3C479A91F
11 changed files with 27 additions and 42 deletions

View File

@ -20,26 +20,12 @@
], ],
"plugins": ["@typescript-eslint", "prettier"], "plugins": ["@typescript-eslint", "prettier"],
"rules": { "rules": {
"@typescript-eslint/member-delimiter-style": [
"error",
{ "multiline": { "delimiter": "none" } }
],
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": "off", "@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-var-requires": "off", "@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off",
"no-empty": ["error", { "allowEmptyCatch": true }], "no-empty": ["error", { "allowEmptyCatch": true }],
"prefer-destructuring": ["warn"], "prefer-destructuring": ["warn"],
"no-dupe-class-members": ["warn"], "no-dupe-class-members": ["warn"],
"no-useless-constructor": ["warn"], "no-useless-constructor": ["warn"]
"dot-notation": 0
}, },
"env": { "env": {
"es6": true, "es6": true,

View File

@ -29,7 +29,7 @@ export default class ContractHandler extends Instantiable {
this.setInstanceConfig(config) this.setInstanceConfig(config)
} }
public async get(what: string, optional: boolean = false): Promise<Contract> { public async get(what: string, optional = false): Promise<Contract> {
const where = (await this.ocean.network.getNetworkName()).toLowerCase() const where = (await this.ocean.network.getNetworkName()).toLowerCase()
const networkId = await this.ocean.network.getNetworkId() const networkId = await this.ocean.network.getNetworkId()
try { try {

View File

@ -14,7 +14,7 @@ export class EventHandler extends Instantiable {
private interval = 200 private interval = 200
private polling: boolean = false private polling = false
private lastTimeout: NodeJS.Timeout private lastTimeout: NodeJS.Timeout

View File

@ -29,7 +29,7 @@ export class DDO {
return new DDO(ddo) return new DDO(ddo)
} }
public '@context': string = 'https://w3id.org/did/v1' public '@context' = 'https://w3id.org/did/v1'
/** /**
* DID, descentralized ID. * DID, descentralized ID.

View File

@ -365,7 +365,7 @@ export class Assets extends Instantiable {
creator: Account, creator: Account,
cost: string, cost: string,
datePublished: string, datePublished: string,
timeout: number = 0 timeout = 0
): Promise<ServiceAccess> { ): Promise<ServiceAccess> {
return { return {
type: 'access', type: 'access',
@ -387,7 +387,7 @@ export class Assets extends Instantiable {
did: string, did: string,
serviceType: string, serviceType: string,
consumerAddress: string, consumerAddress: string,
serviceIndex: number = -1 serviceIndex = -1
): Promise<string> { ): Promise<string> {
if (serviceIndex === -1) { if (serviceIndex === -1) {
const service = await this.getServiceByType(did, serviceType) const service = await this.getServiceByType(did, serviceType)

View File

@ -126,7 +126,7 @@ export class Provider extends Instantiable {
destination: string, destination: string,
account: Account, account: Account,
files: File[], files: File[],
index: number = -1 index = -1
): Promise<any> { ): Promise<any> {
await this.getNonce(account.getId()) await this.getNonce(account.getId())
const signature = await this.createSignature(account, did + this.nonce) const signature = await this.createSignature(account, did + this.nonce)

View File

@ -3,7 +3,7 @@ import { LoggerInstance } from './Logger'
// Ox transformer // Ox transformer
export const zeroX = (input: string): string => zeroXTransformer(input, true) export const zeroX = (input: string): string => zeroXTransformer(input, true)
export const noZeroX = (input: string): string => zeroXTransformer(input, false) export const noZeroX = (input: string): string => zeroXTransformer(input, false)
export function zeroXTransformer(input: string = '', zeroOutput: boolean): string { export function zeroXTransformer(input = '', zeroOutput: boolean): string {
const { valid, output } = inputMatch(input, /^(?:0x)*([a-f0-9]+)$/i, 'zeroXTransformer') const { valid, output } = inputMatch(input, /^(?:0x)*([a-f0-9]+)$/i, 'zeroXTransformer')
return (zeroOutput && valid ? '0x' : '') + output return (zeroOutput && valid ? '0x' : '') + output
} }
@ -11,7 +11,7 @@ export function zeroXTransformer(input: string = '', zeroOutput: boolean): strin
// did:op: transformer // did:op: transformer
export const didPrefixed = (input: string): string => didTransformer(input, true) export const didPrefixed = (input: string): string => didTransformer(input, true)
export const noDidPrefixed = (input: string): string => didTransformer(input, false) export const noDidPrefixed = (input: string): string => didTransformer(input, false)
export function didTransformer(input: string = '', prefixOutput: boolean): string { export function didTransformer(input = '', prefixOutput: boolean): string {
const { valid, output } = inputMatch( const { valid, output } = inputMatch(
input, input,
/^(?:0x|did:op:)*([a-f0-9]{64})$/i, /^(?:0x|did:op:)*([a-f0-9]{64})$/i,

View File

@ -1,5 +1,5 @@
export class SubscribableObserver<T, P> { export class SubscribableObserver<T, P> {
public completed: boolean = false public completed = false
private subscriptions = new Set<{ private subscriptions = new Set<{
onNext?: (next: T) => void onNext?: (next: T) => void

View File

@ -274,10 +274,10 @@ describe('Compute flow', () => {
assert(order != null) assert(order != null)
const computeOrder = JSON.parse(order) const computeOrder = JSON.parse(order)
const tx = await datatoken.transferWei( const tx = await datatoken.transferWei(
computeOrder['dataToken'], computeOrder.dataToken,
computeOrder['to'], computeOrder.to,
String(computeOrder['numTokens']), String(computeOrder.numTokens),
computeOrder['from'] computeOrder.from
) )
const response = await ocean.compute.start( const response = await ocean.compute.start(
ddo.id, ddo.id,
@ -342,10 +342,10 @@ describe('Compute flow', () => {
) )
const algoOrder = JSON.parse(orderalgo) const algoOrder = JSON.parse(orderalgo)
const algoTx = await datatoken.transferWei( const algoTx = await datatoken.transferWei(
algoOrder['dataToken'], algoOrder.dataToken,
algoOrder['to'], algoOrder.to,
String(algoOrder['numTokens']), String(algoOrder.numTokens),
algoOrder['from'] algoOrder.from
) )
const order = await ocean.compute.order( const order = await ocean.compute.order(
bob.getId(), bob.getId(),
@ -357,10 +357,10 @@ describe('Compute flow', () => {
assert(order != null) assert(order != null)
const computeOrder = JSON.parse(order) const computeOrder = JSON.parse(order)
const tx = await datatoken.transferWei( const tx = await datatoken.transferWei(
computeOrder['dataToken'], computeOrder.dataToken,
computeOrder['to'], computeOrder.to,
String(computeOrder['numTokens']), String(computeOrder.numTokens),
computeOrder['from'] computeOrder.from
) )
const response = await ocean.compute.start( const response = await ocean.compute.start(
ddo.id, ddo.id,

View File

@ -155,13 +155,13 @@ describe('Marketplace flow', () => {
it('Bob consumes asset 1', async () => { it('Bob consumes asset 1', async () => {
await ocean.assets await ocean.assets
.order(ddo.id, accessService.type, bob.getId()) .order(ddo.id, accessService.type, bob.getId())
.then(async (res: string) => { .then(async (res: any) => {
res = JSON.parse(res) res = JSON.parse(res)
return await datatoken.transferWei( return await datatoken.transferWei(
res['dataToken'], res.dataToken,
res['to'], res.to,
String(res['numTokens']), String(res.numTokens),
res['from'] res.from
) )
}) })
.then(async (tx) => { .then(async (tx) => {

View File

@ -8,7 +8,6 @@
"declaration": true, "declaration": true,
"module": "commonjs", "module": "commonjs",
"target": "es5", "target": "es5",
"noImplicitAny": false,
"removeComments": true, "removeComments": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"preserveConstEnums": true, "preserveConstEnums": true,