Sho*_*TGM 4 ruby rubocop visual-studio-code
最近我在vscode上安装了rubocop。但是,它不起作用。错误消息如下。
rubocop is not excutable
execute path is empty! please check ruby.rubocop.executePath
Run Code Online (Sandbox Code Playgroud)
我应该如何解决?我搜索了一些文章,但从未解决...
cf. vscode-ruby-rubocop https://github.com/misogi/vscode-ruby-rubocop
IAm*_*NaN 11
简短回答:尝试以不同的方式启动 VSCode。
解释:进程继承其启动时的所有环境配置。如果 rubocop 安装在您的全局环境中,那么,无论您如何启动 VSCode,rubocop 都将可供该插件使用。不利的一面是,rubocop 现在可供所有事物使用,其中大多数永远不需要它,并且所有使用它的事物都需要相同版本的 rubocop。
如果 rubocop 使用 ruby 管理器安装在 gemset 中,或者您有类似点文件管理器之类的东西来操纵您的环境,那么当您启动 VSCode 时,rubocop 可能不在 PATH 中。
我总是从终端启动 VSCode。我打开一个终端并cd进入我的项目文件夹。我的 ruby 管理器(rvm)和点文件管理器(direnv)自动添加和更改环境中的一些变量。然后我运行code .VSCode 来启动我的项目。这可确保 VSCode 在与我的应用程序运行相同的环境配置中运行。
Make sure you installed Rubocop in the first place.
gem install rubocop
Run Code Online (Sandbox Code Playgroud)
You can check that it works properly like this:
rubocop -v
Run Code Online (Sandbox Code Playgroud)
Search for ruby-rubocop in the marketplace and install it.
Add a .rubocop.yml file to your project's root. You can see all the configuration options and how such a file should look like in the default config file. Be aware that if there are outdated or wrong rules in the file, you will get an error and Rubocop won't work. VS Code will alert you about this:
看一下配置文档。
{
// If not specified searches for 'rubocop' executable available on PATH (default and recommended)
"ruby.rubocop.executePath": "",
...
}
Run Code Online (Sandbox Code Playgroud)
因此,默认情况下executePath不会进行设置,因为它期望您在PATH中包含rubocop可执行文件。
通过简单的方法,您可以做两件事,将rubocop可执行文件路径添加到PATH,或在包选项中添加它。
您可以使用which rubocop(然后复制并粘贴)检查rubocop可执行目录。
接受的答案对我不起作用。但是,我没有找到一个评论jdarnok对这个GitHub的问题,对我的工作。
首先,我获取了程序文件的用户路径:
rbenv which rubocop
这给了我这个结果:
/Users/johnstewart/.rbenv/versions/2.6.2/gemsets/Rails4.2_EnergyLink/bin/rubocop
然后我跑了:
which rubocop
这给了我这个结果:
/Users/johnstewart/.rbenv/shims/rubocop
解
在Ruby > Rubocop: Execute Path我粘贴的VS Code的设置中:
/Users/johnstewart/.rbenv/shims/
其他潜在解决方案
该Stackoverflow帖子还引用了其他一些潜在的解决方案,例如:
bin在PATH中替换为wrappersexecutable hooks| 归档时间: |
|
| 查看次数: |
6454 次 |
| 最近记录: |