Webstorm 格式化配置适配 Vscode

我在使用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 parenthesesIn 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'
      }
    }
  ]
  ...
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容