Ini*_*tyx 5 ruby string-literals rubocop
我使用的是 RuboCop 0.46.0 和 Ruby 2.3.1。
Style/FrozenStringLiteralComment:
EnforcedStyle: always
Run Code Online (Sandbox Code Playgroud)
# frozen_string_literal: true
MY_CONSTANT = 'mystring'
Run Code Online (Sandbox Code Playgroud)
运行时,rubocop -D返回:
Inspecting 1 file
C
Offenses:
constant.rb:3:15: C: Style/MutableConstant: Freeze mutable objects assigned to constants.
MY_CONSTANT = 'mystring'
^^^^^^^^^^
1 file inspected, 1 offense detected
Run Code Online (Sandbox Code Playgroud)
有没有理由 MutableConstant 没有观察我的冻结字符串文字注释?
并非每项检查都对所有 Ruby 版本都有意义。告诉 RuboCop 要检查的 Ruby 版本。
将以下内容添加到您的.rubocop.yml:
AllCops:
TargetRubyVersion: 2.3
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
571 次 |
| 最近记录: |