diff --git a/.circleci/config.yml b/.circleci/config.yml index f31b7cd6dc..4368965768 100755 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -109,6 +109,16 @@ jobs: paths: - test/fixtures + lint-app: + <<: *defaults + steps: + - checkout + - attach_workspace: + at: ~/project + - run: + name: Lint vue-app templates + command: yarn lint:app + # -------------------------------------------------------------------------- # Phase 3: Unit and E2E tests # -------------------------------------------------------------------------- @@ -148,17 +158,18 @@ workflows: version: 2 # Build and test after each commit - # Manually release on releas branches + # Manually release on release branches commit: jobs: - setup - lint: { requires: [setup] } - audit: { requires: [setup] } - build: { requires: [setup] } + - lint-app: { requires: [build] } - test-unit: { requires: [build] } - test-e2e: { requires: [build] } - release-commit: - requires: [build, lint, audit, test-unit, test-e2e] + requires: [build, lint, lint-app, audit, test-unit, test-e2e] filters: <<: *release_branches @@ -169,10 +180,11 @@ workflows: - lint: { requires: [setup] } - audit: { requires: [setup] } - build: { requires: [setup] } + - lint-app: { requires: [build] } - test-unit: { requires: [build] } - test-e2e: { requires: [build] } - release-nightly: - requires: [build, lint, audit, test-unit, test-e2e] + requires: [build, lint, lint-app, audit, test-unit, test-e2e] triggers: - schedule: cron: "0 0 * * *" diff --git a/.eslintrc.js b/.eslintrc.js index ed08d4468a..9fa6477017 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,9 +13,9 @@ module.exports = { overrides: [{ files: [ 'test/fixtures/*/.nuxt*/**' ], rules: { - 'vue/name-property-casing': ['error', 'kebab-case'] + 'vue/name-property-casing': 'error' } - },{ + }, { files: [ 'examples/storybook/**', 'examples/with-element-ui/**', @@ -29,9 +29,9 @@ module.exports = { 'vue/component-name-in-template-casing': ['warn', 'kebab-case'] } }, { - files: [ 'test/fixtures/*/.nuxt*/**/+(App|index).js' ], + files: [ 'test/fixtures/*/.nuxt*/**/+(App|index|server|client).js' ], rules: { - 'import/order': 'ignore' + 'import/order': 'off' } }, { files: [ 'test/fixtures/*/.nuxt*/**/client.js' ], @@ -47,7 +47,18 @@ module.exports = { files: [ 'test/fixtures/*/.nuxt*/**/*.html' ], rules: { 'semi': ['error', 'always', { 'omitLastInOneLineBlock': true }], - 'no-var': 'warn' + 'no-var': 'off' + } + }, { + files: [ 'test/fixtures/*/.nuxt*/**/nuxt-error.vue' ], + rules: { + 'vue/singleline-html-element-content-newline': 'off' + } + }, { + // might be removed in the future, see https://github.com/standard/eslint-plugin-standard/issues/27 + files: [ 'test/fixtures/*/.nuxt*/**/nuxt-link.client.js' ], + rules: { + 'standard/no-callback-literal': 'off' } }] } diff --git a/package.json b/package.json index d216ab6282..d04a4a1c67 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev": "node -r esm ./scripts/dev", "coverage": "codecov", "lint": "eslint --ext .js,.mjs,.vue .", - "lint:app": "eslint-multiplexer eslint --ignore-path packages/app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b", + "lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b", "nuxt": "node -r esm ./packages/cli/bin/nuxt-cli.js", "test": "yarn test:fixtures && yarn test:unit && yarn test:types", "test:fixtures": "jest test/fixtures", diff --git a/packages/utils/src/serialize.js b/packages/utils/src/serialize.js index a53c59e77a..d04bd31194 100644 --- a/packages/utils/src/serialize.js +++ b/packages/utils/src/serialize.js @@ -5,17 +5,17 @@ export function serializeFunction(func) { let open = false return serialize(func) .replace(serializeFunction.assignmentRE, (_, spaces) => { - return `${spaces}:function(` + return `${spaces}: function (` }) .replace(serializeFunction.internalFunctionRE, (_, spaces, name, args) => { if (open) { - return `${spaces}${name}:function(${args}) {` + return `${spaces}${name}: function (${args}) {` } else { open = true return _ } }) - .replace(`${func.name}(`, 'function(') + .replace(`${func.name}(`, 'function (') } serializeFunction.internalFunctionRE = /^(\s*)(?!(?:if)|(?:for)|(?:while)|(?:switch))(\w+)\s*\((.*?)\)\s*\{/gm diff --git a/packages/vue-app/template/App.js b/packages/vue-app/template/App.js index d14d7a8ed5..4b362a4600 100644 --- a/packages/vue-app/template/App.js +++ b/packages/vue-app/template/App.js @@ -17,9 +17,9 @@ const layouts = { <%= Object.keys(layouts).map(key => `"_${key}": _${hash(key)}` <% if (splitChunks.layouts) { %>let resolvedLayouts = {}<% } %> export default { - <%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %> + <%= isTest ? '/* eslint-disable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, space-before-function-paren */' : '' %> head: <%= serializeFunction(head) %>, - <%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, object-property-newline, arrow-parens */' : '' %> + <%= isTest ? '/* eslint-enable quotes, semi, indent, comma-spacing, key-spacing, object-curly-spacing, space-before-function-paren */' : '' %> render(h, props) { <% if (loading) { %>const loadingEl = h('NuxtLoading', { ref: 'loading' })<% } %> const layoutEl = h(this.layout || 'nuxt') diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index 58681d4c78..1794ac53e3 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -22,14 +22,11 @@ import NuxtLink from './components/nuxt-link.<%= router.prefetchLinks ? "client" Vue.component(NuxtLink.name, NuxtLink) Vue.component('NLink', NuxtLink) -const noopData = () => { return {} } -const noopFetch = () => {} - // Global shared references let _lastPaths = [] let app let router -<% if (store) { %>let store<% } %> +<% if (store) { %>let store<%= isTest ? '// eslint-disable-line no-unused-vars' : '' %><% } %> // Try to rehydrate SSR data from window const NUXT = window.<%= globals.context %> || {} @@ -150,8 +147,8 @@ async function loadAsyncComponents(to, from, next) { <% } %> // Call next() next() - } catch (err) { - err = err || {} + } catch (error) { + const err = error || {} const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500 const message = err.message || '' @@ -524,6 +521,9 @@ function nuxtReady(_app) { } <% if (isDev) { %> +const noopData = () => { return {} } +const noopFetch = () => {} + // Special hot reload with asyncData(context) function getNuxtChildComponents($parent, $components = []) { $parent.$children.forEach(($child) => { diff --git a/packages/vue-app/template/components/nuxt-child.js b/packages/vue-app/template/components/nuxt-child.js index eead146bac..b6e8595a06 100644 --- a/packages/vue-app/template/components/nuxt-child.js +++ b/packages/vue-app/template/components/nuxt-child.js @@ -8,7 +8,10 @@ export default { default: '' }, keepAlive: Boolean, - keepAliveProps: Object + keepAliveProps: { + type: Object, + default: undefined + } }, render(h, { parent, data, props }) { data.nuxtChild = true diff --git a/packages/vue-app/template/components/nuxt-error.vue b/packages/vue-app/template/components/nuxt-error.vue index 7c4e7d7b26..a84cbd475a 100644 --- a/packages/vue-app/template/components/nuxt-error.vue +++ b/packages/vue-app/template/components/nuxt-error.vue @@ -1,7 +1,9 @@