手动格式化-爱代码爱编程
1 安装 yarn add prettier eslint eslint-plugin-vue
2 配置文件 .prettierrc
{
"tabWidth": 2,
"printWidth": 120,
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"requirePragma": false,
"proseWrap": "preserve"
}
3配置.eslintrc.cjs
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution');
module.exports = {
root: true,
extends: ['plugin:vue/vue3-essential', 'eslint:recommended', '@vue/eslint-config-prettier'],
plugins: ['prettier'],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
'no-unused-vars': 0,
indent: ['error', 2],
'vue/multi-word-component-names': 0,
'prettier/prettier': [
'error',
{
tabWidth: 2,
},
],
},
};
4每次服务器写完代码就
-
npx prettier --write "src/**/*.js"
-
npx prettier --write "src/**/*.vue"
-
npx prettier --write "src/**/*.tsx"