eslint rules (#1099)
* Off to the races - 3760 problems (1794 errors, 1966 warnings)
* Convert Array<T> -> T[] (not all correct, eg. extends)
* () => { -> (): void => {
* get is/as -> public get is/as
* public for getters, constructors & base Codec
* Some cleanups from previous overzealous search & replace
* Under 2k, 1874 problems (649 errors, 1225 warnings)
* ^^^ check that commit for details ;)
* Minor.
* rm config header
* Minor cleanups
* Default to tslint, eslint as option
* Trigger
* Update jsonrpc
* 1494 problems (433 errors, 1061 warnings)
* 1103 problems (135 errors, 968 warnings)
* 899 problems (9 errors, 890 warnings)
* 483 problems (9 errors, 474 warnings) (ignore any... for now)
* 366 problems (9 errors, 357 warnings)
* 336 problems (9 errors, 327 warnings)
* 148 problems (9 errors, 139 warnings)
* 31 problems (8 errors, 23 warnings)
* 0, 0
This commit is contained in:
@@ -5,37 +5,39 @@
|
||||
import { TEST_HTTP_URL } from '../../test/mockHttp';
|
||||
import Http from './';
|
||||
|
||||
describe('Http', () => {
|
||||
describe('Http', (): void => {
|
||||
let http: Http;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach((): void => {
|
||||
http = new Http(TEST_HTTP_URL);
|
||||
});
|
||||
|
||||
it('requires an http:// prefixed endpoint', () => {
|
||||
it('requires an http:// prefixed endpoint', (): void => {
|
||||
expect(
|
||||
() => new Http('ws://')
|
||||
(): Http => new Http('ws://')
|
||||
).toThrow(/with 'http/);
|
||||
});
|
||||
|
||||
it('allows https:// endpoints', () => {
|
||||
it('allows https:// endpoints', (): void => {
|
||||
expect(
|
||||
() => new Http('https://')
|
||||
(): Http => new Http('https://')
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('always returns isConnected true', () => {
|
||||
it('always returns isConnected true', (): void => {
|
||||
expect(http.isConnected()).toEqual(true);
|
||||
});
|
||||
|
||||
it('does not (yet) support subscribe', () => {
|
||||
return http.subscribe('', '', [], (cb) => { expect(cb).toEqual(expect.anything()); }).catch((error) => {
|
||||
it('does not (yet) support subscribe', (): Promise<number | void> => {
|
||||
return http.subscribe('', '', [], (cb): void => {
|
||||
expect(cb).toEqual(expect.anything());
|
||||
}).catch((error): void => {
|
||||
expect(error.message).toMatch(/does not have subscriptions/);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not (yet) support unsubscribe', () => {
|
||||
return http.unsubscribe('', '', 0).catch((error) => {
|
||||
it('does not (yet) support unsubscribe', (): Promise<boolean | void> => {
|
||||
return http.unsubscribe('', '', 0).catch((error): void => {
|
||||
expect(error.message).toMatch(/does not have subscriptions/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ProviderInterface, ProviderInterface$Callback, ProviderInterface$Emitted, ProviderInterface$EmitCb } from '../types';
|
||||
import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types';
|
||||
|
||||
import './polyfill';
|
||||
|
||||
@@ -37,12 +37,13 @@ const l = logger('api-http');
|
||||
*/
|
||||
export default class HttpProvider implements ProviderInterface {
|
||||
private coder: Coder;
|
||||
|
||||
private endpoint: string;
|
||||
|
||||
/**
|
||||
* @param {string} endpoint The endpoint url starting with http://
|
||||
*/
|
||||
constructor (endpoint: string = defaults.HTTP_URL) {
|
||||
public constructor (endpoint: string = defaults.HTTP_URL) {
|
||||
assert(/^(https|http):\/\//.test(endpoint), `Endpoint should start with 'http://', received '${endpoint}'`);
|
||||
|
||||
this.coder = new Coder();
|
||||
@@ -52,21 +53,21 @@ export default class HttpProvider implements ProviderInterface {
|
||||
/**
|
||||
* @summary `true` when this provider supports subscriptions
|
||||
*/
|
||||
get hasSubscriptions (): boolean {
|
||||
public get hasSubscriptions (): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a clone of the object
|
||||
*/
|
||||
clone (): HttpProvider {
|
||||
public clone (): HttpProvider {
|
||||
throw new Error('Unimplemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Manually disconnect from the connection
|
||||
*/
|
||||
disconnect (): void {
|
||||
public disconnect (): void {
|
||||
// noop
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ export default class HttpProvider implements ProviderInterface {
|
||||
* @summary Whether the node is connected or not.
|
||||
* @return {boolean} true if connected
|
||||
*/
|
||||
isConnected (): boolean {
|
||||
public isConnected (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,19 +83,20 @@ export default class HttpProvider implements ProviderInterface {
|
||||
* @summary Events are not supported with the HttpProvider, see [[WsProvider]].
|
||||
* @description HTTP Provider does not have 'on' emitters. WebSockets should be used instead.
|
||||
*/
|
||||
on (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): void {
|
||||
l.error(`HTTP Provider does not have 'on' emitters, use WebSockets instead`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Send HTTP POST Request with Body to configured HTTP Endpoint.
|
||||
*/
|
||||
async send (method: string, params: Array<any>): Promise<any> {
|
||||
public async send (method: string, params: any[]): Promise<any> {
|
||||
const body = this.coder.encodeJson(method, params);
|
||||
const response = await fetch(this.endpoint, {
|
||||
body,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'Content-Length': `${body.length}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
@@ -111,7 +113,8 @@ export default class HttpProvider implements ProviderInterface {
|
||||
/**
|
||||
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
||||
*/
|
||||
async subscribe (types: string, method: string, params: Array<any>, cb: ProviderInterface$Callback): Promise<number> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public async subscribe (types: string, method: string, params: any[], cb: ProviderInterfaceCallback): Promise<number> {
|
||||
l.error(ERROR_SUBSCRIBE);
|
||||
|
||||
throw new Error(ERROR_SUBSCRIBE);
|
||||
@@ -120,7 +123,8 @@ export default class HttpProvider implements ProviderInterface {
|
||||
/**
|
||||
* @summary Subscriptions are not supported with the HttpProvider, see [[WsProvider]].
|
||||
*/
|
||||
async unsubscribe (type: string, method: string, id: number): Promise<boolean> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public async unsubscribe (type: string, method: string, id: number): Promise<boolean> {
|
||||
l.error(ERROR_SUBSCRIBE);
|
||||
|
||||
throw new Error(ERROR_SUBSCRIBE);
|
||||
|
||||
@@ -6,26 +6,26 @@ import { Global } from './../mock/types';
|
||||
|
||||
declare const global: Global;
|
||||
|
||||
describe('http/polyfill', () => {
|
||||
describe('http/polyfill', (): void => {
|
||||
let origFetch: GlobalFetch;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach((): void => {
|
||||
origFetch = global.fetch;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach((): void => {
|
||||
global.fetch = origFetch;
|
||||
});
|
||||
|
||||
it('polyfills with no exceptions (without fetch)', () => {
|
||||
it('polyfills with no exceptions (without fetch)', (): void => {
|
||||
(global as any).fetch = undefined;
|
||||
require('./polyfill');
|
||||
|
||||
expect(global.fetch).toBeDefined();
|
||||
});
|
||||
|
||||
it('polyfills with no exceptions (with fetch)', () => {
|
||||
(global as any).fetch = () => true;
|
||||
it('polyfills with no exceptions (with fetch)', (): void => {
|
||||
(global as any).fetch = (): boolean => true;
|
||||
require('./polyfill');
|
||||
|
||||
expect(global.fetch).toBeDefined();
|
||||
|
||||
@@ -6,21 +6,21 @@ import Http from './';
|
||||
import { Mock } from './../mock/types';
|
||||
import { mockHttp, TEST_HTTP_URL } from '../../test/mockHttp';
|
||||
|
||||
describe('send', () => {
|
||||
describe('send', (): void => {
|
||||
let http: Http;
|
||||
let mock: Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach((): void => {
|
||||
http = new Http(TEST_HTTP_URL);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach((): void => {
|
||||
if (mock) {
|
||||
mock.done();
|
||||
}
|
||||
});
|
||||
|
||||
it('passes the body through correctly', () => {
|
||||
it('passes the body through correctly', (): Promise<void> => {
|
||||
mock = mockHttp([{
|
||||
method: 'test_body',
|
||||
reply: {
|
||||
@@ -30,7 +30,7 @@ describe('send', () => {
|
||||
|
||||
return http
|
||||
.send('test_body', ['param'])
|
||||
.then((result) => {
|
||||
.then((): void => {
|
||||
expect((mock.body as any)['test_body']).toEqual({
|
||||
id: 1,
|
||||
jsonrpc: '2.0',
|
||||
@@ -40,7 +40,7 @@ describe('send', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws error when !response.ok', () => {
|
||||
it('throws error when !response.ok', (): Promise<any> => {
|
||||
mock = mockHttp([{
|
||||
code: 500,
|
||||
method: 'test_error'
|
||||
@@ -48,7 +48,7 @@ describe('send', () => {
|
||||
|
||||
return http
|
||||
.send('test_error', [])
|
||||
.catch((error) => {
|
||||
.catch((error): void => {
|
||||
expect(error.message).toMatch(/\[500\]: Internal Server/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,8 +6,8 @@ import { Logger } from '@polkadot/util/types';
|
||||
|
||||
import Coder from '../coder';
|
||||
|
||||
export type HttpState = {
|
||||
coder: Coder,
|
||||
endpoint: string,
|
||||
l: Logger
|
||||
};
|
||||
export interface HttpState {
|
||||
coder: Coder;
|
||||
endpoint: string;
|
||||
l: Logger;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user