ruby - 为什么在 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 专业版中。
解决方案
Unix 和 Windows 使用不同的字符来表示换行符。Unix 使用line feed
( "\n"
),而 Windows 使用carriage return + line feed
( "\r\n"
)。
只需将 Windows 机器上的 IDE 配置为仅使用 Unix 版本即可。
推荐阅读
- swift - Swift 不按顺序运行
- arrays - 如何将 perl assc 数组指向简单数组并推送新值?
- python - 按字幕语言搜索 Itunes API
- ruby-on-rails - 如何在视图中使用来自另一个控制器的控制器辅助方法?
- java - 如何使用 HbaseTemplate “findAllBy{Column}”?
- javascript - 在 HTML 中“即时”进行更改的过程背后是什么?
- c# - 为 google 任务设置 ShowCompleted
- mysql - 在一列中多次存储多个值?
- python - 试图理解为什么创建和操纵期货是一种不好的做法
- mysql - Rails db:在生产环境中迁移默认为本地套接字连接