From 9bb4696c16b35c8042a3fa49764c6dcb8816a18d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 15 Jun 2016 21:40:12 +0200 Subject: [PATCH] fix lint issues with latest XO --- index.js | 12 ++++++++---- test/arguments.js | 6 +++++- test/error.js | 4 ++-- test/headers.js | 22 +++++++++++++++++++--- test/helpers/server.js | 1 + test/http.js | 5 ++++- test/https.js | 7 +++++-- test/post.js | 15 ++++++++++++--- test/redirects.js | 12 +++++++++--- test/retry.js | 26 +++++++++++++++++++------- 10 files changed, 84 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 3c5afa5..ee648e1 100644 --- a/index.js +++ b/index.js @@ -198,7 +198,11 @@ function normalizeArguments(url, opts) { } opts = Object.assign( - {protocol: 'http:', path: '', retries: 5}, + { + protocol: 'http:', + path: '', + retries: 5 + }, url, opts ); @@ -265,7 +269,7 @@ function normalizeArguments(url, opts) { const noise = Math.random() * 100; - return (1 << iter) * 1000 + noise; + return ((1 << iter) * 1000) + noise; }; } @@ -279,8 +283,8 @@ function normalizeArguments(url, opts) { function got(url, opts) { try { return asPromise(normalizeArguments(url, opts)); - } catch (error) { - return Promise.reject(error); + } catch (err) { + return Promise.reject(err); } } diff --git a/test/arguments.js b/test/arguments.js index 1f611ec..6ee1ec4 100644 --- a/test/arguments.js +++ b/test/arguments.js @@ -37,7 +37,11 @@ test('options are optional', async t => { }); test('accepts url.parse object as first argument', async t => { - t.is((await got({hostname: s.host, port: s.port, path: '/test'})).body, '/test'); + t.is((await got({ + hostname: s.host, + port: s.port, + path: '/test' + })).body, '/test'); }); test('overrides querystring from opts', async t => { diff --git a/test/error.js b/test/error.js index ef6ca62..c8ad385 100644 --- a/test/error.js +++ b/test/error.js @@ -22,8 +22,8 @@ test('properties', async t => { } catch (err) { t.truthy(err); t.truthy(err.response); - t.false(err.propertyIsEnumerable('response')); - t.false(err.hasOwnProperty('code')); + t.false({}.propertyIsEnumerable.call(err, 'response')); + t.false({}.hasOwnProperty.call(err, 'code')); t.is(err.message, 'Response code 404 (Not Found)'); t.is(err.host, `${s.host}:${s.port}`); t.is(err.method, 'GET'); diff --git a/test/headers.js b/test/headers.js index c072da1..808f4b7 100644 --- a/test/headers.js +++ b/test/headers.js @@ -30,7 +30,12 @@ test('accept header with json option', async t => { let headers = (await got(s.url, {json: true})).body; t.is(headers.accept, 'application/json'); - headers = (await got(s.url, {headers: {accept: ''}, json: true})).body; + headers = (await got(s.url, { + headers: { + accept: '' + }, + json: true + })).body; t.is(headers.accept, ''); }); @@ -40,12 +45,23 @@ test('host', async t => { }); test('transform names to lowercase', async t => { - const headers = (await got(s.url, {headers: {'USER-AGENT': 'test'}, json: true})).body; + const headers = (await got(s.url, { + headers: { + 'USER-AGENT': 'test' + }, + json: true + })).body; t.is(headers['user-agent'], 'test'); }); test('zero content-length', async t => { - const headers = (await got(s.url, {headers: {'content-length': 0}, body: 'sup', json: true})).body; + const headers = (await got(s.url, { + headers: { + 'content-length': 0 + }, + body: 'sup', + json: true + })).body; t.is(headers['content-length'], '0'); }); diff --git a/test/helpers/server.js b/test/helpers/server.js index 70a6bdc..0a9c1c7 100644 --- a/test/helpers/server.js +++ b/test/helpers/server.js @@ -3,6 +3,7 @@ const http = require('http'); const https = require('https'); const pify = require('pify'); const getPort = require('get-port'); + const host = exports.host = 'localhost'; exports.createServer = function () { diff --git a/test/http.js b/test/http.js index cb6b075..9cc0f29 100644 --- a/test/http.js +++ b/test/http.js @@ -58,7 +58,10 @@ test('buffer on encoding === null', async t => { test('timeout option', async t => { try { - await got(`${s.url}/404`, {timeout: 1, retries: 0}); + await got(`${s.url}/404`, { + timeout: 1, + retries: 0 + }); t.fail('Exception was not thrown'); } catch (err) { t.is(err.code, 'ETIMEDOUT'); diff --git a/test/https.js b/test/https.js index 5d818a7..90e5308 100644 --- a/test/https.js +++ b/test/https.js @@ -10,7 +10,10 @@ let caRootCert; const pemP = pify(pem, Promise); test.before('setup', async () => { - const caKeys = await pemP.createCertificate({days: 1, selfSigned: true}); + const caKeys = await pemP.createCertificate({ + days: 1, + selfSigned: true + }); const caRootKey = caKeys.serviceKey; caRootCert = caKeys.certificate; @@ -31,7 +34,7 @@ test.before('setup', async () => { const key = keys.clientKey; const cert = keys.certificate; - s = await createSSLServer({key, cert}); + s = await createSSLServer({key, cert}); // eslint-disable-line object-property-newline s.on('/', (req, res) => res.end('ok')); diff --git a/test/post.js b/test/post.js index d2cd97a..6293a41 100644 --- a/test/post.js +++ b/test/post.js @@ -51,17 +51,26 @@ test('works with empty post response', async t => { }); test('content-length header with string body', async t => { - const {body} = await got(`${s.url}/headers`, {body: 'wow', json: true}); + const {body} = await got(`${s.url}/headers`, { + body: 'wow', + json: true + }); t.is(body['content-length'], '3'); }); test('content-length header with Buffer body', async t => { - const {body} = await got(`${s.url}/headers`, {body: new Buffer('wow'), json: true}); + const {body} = await got(`${s.url}/headers`, { + body: new Buffer('wow'), + json: true + }); t.is(body['content-length'], '3'); }); test('content-length header with Stream body', async t => { - const {body} = await got(`${s.url}/headers`, {body: intoStream(['wow']), json: true}); + const {body} = await got(`${s.url}/headers`, { + body: intoStream(['wow']), + json: true + }); t.is(body['content-length'], undefined); }); diff --git a/test/redirects.js b/test/redirects.js index 320850d..d12bb24 100644 --- a/test/redirects.js +++ b/test/redirects.js @@ -10,7 +10,10 @@ let https; const pemP = pify(pem, Promise); test.before('setup', async () => { - const caKeys = await pemP.createCertificate({days: 1, selfSigned: true}); + const caKeys = await pemP.createCertificate({ + days: 1, + selfSigned: true + }); const caRootKey = caKeys.serviceKey; const caRootCert = caKeys.certificate; @@ -31,7 +34,7 @@ test.before('setup', async () => { const key = keys.clientKey; const cert = keys.certificate; - https = await createSSLServer({key, cert}); + https = await createSSLServer({key, cert}); // eslint-disable-line object-property-newline https.on('/', (req, res) => { res.end('https'); @@ -108,7 +111,10 @@ test('query in options are not breaking redirects', async t => { }); test('hostname+path in options are not breaking redirects', async t => { - t.is((await got(`${http.url}/relative`, {hostname: http.host, path: '/relative'})).body, 'reached'); + t.is((await got(`${http.url}/relative`, { + hostname: http.host, + path: '/relative' + })).body, 'reached'); }); test('redirect only GET and HEAD requests', async t => { diff --git a/test/retry.js b/test/retry.js index 6d0872c..fa1fbcf 100644 --- a/test/retry.js +++ b/test/retry.js @@ -37,7 +37,10 @@ test('works on timeout error', async t => { test('can be disabled with option', async t => { try { - await got(`${s.url}/try-me`, {timeout: 500, retries: 0}); + await got(`${s.url}/try-me`, { + timeout: 500, + retries: 0 + }); t.fail(); } catch (err) { t.truthy(err); @@ -46,13 +49,19 @@ test('can be disabled with option', async t => { }); test('function gets iter count', async t => { - await got(`${s.url}/fifth`, {timeout: 100, retries: iter => iter < 10}); + await got(`${s.url}/fifth`, { + timeout: 100, + retries: iter => iter < 10 + }); t.is(fifth, 6); }); test('falsy value prevents retries', async t => { try { - await got(`${s.url}/long`, {timeout: 100, retries: () => 0}); + await got(`${s.url}/long`, { + timeout: 100, + retries: () => 0 + }); } catch (err) { t.truthy(err); } @@ -60,10 +69,13 @@ test('falsy value prevents retries', async t => { test('falsy value prevents retries #2', async t => { try { - await got(`${s.url}/long`, {timeout: 100, retries: (iter, err) => { - t.truthy(err); - return false; - }}); + await got(`${s.url}/long`, { + timeout: 100, + retries: (iter, err) => { + t.truthy(err); + return false; + } + }); } catch (err) { t.truthy(err); }