代码风格(editorconfig + eslint + pre
2021-05-14 本文已影响0人
无疆wj
# .editorconfig
root = true # 根目录的配置文件,编辑器会由当前目录向上查找,如果找到 `roor = true` 的文件,则不再查找
[*] # 匹配所有的文件
indent_style = space # 空格缩进
indent_size = 2 # 缩进空格为2个
end_of_line = lf # 文件换行符是 linux 的 `\n`
charset = utf-8 # 文件编码是 utf-8
trim_trailing_whitespace = true # 不保留行末的空格
insert_final_newline = true # 文件末尾添加一个空行
// .eslintrc.js
module.exports = {
root: true,
env: {
node: true,
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint",
},
rules: {
indent: ["warn", 2, { SwitchCase: 1 }],
quotes: ["warn", "double"],
"prettier/prettier": ["warn", { arrowParens: "always", printWidth: 120 }],
},
globals: {
WeixinJSBridge: "readonly",
AlipayJSBridge: "readonly",
},
};
// .prettierrc.js
module.exports = {
singleQuote: false, // 是否单引号包含字符串
semi: true, // 是否在语句末尾打印分号
bracketSpacing: true, // 是否在对象属性后添加空格
htmlWhitespaceSensitivity: 'ignore', // 优化html闭合标签不换行的问题
arrowParens: 'always', // 只有一个参数的箭头函数的参数是否带圆括号(默认avoid)
printWidth: 120, // 指定代码换行的行长度。单行代码宽度超过指定的最大宽度,将会换行,如果都不想换,可以添加 "proseWrap": "never"
}