首页 > 解决方案 > 为什么在 Windows 10 pro 中而不是在 Mac 中出现 rubocop 违规(C:检测到回车字符)?

问题描述

下面的代码:

def fix(value)
  value << 'xyz'
  value = value.upcase
  value.concat('!')
end

s = 'hello'
t = fix(s)

puts s
puts t

在 mac 中没有显示任何 rubocop 攻击,但显示

C: Carriage return character detected
def fix(value) ...
^^^^^^^^^^^^^^

在 Windows 10 专业版中。

标签: rubywindowsrubocop

解决方案


Unix 和 Windows 使用不同的字符来表示换行符。Unix 使用line feed( "\n"),而 Windows 使用carriage return + line feed( "\r\n")。

只需将 Windows 机器上的 IDE 配置为仅使用 Unix 版本即可。


推荐阅读