Skip to content

Commit a139cd7

Browse files
yinmpotato4d
authored andcommitted
Prettier を導入する (#370)
* yarn add -D eslint-config-prettier eslint-plugin-prettier prettier ref: https://ja.nuxtjs.org/guide/development-tools/#eslint-%E3%81%A8-prettier * prettierを導入して、lintのerrorまで解消 create-nuxt-app で prettierを導入した時の設定ファイルをベースにした * fixオプションを追加 * lintの warning を解消 * 既存のlintコマンドを使って、DRYに書く * 不要な部分を削除して、記述を統一する * Prettierで整形する
1 parent 886c95e commit a139cd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1195
-814
lines changed

.eslintrc.js

+13-36
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,21 @@ module.exports = {
22
root: true,
33
env: {
44
browser: true,
5-
node: true,
5+
node: true
66
},
77
parserOptions: {
8-
parser: 'babel-eslint',
8+
parser: 'babel-eslint'
99
},
10-
extends: [
11-
'standard',
12-
13-
// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
14-
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
15-
'plugin:vue/essential',
16-
],
17-
// required to lint *.vue files
18-
plugins: [
19-
'vue',
20-
],
21-
// add your custom rules here
10+
extends: ['@nuxtjs', 'plugin:prettier/recommended'],
11+
plugins: ['prettier'],
2212
rules: {
23-
'max-len': 'off',
24-
25-
// require trailing commas in multiline object literals
26-
'comma-dangle': ['error', {
27-
arrays: 'always-multiline',
28-
objects: 'always-multiline',
29-
imports: 'always-multiline',
30-
exports: 'always-multiline',
31-
functions: 'never',
32-
}],
33-
34-
'function-paren-newline': 'off',
35-
36-
// JavaScript Standard Style
37-
// http://standardjs.com/rules.html
38-
'semi': ['error', 'never'],
39-
'space-before-function-paren': ['error', {
40-
'anonymous': 'always',
41-
'named': 'always',
42-
'asyncArrow': 'always',
43-
}],
44-
},
13+
'vue/html-self-closing': [
14+
'error',
15+
{
16+
html: {
17+
void: 'always'
18+
}
19+
}
20+
]
21+
}
4522
}

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

babel.config.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
module.exports = (api) => {
1+
module.exports = api => {
22
api.cache(true)
33

44
const presets = [
55
[
66
'@babel/preset-env',
77
{
8-
'targets': {
9-
'node': 'current',
10-
},
11-
},
12-
],
8+
targets: {
9+
node: 'current'
10+
}
11+
}
12+
]
1313
]
1414

1515
return {
16-
'env': {
17-
'test': {
18-
presets,
19-
},
20-
},
16+
env: {
17+
test: {
18+
presets
19+
}
20+
}
2121
}
2222
}

jest.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
module.exports = {
22
moduleNameMapper: {
3-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/test/unit/__mocks__/fileMock.js',
3+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
4+
'<rootDir>/test/unit/__mocks__/fileMock.js',
45
'\\.(css|scss)$': '<rootDir>/test/unit/__mocks__/styleMock.js',
56
'^@/(.*)$': '<rootDir>/src/$1',
67
'^~/(.*)$': '<rootDir>/src/$1',
7-
'^vue$': 'vue/dist/vue.common.js',
8+
'^vue$': 'vue/dist/vue.common.js'
89
},
910
moduleFileExtensions: ['js', 'vue', 'json'],
1011
transform: {
1112
'^.+\\.js$': 'babel-jest',
12-
'.*\\.(vue)$': 'vue-jest',
13-
},
13+
'.*\\.(vue)$': 'vue-jest'
14+
}
1415
}

nuxt.config.js

+62-39
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,28 @@ try {
1111
require('dotenv').config()
1212
} catch (error) {
1313
if (error.code === 'ENOENT') {
14-
console.log('.env file NOT FOUND')
14+
console.log('.env file NOT FOUND') // eslint-disable-line no-console
1515
} else {
1616
throw error
1717
}
1818
}
1919

2020
const defaultUrl = 'https://vuefes.jp/'
2121
const defaultTitle = 'Vue Fes Japan 2018 | 2018年11月3日(土)'
22-
const defaultDescription = '日本で初めて開催する大規模 Vue.js カンファレンス。国内外の著名スピーカーによるセッションの他、ユーザー同士が気軽に話し合える場も設ける予定です。ぜひ、一緒に Vue.js を楽しみ、盛り上げていきましょう!'
22+
const defaultDescription =
23+
'日本で初めて開催する大規模 Vue.js カンファレンス。国内外の著名スピーカーによるセッションの他、ユーザー同士が気軽に話し合える場も設ける予定です。ぜひ、一緒に Vue.js を楽しみ、盛り上げていきましょう!'
2324
const defaultOgImageUrl = 'https://vuefes.jp/opengraph.jpg'
2425

