Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Task: Migrate to ESLint #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
coverage
bake-scripts
dist
docs
docconfig
1,022 changes: 543 additions & 479 deletions package-lock.json

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"pretest": "npm run build",
"test": "mocha",
"posttest": "npm run lint",
"lint": "tslint --project tsconfig.json --format stylish",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --fix",
"coverage": "nyc mocha && nyc report --reporter=html && nyc report --reporter=json-summary",
"jsdoc": "jsdoc -c ./docconfig/jsdoc.json"
},
Expand Down Expand Up @@ -46,18 +47,16 @@
"@types/sinon": "^7.0.3",
"babel-eslint": "^10.0.2",
"chai": "^4.1.2",
"eslint": "^6.0.1",
"eslint": "^7.1.0",
"eslint-config-iplayer-base": "^1.0.0",
"eslint-config-iplayer-ts": "^2.0.0",
"express": "^4.16.3",
"jsdoc": "^3.6.3",
"mocha": "^5.2.0",
"nock": "^9.6.1",
"nyc": "^14.1.1",
"sinon": "^7.2.2",
"ts-node": "^3.3.0",
"tslint": "^5.18.0",
"tslint-config-airbnb": "^5.3.1",
"tslint-microsoft-contrib": "^5.0.3",
"typescript": "^2.6.1"
},
"dependencies": {
Expand Down Expand Up @@ -87,5 +86,15 @@
"instrument": true
},
"nodeVersion": ">= 8.0.0",
"prune": false
}
"prune": false,
"eslintConfig": {
"extends": "iplayer-ts",
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-unused-vars": "warn"
}
}
}
2 changes: 1 addition & 1 deletion src/circuitBreaker/circuitBreaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function isFailure(err: any): boolean {
}

