首页 > 解决方案 > 在 VSCode 终端中在 Win 10 上运行 rake 任务会添加一个默认的 -w 标志

问题描述

我不完全确定这是如何发生的或如何更改设置,但现在当我运行

rake <name_of_task>

可执行文件显示了这一点:

C:/Ruby30-x64/bin/ruby.exe -w -I"lib" C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/rake_test_loader.rb "<the dir of the test and filename>"

...然后似乎给 Ruby.exe 命令标志-w,它在终端中将代码格式化警告显示为 STDout,例如:

warning: mismatched indentations at 'end' with 'def' at 8

这一切都很好,因为它是 STDout,所以它不会写入我们的日志,但它会使 VScode 终端中的调试变得疯狂,因为现在有 100 条这样的警告。

更奇怪的是,当我的同事运行相同的代码时,他们现在得到的输出相同。除非 Rake 中存在错误,否则我不确定这怎么可能?

另一件事是,当您运行直接 ruby​​ 测试(使用 minitest)时,它根本不会显示此输出。那么有没有其他人使用rake-13.0.3gem 看到过这个?

标签: rubyvisual-studio-coderakeminitest

解决方案


好吧 - 想通了。

rake默认warningtrue,向 Ruby 可执行文件添加一个-w标志。

如何修复的示例:

Rake::TestTask.new("<task_name>") do |t|
  t.test_files = FileList["test/<file.rb>"]
  t.warning = false   <-- must be false to remove -w flag
end

推荐阅读