Rubocop 警告:Style/EndOfLine 有错误的命名空间

Rubocop warning: Style/EndOfLine has the wrong namespace

我在 Windows 平台下使用 Ruby。解决 "Carriage return character missing" rubocop 违规行为,我在项目的根目录中创建了文件 .rubocop.yml

Style/EndOfLine:
  EnforcedStyle: lf

这解决了我的 "Carriage return" 问题。但是出现了新的警告:

~/project/.rubocop.yml:Style/EndOfLine has the wrong namespace - should be Layout

"wrong namespace - should be Layout"是什么意思?目前我不知道去哪里修复它。

Layout/EndOfLine,不是Style/EndOfLine/ 之前的部分是命名空间。

看来您需要缩进第二行:

Style/EndOfLine:
  EnforcedStyle: lf

要删除此警告需要使用 Layout/EndOfLine 而不是 Style/EndOfLine。 EndOfLine 是一个 rubucop cop 负责检测与缩进相关的违规行为,因为它位于 Layout 部门。

  Layout/EndOfLine:
    EnforcedStyle: lf

有趣的是,为什么在 this comment 中关于修复 "Carriage return character missing" 建议使用 Style/EndOfLine。这是相对较新的文章和评论。看起来自 4 月以来,rubocop 中添加了一些更改。

我在 Windows 10 上使用 RubyMine,我的 .rubocop.yml 包括以下内容:

Layout/EndOfLine:
    EnforcedStyle: lf

如果我从命令行 运行 Rubocop,那么我会标记第 1 行,但在 RubyMine 中没有突出显示错误。

如果我将 .rubocop.yml 更改为:

Layout/Endofline:
    EnforcedStyle: crlf

然后我从命令行中没有得到任何错误 运行,但是每个文件的第一行都被 RuboCop 在 RubyMine 中高亮显示