admin管理员组

文章数量:1613937

 

我在使用webstorm做开发几年后,碰见了喜欢使用vscode的同事一起开发,但是出现了代码格式化不一致问题,这里我记录了我解决webstorm格式化适用vscode

  • 禁用script标签后export缩进问题
    在 webstorm 配置中 找到 code style -> HTML -> other -> Do not indent children of 中添加 script 标签

  • 字符串使用双引号,以及分号结尾
    code style -> Javascript -> Punctuation ->

use semicolon to terminate statement always
use double quotes always
Trailing comma Remove
  • 定义方法后和括号之间无空格
    code style -> Javascript -> Space -> Before Parentheses -> 取消勾选 Function declaretion parentheses 和 In function expression

  • 对象花括号和中间键值需要有空格
    code style -> Javascript -> Space -> Within -> 勾选Object literal braces

我对应的eslint配置

{
  ...
  // add your custom rules here
  rules: {
    // allow async-await
    'generator-star-spacing': 'off',
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    // script的下一行缩进2格
    // 'vue/script-indent': ['error', 0, {'baseIndent': 1, 'switchCase': 1}],
    // 允许空一行,为了阅读方便
    'no-trailing-spaces': [1, { 'skipBlankLines': true }],
    // 全等
    'eqeqeq': 0,
    // 关闭行末分号提示/报错
    'semi': 0,
    // 字符串尽可能使用双引号
    'quotes': [0, "double"],
    // 函数定义时括号前面要不要有空格
    "space-before-function-paren": [0, "always"]
  },
  overrides: [
    {
      'files': ['*.vue'],
      'rules': {
        'indent': 'off'
      }
    }
  ]
  ...
}

 

转载:
https://www.jianshu/p/7f448e90f72f

本文标签: 代码WebStormVSCode