Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 1760f6a

Browse files
authored
feat: lint git staged files (#269)
1 parent d38aa96 commit 1760f6a

File tree

4 files changed

+111
-3
lines changed

4 files changed

+111
-3
lines changed

saofile.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ module.exports = {
8989
pageSize: 10,
9090
choices: [
9191
{ name: 'ESLint', value: 'eslint' },
92-
{ name: 'Prettier', value: 'prettier' }
92+
{ name: 'Prettier', value: 'prettier' },
93+
{ name: 'Lint staged files', value: 'lintStaged' }
9394
],
9495
default: []
9596
},
@@ -119,6 +120,7 @@ module.exports = {
119120
const pwa = this.answers.features.includes('pwa')
120121
const eslint = this.answers.linter.includes('eslint')
121122
const prettier = this.answers.linter.includes('prettier')
123+
const lintStaged = eslint && this.answers.linter.includes('lintStaged')
122124
const axios = this.answers.features.includes('axios')
123125
const esm = this.answers.server === 'none'
124126
const edge = process.argv.includes('--edge') ? '-edge' : ''
@@ -128,6 +130,7 @@ module.exports = {
128130
pwa,
129131
eslint,
130132
prettier,
133+
lintStaged,
131134
axios,
132135
esm,
133136
edge,

template/_package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"scripts": {
88
<%_ if (eslint) { _%>
99
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
10-
"precommit": "<%= pmRun %> lint",
1110
<%_ } _%>
1211
<%_ if (test !== 'none') { _%>
1312
"test": "<%= test %>",
@@ -29,6 +28,16 @@
2928
"generate": "nuxt generate"
3029
<%_ } _%>
3130
},
31+
<%_ if (lintStaged) { _%>
32+
"lint-staged": {
33+
"*.{js,vue}": "<%= pmRun %> lint"
34+
},
35+
"husky": {
36+
"hooks": {
37+
"pre-commit": "lint-staged"
38+
}
39+
},
40+
<%_ } _%>
3241
"dependencies": {
3342
<%_ if (server !== 'none') { _%>
3443
"cross-env": "^5.2.0",
@@ -118,6 +127,10 @@
118127
"eslint-plugin-prettier": "^3.0.1",
119128
"prettier": "^1.16.4",
120129
<%_ } _%>
130+
<%_ if (lintStaged) { _%>
131+
"husky": "^2.6.0",
132+
"lint-staged": "^8.2.1",
133+
<%_ } _%>
121134
<%_ if (test !== 'none') { _%>
122135
"@vue/test-utils": "^1.0.0-beta.27",
123136
<%_ } _%>

test/snapshots/index.test.js.md

+93-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ Generated by [AVA](https://ava.li).
347347
dev: 'nuxt',
348348
generate: 'nuxt generate',
349349
lint: 'eslint --ext .js,.vue --ignore-path .gitignore .',
350-
precommit: 'yarn lint',
351350
start: 'nuxt start',
352351
},
353352
}
@@ -404,6 +403,99 @@ Generated by [AVA](https://ava.li).
404403
}␊
405404
`
406405

406+
## verify linter: Lint staged files
407+
408+
> Generated package.json
409+
410+
[
411+
'.editorconfig',
412+
'.gitignore',
413+
'README.md',
414+
'assets/README.md',
415+
'components/Logo.vue',
416+
'components/README.md',
417+
'layouts/README.md',
418+
'layouts/default.vue',
419+
'middleware/README.md',
420+
'nuxt.config.js',
421+
'package.json',
422+
'pages/README.md',
423+
'pages/index.vue',
424+
'plugins/README.md',
425+
'static/README.md',
426+
'static/favicon.ico',
427+
'store/README.md',
428+
]
429+
430+
> package.json
431+
432+
{
433+
dependencies: {
434+
nuxt: '^2.0.0',
435+
},
436+
devDependencies: {
437+
nodemon: '^1.18.9',
438+
},
439+
private: true,
440+
scripts: {
441+
build: 'nuxt build',
442+
dev: 'nuxt',
443+
generate: 'nuxt generate',
444+
start: 'nuxt start',
445+
},
446+
}
447+
448+
> Generated nuxt.config.js
449+
450+
`␊
451+
export default {␊
452+
mode: 'universal',␊
453+
/*␊
454+
** Headers of the page␊
455+
*/␊
456+
head: {␊
457+
title: process.env.npm_package_name || '',␊
458+
meta: [␊
459+
{ charset: 'utf-8' },␊
460+
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },␊
461+
{ hid: 'description', name: 'description', content: process.env.npm_package_description || '' }␊
462+
],␊
463+
link: [␊
464+
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }␊
465+
]␊
466+
},␊
467+
/*␊
468+
** Customize the progress-bar color␊
469+
*/␊
470+
loading: { color: '#fff' },␊
471+
/*␊
472+
** Global CSS␊
473+
*/␊
474+
css: [␊
475+
],␊
476+
/*␊
477+
** Plugins to load before mounting the App␊
478+
*/␊
479+
plugins: [␊
480+
],␊
481+
/*␊
482+
** Nuxt.js modules␊
483+
*/␊
484+
modules: [␊
485+
],␊
486+
/*␊
487+
** Build configuration␊
488+
*/␊
489+
build: {␊
490+
/*␊
491+
** You can extend webpack config here␊
492+
*/␊
493+
extend(config, ctx) {␊
494+
}␊
495+
}␊
496+
}␊
497+
`
498+
407499
## verify linter: Prettier
408500

409501
> Generated package.json

test/snapshots/index.test.js.snap

-5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)