Repository: nuxt/create-nuxt-app (js)

Issue:
Precommit hook does not work out of the box. Possible missing dependency
Hi. When I created a nuxt project using `npx create-nuxt-app`, it creates a precommit hook for `npm run lint` command in package.json. This hook was not working until I installed husky. Is it correct behavior?



Pull request:
feat: lint git staged files
Resolve #260

Patch:
diff --git a/saofile.js b/saofile.js
index 5e8f93b..955dcf0 100644
--- a/saofile.js
+++ b/saofile.js
@@ -89,7 +89,8 @@ module.exports = {
       pageSize: 10,
       choices: [
         { name: 'ESLint', value: 'eslint' },
-        { name: 'Prettier', value: 'prettier' }
+        { name: 'Prettier', value: 'prettier' },
+        { name: 'Lint staged files', value: 'lintStaged' }
       ],
       default: []
     },
@@ -119,6 +120,7 @@ module.exports = {
     const pwa = this.answers.features.includes('pwa')
     const eslint = this.answers.linter.includes('eslint')
     const prettier = this.answers.linter.includes('prettier')
+    const lintStaged = eslint && this.answers.linter.includes('lintStaged')
     const axios = this.answers.features.includes('axios')
     const esm = this.answers.server === 'none'
     const edge = process.argv.includes('--edge') ? '-edge' : ''
@@ -128,6 +130,7 @@ module.exports = {
       pwa,
       eslint,
       prettier,
+      lintStaged,
       axios,
       esm,
       edge,
diff --git a/template/_package.json b/template/_package.json
index 5aff426..4e4684e 100644
--- a/template/_package.json
+++ b/template/_package.json
@@ -7,7 +7,6 @@
   "scripts": {
     <%_ if (eslint) { _%>
     "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
-    "precommit": "<%= pmRun %> lint",
     <%_ } _%>
     <%_ if (test !== 'none') { _%>
     "test": "<%= test %>",
@@ -29,6 +28,16 @@
     "generate": "nuxt generate"
     <%_ } _%>
   },
+  <%_ if (lintStaged) { _%>
+  "lint-staged": {
+    "*.{js,vue}": "<%= pmRun %> lint"
+  },
+  "husky": {
+    "hooks": {
+      "pre-commit": "lint-staged"
+    }
+  },
+  <%_ } _%>
   "dependencies": {
     <%_ if (server !== 'none') { _%>
     "cross-env": "^5.2.0",
@@ -118,6 +127,10 @@
     "eslint-plugin-prettier": "^3.0.1",
     "prettier": "^1.16.4",
     <%_ } _%>
+    <%_ if (lintStaged) { _%>
+    "husky": "^2.6.0",
+    "lint-staged": "^8.2.1",
+    <%_ } _%>
     <%_ if (test !== 'none') { _%>
     "@vue/test-utils": "^1.0.0-beta.27",
     <%_ } _%>


Test patch:
diff --git a/test/snapshots/index.test.js.md b/test/snapshots/index.test.js.md
index 0598e6f..7d14fca 100644
--- a/test/snapshots/index.test.js.md
+++ b/test/snapshots/index.test.js.md
@@ -347,7 +347,6 @@ Generated by [AVA](https://ava.li).
         dev: 'nuxt',
         generate: 'nuxt generate',
         lint: 'eslint --ext .js,.vue --ignore-path .gitignore .',
-        precommit: 'yarn lint',
         start: 'nuxt start',
       },
     }
@@ -404,6 +403,99 @@ Generated by [AVA](https://ava.li).
     }␊
     `
 
+## verify linter: Lint staged files
+
+> Generated package.json
+
+    [
+      '.editorconfig',
+      '.gitignore',
+      'README.md',
+      'assets/README.md',
+      'components/Logo.vue',
+      'components/README.md',
+      'layouts/README.md',
+      'layouts/default.vue',
+      'middleware/README.md',
+      'nuxt.config.js',
+      'package.json',
+      'pages/README.md',
+      'pages/index.vue',
+      'plugins/README.md',
+      'static/README.md',
+      'static/favicon.ico',
+      'store/README.md',
+    ]
+
+> package.json
+
+    {
+      dependencies: {
+        nuxt: '^2.0.0',
+      },
+      devDependencies: {
+        nodemon: '^1.18.9',
+      },
+      private: true,
+      scripts: {
+        build: 'nuxt build',
+        dev: 'nuxt',
+        generate: 'nuxt generate',
+        start: 'nuxt start',
+      },
+    }
+
+> Generated nuxt.config.js
+
+    `␊
+    export default {␊
+      mode: 'universal',␊
+      /*␊
+      ** Headers of the page␊
+      */␊
+      head: {␊
+        title: process.env.npm_package_name || '',␊
+        meta: [␊
+          { charset: 'utf-8' },␊
+          { name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
+          { hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊
+        ],␊
+        link: [␊
+          { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
+        ]␊
+      },␊
+      /*␊
+      ** Customize the progress-bar color␊
+      */␊
+      loading: { color: '#fff' },␊
+      /*␊
+      ** Global CSS␊
+      */␊
+      css: [␊
+      ],␊
+      /*␊
+      ** Plugins to load before mounting the App␊
+      */␊
+      plugins: [␊
+      ],␊
+      /*␊
+      ** Nuxt.js modules␊
+      */␊
+      modules: [␊
+      ],␊
+      /*␊
+      ** Build configuration␊
+      */␊
+      build: {␊
+        /*␊
+        ** You can extend webpack config here␊
+        */␊
+        extend(config, ctx) {␊
+        }␊
+      }␊
+    }␊
+    `
+
 ## verify linter: Prettier
 
 > Generated package.json