V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
meloncc
V2EX  ›  问与答

vscode 对 eslint-js 的格式化问题

  •  
  •   meloncc · 2020-04-26 15:29:20 +08:00 · 1419 次点击
    这是一个创建于 1432 天前的主题,其中的信息可能已经有所发展或是发生改变。

    背景:团队使用 eslint 格式化,保存自动 eslint-fix,大部分的人都正常,一个小伙子 js(项目使用 vue,在.vue 中的 js 可以正常格式化缩进)文件保存时会把缩进变成 8 个“Expected indentation of 4 spaces but found 8.”,系统环境是 windows 。

    现象:ctrl+s 触发而 elint 自动格式化有很明显的两次格式改变,第一次格式正常,紧接着会闪一下,由把格式变成 8 个 spaces 。

    看了他的 eslint 、.editconfig 、setting.json 配置和大家是一样,且格式化的操作代码格式正常,把语言选择为 javascriptreact 能正常使用 eslint 的自动格式化。有没有兄弟姐妹叔叔阿姨遇到过!

    4 条回复    2020-05-12 09:29:51 +08:00
    red2dog
        1
    red2dog  
       2020-04-26 16:01:07 +08:00
    看看他有没有装其他的格式化插件吧。 根据 你这个描述
    oreo
        2
    oreo  
       2020-05-10 17:58:23 +08:00
    Please also note that if you use ESLint as your default formatter you should turn off editor.formatOnSave when you have turned on editor.codeActionsOnSave. Otherwise you file gets fixed twice which in unnecessary.

    vscode-eslint 插件文档里写着,试试
    meloncc
        3
    meloncc  
    OP
       2020-05-12 09:29:10 +08:00
    @oreo 已经解决了,原因是这个小伙子装了其他插件,并且有默认配置,所以在配置文件没看出来(口区)
    meloncc
        4
    meloncc  
    OP
       2020-05-12 09:29:51 +08:00
    @red2dog 已经解决了,原因是这个小伙子装了其他插件,并且有默认配置,所以在配置文件没看出来(口区)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1179 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 18:18 · PVG 02:18 · LAX 11:18 · JFK 14:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.