From 3f1d634fb7f43676090a873ba208ded1f9ce6be1 Mon Sep 17 00:00:00 2001 From: Jonas Galvez Date: Sun, 5 Aug 2018 21:12:44 -0300 Subject: [PATCH] Consistent parens in arrow functions (#3630) * Minor consistency enhancements * Arrow parenthesis consistency * Change linting rule * Fix typo * Update .eslintrc.js to only require parens for blocks * Update style according to brace-only suggestion * Remove --fix from lint * Tweak no-loading time (failing test) * Tweak no-loading time (failing test) (2) * Tweak no-loading time (failing test) (3) * Tweak no-loading time (failing test) (4) * Tweak no-loading time (failing test) (5) --- .eslintrc.js | 4 +- bin/common/utils.js | 4 +- .../async-component-injection/pages/_slug.vue | 2 +- examples/coffeescript/modules/coffeescript.js | 2 +- examples/dynamic-components/pages/index.vue | 2 +- examples/dynamic-components/pages/ssr.vue | 2 +- examples/layout-transitions/pages/users.vue | 2 +- examples/nested-components/pages/index.vue | 2 +- examples/nested-routes/pages/index/_id.vue | 2 +- examples/routes-transitions/pages/users.vue | 2 +- examples/scroll-behavior/pages/users.vue | 2 +- .../storybook/stories/collection.story.js | 4 +- examples/typescript/modules/typescript.js | 2 +- examples/vue-chartjs/pages/contributors.vue | 2 +- examples/vue-chartjs/pages/index.vue | 4 +- examples/vuex-persistedstate/store/index.js | 4 +- examples/with-ava/test/index.test.js | 6 +- examples/with-sockets/io/index.js | 2 +- examples/with-tape/test/index.test.js | 2 +- lib/app/App.js | 15 ++- lib/app/client.js | 102 ++++++++++++------ lib/app/components/nuxt.js | 12 ++- lib/app/index.js | 6 +- lib/app/router.js | 2 +- lib/app/server.js | 8 +- lib/app/utils.js | 2 +- lib/builder/builder.js | 20 ++-- lib/builder/generator.js | 11 +- lib/builder/webpack/base.js | 2 +- lib/builder/webpack/plugins/stats.js | 2 +- lib/builder/webpack/plugins/vue/client.js | 8 +- lib/builder/webpack/plugins/vue/server.js | 2 +- lib/builder/webpack/plugins/vue/util.js | 2 +- lib/builder/webpack/plugins/warnfix.js | 4 +- lib/builder/webpack/server.js | 2 +- lib/builder/webpack/utils/postcss.js | 2 +- lib/common/utils.js | 10 +- lib/core/middleware/error.js | 6 +- lib/core/module.js | 2 +- lib/core/nuxt.js | 14 +-- lib/core/renderer.js | 6 +- test/e2e/basic.browser.test.js | 12 +-- test/fixtures/basic/nuxt.config.js | 1 + .../fixtures/basic/pages/await-async-data.vue | 2 +- test/fixtures/basic/pages/noloading.vue | 25 +++-- .../children/pages/patch/_id/child/_slug.vue | 2 +- test/fixtures/module/modules/hooks/index.js | 10 +- test/fixtures/module/nuxt.config.js | 6 +- test/fixtures/ssr/pages/asyncComponent.vue | 2 +- test/unit/basic.dev.test.js | 2 +- test/unit/basic.fail.generate.test.js | 2 +- test/unit/cli-start.test.js | 6 +- test/unit/cli.test.js | 6 +- test/unit/dynamic-routes.test.js | 2 +- test/unit/nuxt.test.js | 2 +- test/unit/spa.test.js | 2 +- test/unit/utils.test.js | 20 ++-- test/utils/browser.js | 2 +- 58 files changed, 226 insertions(+), 170 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4e895e3ca6..992b0e3d53 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,8 +38,8 @@ module.exports = { // Allow unresolved imports 'import/no-unresolved': 0, - // Allow paren-less arrow functions - 'arrow-parens': 0, + // Allow paren-less arrow functions only when there's no braces + 'arrow-parens': [2, 'as-needed', { requireForBlockBody: true }], // Allow async-await 'generator-star-spacing': 0, diff --git a/bin/common/utils.js b/bin/common/utils.js index fef511afb1..4bd2fe75bd 100644 --- a/bin/common/utils.js +++ b/bin/common/utils.js @@ -16,7 +16,7 @@ const getNuxtConfigFile = argv => resolve(getRootDir(argv), argv['config-file']) exports.nuxtConfigFile = getNuxtConfigFile -exports.loadNuxtConfig = argv => { +exports.loadNuxtConfig = (argv) => { const rootDir = getRootDir(argv) const nuxtConfigFile = getNuxtConfigFile(argv) @@ -46,7 +46,7 @@ exports.loadNuxtConfig = argv => { return options } -exports.getLatestHost = argv => { +exports.getLatestHost = (argv) => { const port = argv.port || process.env.PORT || process.env.npm_package_config_nuxt_port const host = diff --git a/examples/async-component-injection/pages/_slug.vue b/examples/async-component-injection/pages/_slug.vue index 32359858fb..62700c7a87 100644 --- a/examples/async-component-injection/pages/_slug.vue +++ b/examples/async-component-injection/pages/_slug.vue @@ -6,7 +6,7 @@ diff --git a/test/fixtures/children/pages/patch/_id/child/_slug.vue b/test/fixtures/children/pages/patch/_id/child/_slug.vue index 1b74d9915b..7b784a1aaf 100644 --- a/test/fixtures/children/pages/patch/_id/child/_slug.vue +++ b/test/fixtures/children/pages/patch/_id/child/_slug.vue @@ -18,7 +18,7 @@ async function search(q) { q = String(q || '').toLowerCase() return new Promise((resolve) => { - const searchResults = countries.filter((s) => s.toLowerCase().includes(q)) + const searchResults = countries.filter(s => s.toLowerCase().includes(q)) setTimeout(() => resolve(searchResults), 100) }) } diff --git a/test/fixtures/module/modules/hooks/index.js b/test/fixtures/module/modules/hooks/index.js index 227907b503..864721a32c 100644 --- a/test/fixtures/module/modules/hooks/index.js +++ b/test/fixtures/module/modules/hooks/index.js @@ -2,26 +2,26 @@ export default function () { let ctr = 1 // Add hook for module - this.nuxt.hook('modules:done', moduleContainer => { + this.nuxt.hook('modules:done', (moduleContainer) => { this.nuxt.__module_hook = moduleContainer && ctr++ }) // Add hook for renderer - this.nuxt.hook('render:done', renderer => { + this.nuxt.hook('render:done', (renderer) => { this.nuxt.__renderer_hook = renderer && ctr++ }) // Get data before data sent to client - this.nuxt.hook('render:context', data => { + this.nuxt.hook('render:context', (data) => { this.nuxt.__render_context = data }) // Add hook for build - this.nuxt.hook('build:done', builder => { + this.nuxt.hook('build:done', (builder) => { this.nuxt.__builder_hook = builder && ctr++ }) - this.nuxt.hook('build:done', builder => { + this.nuxt.hook('build:done', (builder) => { this.nuxt.__builder_plugin = builder && ctr++ }) } diff --git a/test/fixtures/module/nuxt.config.js b/test/fixtures/module/nuxt.config.js index a16d06bbb0..07f5ab6e5a 100644 --- a/test/fixtures/module/nuxt.config.js +++ b/test/fixtures/module/nuxt.config.js @@ -13,14 +13,14 @@ export default { ], serverMiddleware: ['./modules/middleware/midd2'], hooks(hook) { - hook('ready', nuxt => { + hook('ready', (nuxt) => { nuxt.__ready_called__ = true }) - hook('build:done', builder => { + hook('build:done', (builder) => { builder.__build_done__ = true }) // Add hook for renderer - hook('render:before', renderer => { + hook('render:before', (renderer) => { renderer.useMiddleware({ path: '/use-middleware', handler: '~/modules/middleware/use-middleware' diff --git a/test/fixtures/ssr/pages/asyncComponent.vue b/test/fixtures/ssr/pages/asyncComponent.vue index a265619eaa..4fb2845081 100644 --- a/test/fixtures/ssr/pages/asyncComponent.vue +++ b/test/fixtures/ssr/pages/asyncComponent.vue @@ -5,7 +5,7 @@