vscode( vscode-ruby + rubocop ) 如何在保存时自动更正?

2024-06-23

环境

  • vscode 版本1.19.1 (1.19.1)
  • 鲁博科普 (0.52.1)
  • Darwin mbp 16.7.0 Darwin 内核版本 16.7.0:2017 年 10 月 4 日星期三 00:17:00 PDT;根:xnu-3789.71.6~1/RELEASE_X86_64 x86_64
  • ruby 2.3.5p376(2017-09-14 修订版 59905)[x86_64-darwin16]

已关注https://github.com/rubyide/vscode-ruby#linters https://github.com/rubyide/vscode-ruby#linters并安装了所有 gems 并像这样编辑了 settings.json 。

{

  "ruby.rubocop.executePath": "/Users/ac/.rbenv/shims/",
  "ruby.rubocop.onSave": true,
  "ruby.lint": {
    "ruby": {
      "unicode": true //Runs ruby -wc -Ku
    },
    "reek": true,
    "rubocop": {
      "lint": true,
      "rails": true
    },
    "fasterer": true,
    "debride": {
      "rails": true //Add some rails call conversions.
    },
    "ruby-lint": true
  },
  "ruby.locate": {
    "include": "**/*.rb",
    "exclude": "{**/@(test|spec|tmp|.*),**/@(test|spec|tmp|.*)/**,**/*_spec.rb}"
  }

}

在 vscode 上,代码高亮显示工作正常。
*请注意,您会在问题选项卡中看到已安装的扩展和警告。

Question

我的印象是vscode-ruby and rubocop会自动更正缩进和警察规则文件保存,但显然事实并非如此。
如果我希望它像这样格式化我的代码prettier,我应该如何设置?


Per 这条评论 https://github.com/misogi/vscode-ruby-rubocop/issues/49#issuecomment-417617844在 vscode-ruby-rubocop GitHub 上,您可以使用以下设置:

{
    "editor.formatOnSave": true,
    "editor.formatOnSaveTimeout": 5000,
    "ruby.rubocop.executePath": "path/where/rubocop/is/located",
    "ruby.format": "rubocop",
}

只需将它们应用到本地盒子上的用户设置中,它似乎就可以工作。 VS Code 为我抛出了一个错误ruby.rubocop.executePath设置说它不可执行,并且删除该行似乎不会导致该错误显示,并且仍然相应地格式化我的代码。设置较低的超时(我尝试过 2500)似乎也会破坏保存时的自动格式,因此我建议将其保留为 5000。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

vscode( vscode-ruby + rubocop ) 如何在保存时自动更正? 的相关文章

随机推荐