diff --git a/cli.js b/cli.js index f2e438a6..9b4e8329 100755 --- a/cli.js +++ b/cli.js @@ -1,5 +1,7 @@ #!/usr/bin/env node + 'use strict'; + const os = require('os'); const path = require('path'); const chalk = require('chalk'); diff --git a/index.js b/index.js index ea4d603e..6a19bd61 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ 'use strict'; + const path = require('path'); const fs = require('fs-extra'); const assign = require('lodash/assign'); @@ -82,7 +83,7 @@ function prepareOptions(opts) { * @accepts src, base, width, height, dimensions, dest * @return {Promise}|undefined */ -exports.generate = function (opts, cb) { +exports.generate = (opts, cb) => { opts = prepareOptions(opts); // Generate critical css @@ -134,14 +135,14 @@ exports.generate = function (opts, cb) { /** * Deprecated has been removed */ -exports.generateInline = function () { +exports.generateInline = () => { throw new Error('"generateInline" has been removed. Use "generate" with the inline option instead. https://goo.gl/7VbE4b'); }; /** * Deprecated has been removed */ -exports.inline = function () { +exports.inline = () => { throw new Error('"inline" has been removed. Consider using "inline-critical" instead. https://goo.gl/MmTrUZ'); }; @@ -151,7 +152,7 @@ exports.inline = function () { * @param {object} opts * @returns {*} */ -exports.stream = function (opts) { +exports.stream = opts => { // Return stream return through2.obj(function (file, enc, cb) { if (file.isNull()) { diff --git a/lib/core.js b/lib/core.js index 0956638d..12a2810a 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,4 +1,5 @@ 'use strict'; + const os = require('os'); const path = require('path'); const url = require('url'); @@ -52,7 +53,7 @@ function combineCss(cssArray) { * @returns {function} */ function appendStylesheets(opts) { - return function (htmlfile) { + return htmlfile => { // Consider opts.css and map to array if it isn't one if (opts.css) { const css = Array.isArray(opts.css) ? opts.css : [opts.css]; @@ -88,7 +89,7 @@ function appendStylesheets(opts) { * @returns {function} */ function inlineImages(opts) { - return function (vinyl) { + return vinyl => { if (opts.inlineImages) { const assetPaths = opts.assetPaths || []; @@ -100,7 +101,7 @@ function inlineImages(opts) { if (file.isExternal(opts.src)) { // eslint-disable-next-line node/no-deprecated-api const urlObj = url.parse(opts.src); - const domain = urlObj.protocol + '//' + urlObj.host; + const domain = `${urlObj.protocol}//${urlObj.host}`; assetPaths.push(domain, domain + path.dirname(urlObj.pathname)); } @@ -132,7 +133,7 @@ function inlineImages(opts) { * @returns {function} */ function vinylize(opts) { - return function (filepath) { + return filepath => { if (filepath._isVinyl) { return filepath; } @@ -151,7 +152,7 @@ function vinylize(opts) { * @returns {function} */ function processStylesheets(opts) { - return function (htmlfile) { + return htmlfile => { debug('processStylesheets', htmlfile.stylesheets); return Bluebird.map(htmlfile.stylesheets, vinylize(opts)) .map(inlineImages(opts)) @@ -174,8 +175,8 @@ function processStylesheets(opts) { * @returns {function} */ function computeCritical(dimensions, opts) { - return function (htmlfile) { - debug('Processing: ' + htmlfile.path + ' [' + dimensions.width + 'x' + dimensions.height + ']'); + return htmlfile => { + debug(`Processing: ${htmlfile.path} [${dimensions.width}x${dimensions.height}]`); const penthouseOpts = assign({}, opts.penthouse, { url: file.getPenthouseUrl(opts, htmlfile), cssString: htmlfile.cssString, @@ -185,7 +186,7 @@ function computeCritical(dimensions, opts) { }); if (opts.user && opts.pass) { - penthouseOpts.customPageHeaders = {Authorization: 'Basic ' + file.token(opts.user, opts.pass)}; + penthouseOpts.customPageHeaders = {Authorization: `Basic ${file.token(opts.user, opts.pass)}`}; } return penthouse(penthouseOpts); diff --git a/lib/file-helper.js b/lib/file-helper.js index 9c70d4b3..0e9f710e 100644 --- a/lib/file-helper.js +++ b/lib/file-helper.js @@ -1,4 +1,5 @@ 'use strict'; + const os = require('os'); const url = require('url'); const path = require('path'); @@ -41,7 +42,7 @@ function replaceAssetPaths(html, opts) { /** * The resulting function should get passed an vinyl object with the css file */ - return function (stylesheet) { + return stylesheet => { // Normalize relative paths const css = stylesheet.contents.toString().replace(/url\(['"]?([^'"\\)]+)['"]?\)/g, (match, assetPath) => { // Skip absolute paths, urls and data-uris @@ -84,8 +85,8 @@ function getPenthouseUrl(opts, file) { filepath = path.resolve(file.history[0]); } - debug('Fetching local html:', 'file://' + filepath); - return 'file://' + filepath; + debug('Fetching local html:', `file://${filepath}`); + return `file://${filepath}`; } /** @@ -141,7 +142,7 @@ function requestAsync(uri, secure = true, opts = {}) { debug(`Fetching resource: ${resourceUrl}`); const options = {rejectUnauthorized: false, headers: {}}; if (user && pass) { - options.headers.Authorization = 'Basic ' + token(user, pass); + options.headers.Authorization = `Basic ${token(user, pass)}`; } if (userAgent) { @@ -211,7 +212,7 @@ function assertLocal(filePath, opts = {}) { * @returns {function} */ function resourcePath(htmlfile, opts) { - return function (filepath) { + return filepath => { if (isExternal(filepath)) { debug('resourcePath - remote', filepath); return filepath; diff --git a/lib/gc.js b/lib/gc.js index 01447a8a..390b4e3c 100644 --- a/lib/gc.js +++ b/lib/gc.js @@ -1,4 +1,5 @@ 'use strict'; + const fs = require('fs-extra'); const exitHook = require('async-exit-hook'); const _ = require('lodash'); @@ -28,6 +29,6 @@ exitHook(done => cleanup().then(() => done())); process.on('cleanup', cleanup); module.exports.cleanup = cleanup; -module.exports.addFile = function (file) { +module.exports.addFile = file => { files.push(file); }; diff --git a/lib/vinyl-remote.js b/lib/vinyl-remote.js index cab9eb93..91336207 100644 --- a/lib/vinyl-remote.js +++ b/lib/vinyl-remote.js @@ -5,6 +5,7 @@ */ 'use strict'; + const url = require('url'); const File = require('vinyl'); @@ -25,7 +26,7 @@ Object.defineProperty(File.prototype, 'remotePath', { // eslint-disable-next-line node/no-deprecated-api const urlObj = url.parse(remotePath); - remotePath = urlObj.protocol + '//' + urlObj.host + urlObj.pathname; + remotePath = `${urlObj.protocol}//${urlObj.host}${urlObj.pathname}`; // Record history only when path changed if (remotePath && remotePath !== this.remotePath) { diff --git a/package.json b/package.json index 513e99f3..dfe4c235 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,14 @@ "space": 4, "rules": { "valid-jsdoc": "off" - } + }, + "overrides": [ + { + "files": "test/*.js", + "envs": [ + "mocha" + ] + } + ] } } diff --git a/test/00-lib.js b/test/00-lib.js index cdf83a67..bdd14b62 100644 --- a/test/00-lib.js +++ b/test/00-lib.js @@ -1,5 +1,5 @@ -/* eslint-env node, mocha */ 'use strict'; + const path = require('path'); const {assert} = require('chai'); const File = require('vinyl'); @@ -39,7 +39,7 @@ describe('Lib', () => { function mock(p) { return new File({ path: 'fixtures/a/b/file.css', - contents: Buffer.from('url(' + p + ')') + contents: Buffer.from(`url(${p})`) }); } @@ -60,7 +60,7 @@ describe('Lib', () => { function mock(p) { return new File({ path: 'fixtures/a/b/file.css', - contents: Buffer.from('url(' + p + ')') + contents: Buffer.from(`url(${p})`) }); } @@ -82,7 +82,7 @@ describe('Lib', () => { function mock(p) { return new File({ path: 'fixtures/a/b/file.css', - contents: Buffer.from('url(' + p + ')') + contents: Buffer.from(`url(${p})`) }); } @@ -103,7 +103,7 @@ describe('Lib', () => { function mock(p) { return new File({ path: 'fixtures/a/file.css', - contents: Buffer.from('url(' + p + ')') + contents: Buffer.from(`url(${p})`) }); } diff --git a/test/01-module.js b/test/01-module.js index eb2efe90..9e4ab528 100644 --- a/test/01-module.js +++ b/test/01-module.js @@ -1,5 +1,5 @@ -/* eslint-env node, mocha */ 'use strict'; + const {assert} = require('chai'); const critical = require('..'); diff --git a/test/02-generate.js b/test/02-generate.js index cbed3713..d09a9371 100644 --- a/test/02-generate.js +++ b/test/02-generate.js @@ -1,5 +1,5 @@ -/* eslint-env node, mocha */ 'use strict'; + const path = require('path'); const http = require('http'); const fs = require('fs'); diff --git a/test/03-cli.js b/test/03-cli.js index dbd49243..a3bc0617 100644 --- a/test/03-cli.js +++ b/test/03-cli.js @@ -1,5 +1,5 @@ -/* eslint-env node, mocha */ 'use strict'; + const fs = require('fs'); const path = require('path'); const http = require('http'); @@ -216,10 +216,10 @@ describe('CLI', () => { }); mockery.registerMock('.', { - generate: function (opts) { + generate: opts => { this.mockOpts = opts; this.method = 'generate'; - }.bind(this) + } }); }); diff --git a/test/04-streams.js b/test/04-streams.js index 39d81d8e..4ca56a4b 100644 --- a/test/04-streams.js +++ b/test/04-streams.js @@ -1,8 +1,9 @@ /* * Unit tests for Critical. */ -/* eslint-env node, mocha */ + 'use strict'; + const path = require('path'); const fs = require('fs'); const {assert} = require('chai'); diff --git a/test/helper/testhelper.js b/test/helper/testhelper.js index 6b520e6e..85acac57 100644 --- a/test/helper/testhelper.js +++ b/test/helper/testhelper.js @@ -39,7 +39,7 @@ function read(file) { * @returns {Function} */ function assertCritical(target, expected, done, skipTarget) { - return function (err, output) { + return (err, output) => { if (err) { console.log(err); done(err);