I'm using RuboCop 0.46.0 and Ruby 2.3.1.
Style/FrozenStringLiteralComment:
EnforcedStyle: always
# frozen_string_literal: true
MY_CONSTANT = 'mystring'
When run, rubocop -D
returns this:
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
Is there a reason MutableConstant isn't observing my frozen string literal comment?
Not every check makes sense for all Ruby versions. Tell RuboCop the Ruby version to check against.
Add the following to your .rubocop.yml
:
AllCops:
TargetRubyVersion: 2.3