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

Commit

Permalink
feat: lint git staged files (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo authored Jun 26, 2019
1 parent d38aa96 commit 1760f6a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
5 changes: 4 additions & 1 deletion saofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
},
Expand Down Expand Up @@ -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' : ''
Expand All @@ -128,6 +130,7 @@ module.exports = {
pwa,
eslint,
prettier,
lintStaged,
axios,
esm,
edge,
Expand Down
15 changes: 14 additions & 1 deletion template/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"scripts": {
<%_ if (eslint) { _%>
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
"precommit": "<%= pmRun %> lint",
<%_ } _%>
<%_ if (test !== 'none') { _%>
"test": "<%= test %>",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
<%_ } _%>
Expand Down
94 changes: 93 additions & 1 deletion test/snapshots/index.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}
Expand Down Expand Up @@ -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
Expand Down
Binary file modified test/snapshots/index.test.js.snap
Binary file not shown.

0 comments on commit 1760f6a

Please sign in to comment.