diff --git a/.eslintrc.js b/.eslintrc.js index 987af7e911..69b6b59125 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,7 +22,14 @@ module.exports = { // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // do not allow console.logs etc... - 'no-console': 2 + 'no-console': 2, + 'space-before-function-paren': [ + 2, + { + anonymous: 'always', + named: 'never' + } + ], }, globals: {} } diff --git a/lib/builder/webpack/base.config.js b/lib/builder/webpack/base.config.js index 7e1d3c5b0d..e9546072e3 100644 --- a/lib/builder/webpack/base.config.js +++ b/lib/builder/webpack/base.config.js @@ -12,7 +12,7 @@ import { isUrl, urlJoin } from 'utils' | webpack config files |-------------------------------------------------------------------------- */ -export default function webpackBaseConfig (name) { +export default function webpackBaseConfig(name) { const nodeModulesDir = join(__dirname, '..', 'node_modules') const config = { @@ -113,7 +113,7 @@ export default function webpackBaseConfig (name) { // Workaround for hiding Warnings about plugins without a default export (#1179) config.plugins.push({ - apply (compiler) { + apply(compiler) { compiler.plugin('done', stats => { stats.compilation.warnings = stats.compilation.warnings.filter(warn => { if (warn.name === 'ModuleDependencyWarning' && warn.message.includes(`export 'default'`) && warn.message.includes('plugin')) { diff --git a/lib/builder/webpack/client.config.js b/lib/builder/webpack/client.config.js index 5f1d48490e..c61b130e59 100644 --- a/lib/builder/webpack/client.config.js +++ b/lib/builder/webpack/client.config.js @@ -24,7 +24,7 @@ debug.color = 2 // Force green color | In production, will generate public/dist/style.css |-------------------------------------------------------------------------- */ -export default function webpackClientConfig () { +export default function webpackClientConfig() { let config = base.call(this, 'client') // App entry @@ -48,7 +48,7 @@ export default function webpackClientConfig () { new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: this.options.build.filenames.vendor, - minChunks (module, count) { + minChunks(module, count) { // In the dev we use on-demand-entries. // So, it makes no sense to use commonChunks based on the minChunks count. // Instead, we move all the code in node_modules into each of the pages. @@ -222,7 +222,7 @@ export default function webpackClientConfig () { if (typeof this.options.build.extend === 'function') { const isDev = this.options.dev const extendedConfig = this.options.build.extend.call(this, config, { - get dev () { + get dev() { console.warn('dev has been deprecated in build.extend(), please use isDev') // eslint-disable-line no-console return isDev }, diff --git a/lib/builder/webpack/dll.config.js b/lib/builder/webpack/dll.config.js index 8b030f6766..725015c7df 100644 --- a/lib/builder/webpack/dll.config.js +++ b/lib/builder/webpack/dll.config.js @@ -8,7 +8,7 @@ import ClientConfig from './client.config' | https://github.com/webpack/webpack/tree/master/examples/dll |-------------------------------------------------------------------------- */ -export default function webpackDllConfig (_refConfig) { +export default function webpackDllConfig(_refConfig) { const refConfig = _refConfig || new ClientConfig() const name = refConfig.name + '-dll' diff --git a/lib/builder/webpack/server.config.js b/lib/builder/webpack/server.config.js index 2ee1809780..47a74cd3cb 100644 --- a/lib/builder/webpack/server.config.js +++ b/lib/builder/webpack/server.config.js @@ -11,7 +11,7 @@ import base from './base.config.js' | Webpack Server Config |-------------------------------------------------------------------------- */ -export default function webpackServerConfig () { +export default function webpackServerConfig() { let config = base.call(this, 'server') // env object defined in nuxt.config.js @@ -78,7 +78,7 @@ export default function webpackServerConfig () { if (typeof this.options.build.extend === 'function') { const isDev = this.options.dev const extendedConfig = this.options.build.extend.call(this, config, { - get dev () { + get dev() { console.warn('dev has been deprecated in build.extend(), please use isDev') // eslint-disable-line no-console return isDev }, diff --git a/lib/builder/webpack/style-loader.js b/lib/builder/webpack/style-loader.js index 82a1183cfe..1e4b71171d 100755 --- a/lib/builder/webpack/style-loader.js +++ b/lib/builder/webpack/style-loader.js @@ -1,7 +1,7 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin' import { join } from 'path' -export default function styleLoader (ext, loaders = [], isVueLoader = false) { +export default function styleLoader(ext, loaders = [], isVueLoader = false) { // Normalize loaders loaders = (Array.isArray(loaders) ? loaders : [loaders]).map(loader => { if (typeof loader === 'string') { diff --git a/lib/common/utils.js b/lib/common/utils.js index ad0b90bef2..4932974119 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -1,15 +1,15 @@ import { resolve, relative, sep } from 'path' import _ from 'lodash' -export function encodeHtml (str) { +export function encodeHtml(str) { return str.replace(//g, '>') } -export function getContext (req, res) { +export function getContext(req, res) { return { req, res } } -export function setAnsiColors (ansiHTML) { +export function setAnsiColors(ansiHTML) { ansiHTML.setColors({ reset: ['efefef', 'a6004c'], darkgrey: '5a012b', @@ -22,21 +22,21 @@ export function setAnsiColors (ansiHTML) { }) } -export async function waitFor (ms) { +export async function waitFor(ms) { return new Promise(function (resolve) { setTimeout(resolve, (ms || 0)) }) } -export function urlJoin () { +export function urlJoin() { return [].slice.call(arguments).join('/').replace(/\/+/g, '/').replace(':/', '://') } -export function isUrl (url) { +export function isUrl(url) { return (url.indexOf('http') === 0 || url.indexOf('//') === 0) } -export function promisifyRoute (fn) { +export function promisifyRoute(fn) { // If routes is an array if (Array.isArray(fn)) { return Promise.resolve(fn) @@ -59,15 +59,15 @@ export function promisifyRoute (fn) { return promise } -export function sequence (tasks, fn) { +export function sequence(tasks, fn) { return tasks.reduce((promise, task) => promise.then(() => fn(task)), Promise.resolve()) } -export function parallel (tasks, fn) { +export function parallel(tasks, fn) { return Promise.all(tasks.map(task => fn(task))) } -export function chainFn (base, fn) { +export function chainFn(base, fn) { /* istanbul ignore if */ if (!(fn instanceof Function)) { return @@ -90,13 +90,13 @@ export function chainFn (base, fn) { } } -export function isPureObject (o) { +export function isPureObject(o) { return !Array.isArray(o) && typeof o === 'object' } export const isWindows = /^win/.test(process.platform) -export function wp (p = '') { +export function wp(p = '') { /* istanbul ignore if */ if (isWindows) { return p.replace(/\\/g, '\\\\') @@ -104,7 +104,7 @@ export function wp (p = '') { return p } -export function wChunk (p = '') { +export function wChunk(p = '') { /* istanbul ignore if */ if (isWindows) { return p.replace(/\//g, '\\\\') @@ -116,7 +116,7 @@ const reqSep = /\//g const sysSep = _.escapeRegExp(sep) const normalize = string => string.replace(reqSep, sysSep) -export function r () { +export function r() { let args = Array.prototype.slice.apply(arguments) let lastArg = _.last(args) @@ -127,7 +127,7 @@ export function r () { return wp(resolve(...args.map(normalize))) } -export function relativeTo () { +export function relativeTo() { let args = Array.prototype.slice.apply(arguments) let dir = args.shift() @@ -147,7 +147,7 @@ export function relativeTo () { return wp(rp) } -export function flatRoutes (router, path = '', routes = []) { +export function flatRoutes(router, path = '', routes = []) { router.forEach((r) => { if (!r.path.includes(':') && !r.path.includes('*')) { /* istanbul ignore if */ @@ -161,7 +161,7 @@ export function flatRoutes (router, path = '', routes = []) { return routes } -export function cleanChildrenRoutes (routes, isChild = false) { +export function cleanChildrenRoutes(routes, isChild = false) { let start = -1 let routesIndex = [] routes.forEach((route) => { @@ -207,7 +207,7 @@ export function cleanChildrenRoutes (routes, isChild = false) { return routes } -export function createRoutes (files, srcDir) { +export function createRoutes(files, srcDir) { let routes = [] files.forEach((file) => { let keys = file.replace(/^pages/, '').replace(/\.vue$/, '').replace(/\/{2,}/g, '/').split('/').slice(1) diff --git a/lib/core/meta.js b/lib/core/meta.js index 55538f5da4..8975894324 100644 --- a/lib/core/meta.js +++ b/lib/core/meta.js @@ -5,7 +5,7 @@ import VueServerRenderer from 'vue-server-renderer' import LRU from 'lru-cache' export default class MetaRenderer { - constructor (nuxt, renderer) { + constructor(nuxt, renderer) { this.nuxt = nuxt this.renderer = renderer this.options = nuxt.options @@ -22,7 +22,7 @@ export default class MetaRenderer { }) } - getMeta (url) { + getMeta(url) { return new Promise((resolve, reject) => { const vm = new Vue({ render: (h) => h(), // Render empty html tag @@ -35,7 +35,7 @@ export default class MetaRenderer { }) } - async render ({ url = '/' }) { + async render({ url = '/' }) { let meta = this.cache.get(url) if (meta) { diff --git a/test/basic.dom.test.js b/test/basic.dom.test.js index 9835832037..9e3b881a67 100644 --- a/test/basic.dom.test.js +++ b/test/basic.dom.test.js @@ -22,7 +22,7 @@ test.before('Init Nuxt.js', async t => { rootDir: resolve(__dirname, 'fixtures/basic'), dev: false, head: { - titleTemplate (titleChunk) { + titleTemplate(titleChunk) { return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js' } } diff --git a/test/basic.fail.generate.test.js b/test/basic.fail.generate.test.js index 65f996193d..e5386e0bcf 100644 --- a/test/basic.fail.generate.test.js +++ b/test/basic.fail.generate.test.js @@ -7,7 +7,7 @@ test('Fail with routes() which throw an error', async t => { rootDir: resolve(__dirname, 'fixtures/basic'), dev: false, generate: { - async routes () { + async routes() { throw new Error('Not today!') } } diff --git a/test/basic.test.js b/test/basic.test.js index 2420cce13b..c290c184b8 100755 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -15,7 +15,7 @@ test.before('Init Nuxt.js', async t => { rootDir: resolve(__dirname, 'fixtures/basic'), dev: false, head: { - titleTemplate (titleChunk) { + titleTemplate(titleChunk) { return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js' } }