Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit70d5c75

Browse files
author
kevin
committed
feat: add prettier
1 parent786034c commit70d5c75

File tree

9 files changed

+190
-13
lines changed

9 files changed

+190
-13
lines changed

‎.eslintrc.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ module.exports = {
22
root:true,
33
parserOptions:{
44
ecmaVersion:12,
5-
parser:"@babel/eslint-parser",
5+
parser:'@babel/eslint-parser',
66
requireConfigFile:false,
7-
sourceType:"module",
7+
sourceType:'module'
88
},
99
env:{
1010
browser:true,
1111
node:true,
1212
es6:true,
13-
"vue/setup-compiler-macros":true,// 新增
13+
'vue/setup-compiler-macros':true// 新增
1414
},
15-
extends:["plugin:vue/vue3-essential","eslint:recommended"],
16-
rules:{},
17-
};
15+
extends:['plugin:vue/vue3-essential','eslint:recommended','plugin:prettier/recommended'],
16+
rules:{
17+
'prettier/prettier':'error',
18+
'vue/multi-word-component-names':0
19+
}
20+
}

‎.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.vscode

‎.prettierrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports={
2+
printWidth:120,
3+
tabWidth:2,
4+
useTabs:false,
5+
singleQuote:true,
6+
semi:false,
7+
trailingComma:'none',
8+
bracketSpacing:true,
9+
eslintIntegration:true
10+
}

‎README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
"lint": "eslint --ext .vue,.js,.ts,.jsx,.tsx --fix src"
4242
```
4343

44-
vue3的setup语法糖还是有错误
44+
vue3 的 setup 语法糖还是有错误
4545

4646
```
4747
error 'defineProps' is not defined no-undef
@@ -62,6 +62,48 @@ env: {
6262

6363
###prettier
6464

65+
统一代码风格
66+
67+
```
68+
npm install prettier eslint-config-prettier eslint-plugin-prettier -D
69+
```
70+
71+
创建`.prettierrc.js`
72+
73+
```
74+
module.exports = {
75+
// 一行的字符数,如果超过会进行换行,默认为80
76+
printWidth: 120,
77+
// 一个tab代表几个空格数,默认为80
78+
tabWidth: 2,
79+
// 是否使用tab进行缩进,默认为false,表示用空格进行缩减
80+
useTabs: false,
81+
// 字符串是否使用单引号,默认为false,使用双引号
82+
singleQuote: true,
83+
// 行位是否使用分号,默认为true
84+
semi: false,
85+
// 是否使用尾逗号,有三个可选值"<none|es5|all>"
86+
trailingComma: 'none',
87+
// 对象大括号直接是否有空格,默认为true,效果:{ foo: bar }
88+
bracketSpacing: true,
89+
90+
// 开启 eslint 支持
91+
eslintIntegration: true
92+
}
93+
94+
```
95+
96+
也可以添加`.prettierignore` 文件,忽略文件
97+
98+
```
99+
node_modules
100+
.vscode
101+
```
102+
103+
修改 eslint(.eslintrc.js)配置
104+
105+
106+
65107
###husky
66108

67109
###router

‎package-lock.json

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"@babel/eslint-parser":"^7.17.0",
1717
"@vitejs/plugin-vue":"^2.3.1",
1818
"eslint":"^8.13.0",
19+
"eslint-config-prettier":"^8.5.0",
20+
"eslint-plugin-prettier":"^4.0.0",
1921
"eslint-plugin-vue":"^8.6.0",
22+
"prettier":"^2.6.2",
2023
"vite":"^2.9.2"
2124
}
22-
}
25+
}

‎src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup>
2-
// This starter template is using Vue 3 <script setup> SFCs
3-
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
42
importHelloWorldfrom'./components/HelloWorld.vue'
3+
importMainfrom'./components/Main.vue'
54
</script>
65

76
<template>
87
<imgalt="Vue logo"src="./assets/logo.png" />
98
<HelloWorldmsg="Hello Vue 3 + Vite" />
9+
<Main />
1010
</template>
1111

1212
<style>

‎src/components/HelloWorld.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ const count = ref(0)
1919
</p>
2020

2121
<p>
22-
<ahref="https://vitejs.dev/guide/features.html"target="_blank">
23-
Vite Documentation
24-
</a>
22+
<ahref="https://vitejs.dev/guide/features.html"target="_blank"> Vite Documentation </a>
2523
|
2624
<ahref="https://v3.vuejs.org/"target="_blank">Vue 3 Documentation</a>
2725
</p>

‎src/components/Main.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div>sd</div>
3+
</template>
4+
5+
<script>
6+
exportdefault {
7+
setup() {
8+
return {}
9+
}
10+
}
11+
</script>
12+
13+
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp