【问题标题】:Ruby-Rubocop not working on vscodeRuby-Rubocop 不适用于 vscode
【发布时间】:2018-10-28 07:08:02
【问题描述】:

/Users/me/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in ``find_spec_for_exe': can't find gem rubocop (>= 0.a) with executable rubocop (Gem::GemNotFoundException) from /Users/me/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in ``activate_bin_path' from /Users/me/.rbenv/versions/2.5.1/bin/rubocop:23:in'

这是我每次输入内容时都会遇到的错误。有谁知道如何解决这个问题?

【问题讨论】:

  • 在命令行中运行rubocop 是否有效? which rubocop 的结果是什么?从命令行运行/Users/me/.rbenv/versions/2.5.1/bin/rubocop 是否有效?您是否尝试过重新安装 gem?
  • @TomLord hi, which rubocop 返回/Users/me/.rbenv/shims/rubocop 并从命令行运行 rubocop 命令并检查项目。

标签: debugging visual-studio-code rubocop


【解决方案1】:

经过许多痛苦的时间并阅读其他解决方案后,我终于推断出答案是从根目录安装 Rubocop。当我尝试时,以下步骤有效。 您首先需要进入终端中的 root。 安装 Rubocop 然后找到路径并将其添加到 Rubocop 设置中的执行路径中

$ cd ~
$ gem install rubocop
$ which rubocop
Paste location given in Ruby-Rubocop configuration settings > Execute Path
/Users/username/.rvm/gems/ruby-2.6.1/bin/

【讨论】:

  • rubocop 设置在哪里?我四处寻找设置所在的.yml 文件,但找不到。
【解决方案2】:

我可以为您提供 2 个解决方案,因为我遇到了同样的问题:

  • 为我安装 bundlersudo -> sudo gem install bundler 解决问题。

  • RubyGems 版本也可能是一个错误。似乎ruby -v2.5RubyGems -v2.7.3 存在兼容问题。所以尝试使用gem update --system 命令将RubyGems 升级到-v2.7.4

【讨论】:

  • 您的RubyGems 版本是什么?另外,您尝试安装的rubocop 版本是什么以及您使用的是什么操作系统?
  • RubyGems 是 2.7.7
  • 我正在寻找安装最新版本的 rubocop,可在 vscode 市场上获得
【解决方案3】:

对于下载 Ruby26-x64 并遇到相同问题的任何人。这可能是因为安装位置和您的 C://Users//you//whatever 不存在。为了解决这个问题,我简单地检查了 ruby​​ 安装在我的 C 驱动器上的位置。对我来说,它默认下载到我 C 盘上一个名为 Ruby26-x64 的文件中。打开文件夹转到 bin 并仔细检查某处是否有 rubocop.bat。将路径复制粘贴到 settings.json 中。应该看起来像这样。

"ruby.rubocop.executePath": "C:\\Ruby26-x64\\bin\\",

请注意,这是我在 Windows 10 上找到的解决方案,我不了解 Mac。

编辑:

Settings.json 可以通过转到 File>Preferences>Settings>Workbench 找到

在“Editor Associations”下,你会看到settings.json中有一个Edit按钮,打开你的settings.json文件有很多方法,这只是其中一种。

【讨论】:

    【解决方案4】:

    安装rubocop gem后gem install rubocop

    运行bundle install,然后再次运行rubcop。它对我有用。

    【讨论】:

      猜你喜欢
      • 2018-06-10
      • 2023-01-24
      • 2019-04-21
      • 2020-10-22
      • 2022-07-20
      • 2018-03-25
      • 2020-10-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多