2526
export default {
2627
mode: 'universal',
2728
srcDir: 'src/',
2829

2930
/*
30-
** Headers of the page
31-
*/
31+
** Headers of the page
32+
*/
3233
head: {
3334
htmlAttrs: {
34-
lang: 'ja',
35+
lang: 'ja'
3536
},
3637
title: defaultTitle,
3738
meta: [
@@ -44,56 +45,78 @@ export default {
4445
{ hid: 'description', name: 'description', content: defaultDescription },
4546
{ hid: 'og:url', name: 'og:url', content: defaultUrl },
4647
{ hid: 'og:title', name: 'og:title', content: defaultTitle },
47-
{ hid: 'og:description', name: 'og:description', content: defaultDescription },
48+
{
49+
hid: 'og:description',
50+
name: 'og:description',
51+
content: defaultDescription
52+
},
4853
{ hid: 'og:image', name: 'og:image', content: defaultOgImageUrl },
49-
{ hid: 'og:image:secure_url', name: 'og:image:secure_url', content: defaultOgImageUrl },
50-
{ hid: 'twitter:card', name: 'twitter:card', content: 'summary_large_image' },
54+
{
55+
hid: 'og:image:secure_url',
56+
name: 'og:image:secure_url',
57+
content: defaultOgImageUrl
58+
},
59+
{
60+
hid: 'twitter:card',
61+
name: 'twitter:card',
62+
content: 'summary_large_image'
63+
},
5164
{ hid: 'twitter:title', name: 'twitter:title', content: defaultTitle },
52-
{ hid: 'twitter:description', name: 'twitter:description', content: defaultDescription },
53-
{ hid: 'twitter:image', name: 'twitter:image', content: defaultOgImageUrl },
65+
{
66+
hid: 'twitter:description',
67+
name: 'twitter:description',
68+
content: defaultDescription
69+
},
70+
{
71+
hid: 'twitter:image',
72+
name: 'twitter:image',
73+
content: defaultOgImageUrl
74+
}
5475
],
5576
link: [
5677
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
57-
{ rel: 'apple-touch-icon', href: '/apple-touch-icon.png', sizes: '180x180' },
58-
],
78+
{
79+
rel: 'apple-touch-icon',
80+
href: '/apple-touch-icon.png',
81+
sizes: '180x180'
82+
}
83+
]
5984
},
6085
/*
61-
** Customize the progress bar color
62-
*/
86+
** Customize the progress bar color
87+
*/
6388
loading: { color: '#3B8070' },
6489
/*
65-
** Build configuration
66-
*/
90+
** Build configuration
91+
*/
6792
build: {
6893
/*
69-
** Run ESLint on save
70-
*/
71-
extend (config, { isDev, isClient }) {
94+
** Run ESLint on save
95+
*/
96+
extend(config, { isDev, isClient }) {
7297
if (isDev && isClient) {
7398
config.module.rules.push({
7499
enforce: 'pre',
75100
test: /\.(js|vue)$/,
76101
loader: 'eslint-loader',
77-
exclude: /(node_modules)/,
102+
exclude: /(node_modules)/
78103
})
79104
}
80105
config.module.rules.push({
81106
test: /\.webp$/,
82107
loader: 'url-loader',
83108
options: {
84109
limit: 1000,
85-
name: 'img/[name].[hash:7].[ext]',
86-
},
110+
name: 'img/[name].[hash:7].[ext]'
111+
}
87112
})
88-
},
113+
}
89114
},
90-
css: [
91-
{ src: '~/assets/stylesheets/main.scss', lang: 'scss' },
92-
],
115+
css: [{ src: '~/assets/stylesheets/main.scss', lang: 'scss' }],
93116
router: {
94117
scrollBehavior: (to, from, savedPosition) => {
95118
return { x: 0, y: 0 }
96-
},
119+
}
97120
},
98121
generate: {
99122
// TODO: speakers.getters.speakerIds を使うやり方に書き換えたい
@@ -109,8 +132,8 @@ export default {
109132
'fukuiretu',
110133
'takanorip',
111134
'ts020',
112-
'tsuchikazu',
113-
].map(speakerId => `/speakers/${speakerId}`),
135+
'tsuchikazu'
136+
].map(speakerId => `/speakers/${speakerId}`)
114137
},
115138
modules: [
116139
'@nuxtjs/google-analytics',
@@ -119,26 +142,26 @@ export default {
119142
'@nuxtjs/pwa',
120143
{
121144
icon: {
122-
iconSrc: 'src/static/apple-touch-icon.png',
123-
},
124-
},
125-
],
145+
iconSrc: 'src/static/apple-touch-icon.png'
146+
}
147+
}
148+
]
126149
],
127150
plugins: [
128151
{ src: '~/plugins/global-navigation-handler', ssr: false },
129152
{ src: '~/plugins/typekit', ssr: false },
130-
{ src: '~/plugins/vue-lazyload', ssr: false },
153+
{ src: '~/plugins/vue-lazyload', ssr: false }
131154
],
132155
env: {
133-
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY || 'PLEASE_SET_ME',
156+
googleMapsApiKey: process.env.GOOGLE_MAPS_API_KEY || 'PLEASE_SET_ME'
134157
},
135158
'google-analytics': {
136-
id: process.env.GA_TRACKING_ID || 'UA-XXXXXXX-X',
159+
id: process.env.GA_TRACKING_ID || 'UA-XXXXXXX-X'
137160
},
138161
styleResources: {
139162
scss: [
140163
'~/assets/stylesheets/foundation/variables.scss',
141-
'~/assets/stylesheets/foundation/colors.scss',
142-
],
143-
},
164+
'~/assets/stylesheets/foundation/colors.scss'
165+
]
166+
}
144167
}

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"test": "jest --verbose",
1414
"test:ci": "jest --ci --coverage --no-cache",
1515
"lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
16-
"precommit": "yarn run lint && ./bin/imagemin"
16+
"lint:fix": "yarn lint --fix",
17+
"precommit": "yarn lint && ./bin/imagemin"
1718
},
1819
"dependencies": {
1920
"@nuxtjs/axios": "^5.1.1",
@@ -30,16 +31,20 @@
3031
"devDependencies": {
3132
"@babel/core": "^7.3.4",
3233
"@babel/preset-env": "^7.3.4",
34+
"@nuxtjs/eslint-config": "^0.0.1",
3335
"@vue/test-utils": "^1.0.0-beta.25",
3436
"ajv": "^6.1.1",
3537
"babel-eslint": "^10.0.1",
3638
"babel-jest": "^24.1.0",
3739
"eslint": "^5.14.1",
40+
"eslint-config-prettier": "^4.1.0",
3841
"eslint-config-standard": "^12.0.0",
3942
"eslint-friendly-formatter": "^4.0.1",
4043
"eslint-loader": "^2.1.2",
4144
"eslint-plugin-import": "^2.16.0",
45+
"eslint-plugin-jest": "^22.3.0",
4246
"eslint-plugin-node": "^8.0.1",
47+
"eslint-plugin-prettier": "^3.0.1",
4348
"eslint-plugin-promise": "^4.0.1",
4449
"eslint-plugin-standard": "^4.0.0",
4550
"eslint-plugin-vue": "^5.2.2",
@@ -52,6 +57,7 @@
5257
"imagemin-svgo": "^7.0.0",
5358
"jest": "^24.1.0",
5459
"node-sass": "^4.11.0",
60+
"prettier": "^1.16.4",
5561
"sass-loader": "^7.1.0",
5662
"vue-jest": "^4.0.0-beta.2"
5763
}

src/components/BaseButton.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
<script>
88
export default {
9-
name: 'BaseButton',
9+
name: 'BaseButton'
1010
}
1111
</script>
1212

13-
<style lang="scss" scoped src="./BaseButton.scss">
14-
</style>
13+
<style lang="scss" scoped src="./BaseButton.scss"></style>

src/components/BaseSection.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
</section>
1313
</template>
1414

15+
<!-- eslint-disable vue/require-default-prop -->
1516
<script>
1617
export default {
1718
name: 'BaseSection',
1819
props: {
1920
theme: {
2021
type: String,
21-
required: false,
22-
},
23-
},
22+
required: false
23+
}
24+
}
2425
}
2526
</script>
27+
<!-- eslint-enable vue/require-default-prop -->
2628

2729
<style lang="scss" scoped>
2830
.base-section {

src/components/GlobalNavigationContent.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<nav class="global-navigation-content">
33
<p class="date-and-place">
4-
2018.11.3 (Sat.)<br>
4+
2018.11.3 (Sat.)<br />
55
秋葉原 UDX 4F / UDX ギャラリー
66
</p>
77

@@ -42,7 +42,7 @@
4242

4343
<script>
4444
export default {
45-
name: 'GlobalNavigationContent',
45+
name: 'GlobalNavigationContent'
4646
}
4747
</script>
4848

0 commit comments

Comments
 (0)