1. 插件选择
- Vetur
作者:Pine Wu
描述:VUE工具包,支持多种语法,为每种语言提供分段高亮展示,语法检查,兼容所有主流css语法
插件链接:https://marketplace.visualstudio.com/items?itemName=octref.vetur
- Prettier - Code formatter
作者:Prettier
描述:格式化代码工具,以下格式均可处理
JavaScript · TypeScript · Flow · JSX · JSON
CSS · SCSS · Less
HTML · Vue · Angular
GraphQL · Markdown · YAML
插件链接:https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
- ESLint
作者:Dirk Baeumer
描述:JavaScript语法规则和代码风格的检查工具
插件链接:https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
2. 全局配置settings.json
{// tab 大小为2个空格"editor.tabSize": 2,// 100 列后换行"editor.wordWrapColumn": 100,// 保存时格式化"editor.formatOnSave": true,// 开启 vscode 文件路径导航"breadcrumbs.enabled": true,// prettier 设置语句末尾不加分号"prettier.semi": false,// prettier 设置强制单引号"prettier.singleQuote": true,// 选择 vue 文件中 template 的格式化工具"vetur.format.defaultFormatter.html": "prettyhtml",// 使能每一种语言默认格式化规则"editor.defaultFormatter": "esbenp.prettier-vscode",// html格式化规则"[html]": {"editor.defaultFormatter": "vscode.html-language-features"},// js格式化规则"[javascript]": {"editor.defaultFormatter": "esbenp.prettier-vscode"},// vue格式化规则"[vue]": {"editor.defaultFormatter": "octref.vetur"},// 显示 markdown 中英文切换时产生的特殊字符"editor.renderControlCharacters": true,// vetur 的自定义设置"vetur.format.defaultFormatterOptions": {"prettier": {"singleQuote": true,"semi": false}},"editor.codeActionsOnSave": {"source.fixAll.eslint": true},"workbench.colorTheme": "Community Material Theme","editor.suggestSelection": "first","vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue","workbench.startupEditor": "none","editor.quickSuggestions": {"strings": true}}
3.如果是Vue项目,配置.eslintrc.js
module.exports = {root: true,env: {node: true},extends: ["plugin:vue/essential"],rules: {"no-console": process.env.NODE_ENV === "production" ? "error" : "off","no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"},parserOptions: {parser: "babel-eslint"}};
4. 如果是Vue项目,配置.jsbeautifyrc
{"brace_style": "none,preserve-inline","indent_size": 2,"indent_char": " ","jslint_happy": true,"unformatted": [""],"css": {"indent_size": 2}}
