diff --git a/.eslintrc.json b/.eslintrc.json index 0dfc7ee0..32194ed2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -239,7 +239,7 @@ "error", "always" ], - "object-shorthand": "off", + "object-shorthand": "error", "one-var": [ "error", "never" @@ -263,7 +263,7 @@ "prefer-template": "error", "quote-props": [ "error", - "consistent" + "as-needed" ], "quotes": [ "error", diff --git a/build/copyright.js b/build/copyright.js index ecfa52ef..ffe41c1a 100644 --- a/build/copyright.js +++ b/build/copyright.js @@ -24,7 +24,7 @@ function findCopyright(fileGlobs, opts) { return !fileStr.match(options.pattern); }); - if (files.length) { + if (files.length > 0) { console.log('The following files don\'t match the specified pattern:\n> %s\n', options.pattern); files.forEach((file) => { diff --git a/index.js b/index.js index 764ecbb0..f3c6a8bf 100644 --- a/index.js +++ b/index.js @@ -56,14 +56,14 @@ server.register(inert, () => { path: '/', handler(request, reply) { const browsers = helpers.shuffleArray([ - { 'name': 'Firefox', 'url': 'https://www.mozilla.org/firefox/' }, - { 'name': 'Safari', 'url': 'https://www.apple.com/safari/' }, - { 'name': 'Chrome', 'url': 'https://www.google.com/chrome/browser/desktop/' } + { name: 'Firefox', url: 'https://www.mozilla.org/firefox/' }, + { name: 'Safari', url: 'https://www.apple.com/safari/' }, + { name: 'Chrome', url: 'https://www.google.com/chrome/browser/desktop/' } ]); reply .view('index', { - 'title': 'SRI Hash Generator', - 'browsers': browsers + title: 'SRI Hash Generator', + browsers }) .header('Content-Security-Policy', CSP_HEADER) .header('Referrer-Policy', REFERRER_HEADER); @@ -135,7 +135,7 @@ server.register(inert, () => { request.payload.algorithms, (result) => { reply - .view('hash', { 'hash': result }) + .view('hash', { hash: result }) .header('Content-Security-Policy', CSP_HEADER) .header('Referrer-Policy', REFERRER_HEADER); } diff --git a/lib/helpers.js b/lib/helpers.js index fc31e064..4044a334 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -99,18 +99,18 @@ const eligibility = (response) => { const processResource = (data, response, resourceUrl, cb) => { if (response.statusCode !== 200) { return cb({ - 'success': false, - 'status': response.statusCode + success: false, + status: response.statusCode }); } return cb({ - 'success': true, - 'status': response.statusCode, - 'url': resourceUrl, - 'eligibility': eligibility(response), - 'data': data, - 'ct': response.headers['content-type'] + success: true, + status: response.statusCode, + url: resourceUrl, + eligibility: eligibility(response), + data, + ct: response.headers['content-type'] }); }; @@ -133,7 +133,7 @@ const fetchResource = (resourceUrl, cb) => { const options = { hostname: urlObject.hostname, path: urlObject.path, - headers: { 'Origin': 'https://www.srihash.org/' } + headers: { Origin: 'https://www.srihash.org/' } }; moduleForProtocol(resourceUrl).get(options, (response) => { @@ -217,8 +217,8 @@ const generate = (options, cb) => { fetchResource(options.url, (resource) => { if (!resource) { return cb({ - 'success': false, - 'status': 0 + success: false, + status: 0 }); } if (resource.status !== 200) { @@ -226,22 +226,22 @@ const generate = (options, cb) => { } const sri = sriToolbox.generate({ - 'algorithms': options.algorithms, - 'full': true + algorithms: options.algorithms, + full: true }, resource.data); const contentType = getResourceTypeFromContentTypeHeader(resource.ct); return cb({ - 'success': true, - 'status': resource.status, - 'url': resource.url, - 'type': guessResourceType({ - 'url': resource.url, - 'ct': contentType + success: true, + status: resource.status, + url: resource.url, + type: guessResourceType({ + url: resource.url, + ct: contentType }), - 'integrity': sri.integrity, - 'eligibility': resource.eligibility + integrity: sri.integrity, + eligibility: resource.eligibility }); }); }; @@ -257,8 +257,8 @@ const generate = (options, cb) => { */ const generateElement = (resourceUrl, algorithms, cb) => { const options = { - 'url': resourceUrl, - 'algorithms': algorithms + url: resourceUrl, + algorithms }; generate(options, (resource) => { diff --git a/test/helpers.js b/test/helpers.js index 0ea3220d..813a9687 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -65,7 +65,7 @@ describe('eligibility()', () => { describe('Non-eligible', () => { it('non-CORS', () => { - const nonCORS = { headers: { 'dnt': '1' } }; + const nonCORS = { headers: { dnt: '1' } }; const result = helpers.eligibility(nonCORS); assert.deepEqual(result, ['non-cors']); });