function getExecutor(client: RestClient): any {
return function (...args: any[]): any { // tslint:disable-line no-function-expression
return function (...args: any[]): any {
const method = args[0];
const rest = args.slice(1, args.length - 1);
const cb = args[args.length - 1];
Expand Down
28 changes: 21 additions & 7 deletions src/httpTransport/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,27 @@ export function configureClient(params: ClientParams): httpTransport.HttpTranspo
.retryDelay(getRetryDelay(params))
.use(toError());

if (params.rateLimit && params.rateLimitInterval) { builder.use(rateLimit(params.rateLimit, params.rateLimitInterval)); }
if (params.userAgent !== undefined) { builder.userAgent(params.userAgent); }
if (params.collapsing) { configureCollapsing(builder, params); }
if (params.memoryCache) { configureMemoryCache(builder, params); }
if (params.externalCache) { configureExternalCache(builder, params); }
if (params.logger) { builder.use(logger(params.logger)); }
if (params.stats) { builder.use(stats(params.stats, params.name)); }
if (params.rateLimit && params.rateLimitInterval) {
builder.use(rateLimit(params.rateLimit, params.rateLimitInterval));
}
if (params.userAgent !== undefined) {
builder.userAgent(params.userAgent);
}
if (params.collapsing) {
configureCollapsing(builder, params);
}
if (params.memoryCache) {
configureMemoryCache(builder, params);
}
if (params.externalCache) {
configureExternalCache(builder, params);
}
if (params.logger) {
builder.use(logger(params.logger));
}
if (params.stats) {
builder.use(stats(params.stats, params.name));
}

return builder.createClient();
}
16 changes: 9 additions & 7 deletions test/integration/caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as sinon from 'sinon';
import { ClientParams, createClient } from '../../src';
import * as memoryCache from '../../src/caching/memory';

function sleep(ms: number = 200): Promise<void> {
function sleep(ms = 200): Promise<void> {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
Expand All @@ -19,14 +19,14 @@ const sandbox = sinon.createSandbox();

const host = 'http://localhost:5555';
const requestOptions = { headers: { body: { x: 1 } } };
const memoryCacheParams = {
const memoryCacheParams = {
name: 'testing',
memoryCache: {
maxSize: 1000
},
stats: {
increment: sinon.spy(),
timing: () => {}
timing: () => { }
}
};

Expand All @@ -35,7 +35,9 @@ function createStubbedCatbox(): any {
set: sandbox.stub(),
get: sandbox.stub(),
start: sandbox.stub(),
isReady: () => { return true; }
isReady: () => {
return true;
}
};
}

Expand Down Expand Up @@ -81,7 +83,7 @@ describe('Caching integration', () => {

afterEach(() => {
sandbox.restore();
})
});

describe('Memory caching', () => {
it('caches based on max-age', async () => {
Expand Down Expand Up @@ -342,7 +344,7 @@ describe('Caching integration', () => {
sandbox.stub(memoryCache, 'createCache').returns(cache);

nock(host).get('/path').reply(200);

let cacheError = false;
events.on('cache.testingmemory.error', () => {
cacheError = true;
Expand All @@ -367,7 +369,7 @@ describe('Caching integration', () => {
},
stats: {
increment: sinon.spy(),
timing: () => {}
timing: () => { }
}
};

Expand Down
4 changes: 2 additions & 2 deletions test/integration/circuitBreaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createClient } from '../../src';
import { RequestOptions, RestClient } from '../../src/core/restClient';
import { createServer } from './fakeServer';

function sleep(ms: number = 200): Promise<void> {
function sleep(ms = 200): Promise<void> {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
Expand All @@ -15,7 +15,7 @@ const defaultHost = 'http://localhost:5555';
const defaultRequestOpts = { headers: { Status: 500 } };
const defaultParams = { name: 'testing', circuitbreaker: { resetTimeout: 100, maxFailures: 2 } };

function generateFailingCalls(client: RestClient, method: string = 'get', host: string = defaultHost, opts: RequestOptions = defaultRequestOpts): any {
function generateFailingCalls(client: RestClient, method = 'get', host: string = defaultHost, opts: RequestOptions = defaultRequestOpts): any {
return async (times: number) => {
const errors = [];
for (let i = 0; i < times; i++) {
Expand Down
20 changes: 10 additions & 10 deletions test/integration/collapsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { createClient } from '../../src';
const host = 'http://localhost:5555';
const requestOptions = { headers: { body: { x: 1 } } };

function requests(n: any, client: any): Promise<any>[] {
const pending = [];
for (let i = 0; i < n; ++i) {
pending.push(client.get(`${host}/path`));
}
return pending;
}

describe('Request collapsing', () => {
beforeEach(() => {
nock.disableNetConnect();
Expand Down Expand Up @@ -57,7 +65,7 @@ describe('Request collapsing', () => {
},
stats: {
increment: sinon.spy(),
timing: () => {}
timing: () => { }
}
};

Expand All @@ -74,15 +82,7 @@ describe('Request collapsing', () => {

const client = createClient(clientParams);

const requests = (n) => {
const pending = [];
for (let i = 0; i < n; ++i) {
pending.push(client.get(`${host}/path`));
}
return pending;
}

await Promise.all(requests(20));
await Promise.all(requests(20, client));

assert.ok(collapsed);
assert.deepEqual(clientParams.stats.increment.calledWith('testing.collapsing.collapsed'), true);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fakeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ HTTP_METHODS.forEach((method) => {
});
});

export function createServer(cb: () => {}, port: number = 5555): void {
export function createServer(cb: () => {}, port = 5555): void {
return app.listen(port, cb);
}
1 change: 0 additions & 1 deletion test/integration/rateLimiting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe('Rate limiting integration', () => {
const httpMethods = ['get', 'post', 'put', 'patch', 'delete'];
const opts: RequestOptions = { headers: { Status: 200 } };
for (let i = 0; i < rateLimit * 2; i++) {
// tslint:disable-next-line:insecure-random
const httpMethod = httpMethods[Math.floor(Math.random() * httpMethods.length)];
if (httpMethod === 'get' || httpMethod === 'delete') {
await client[httpMethod](defaultHost, opts);
Expand Down
78 changes: 0 additions & 78 deletions tslint.json

This file was deleted.