If you give a constant a name that is not in SCREAMING_SNAKE_CASE the cop _Naming/ConstantName_ raises an offence. If you then .freeze that constant the offence is not detected.
I expect Rubocop's _Naming/ConstantName_ cop to raise an offence for a mis-named constant whether the constant is frozen or not.
If the mis-named constant is frozen with .freeze the _Naming/ConstantName_ offence is not detected.
my_class.rb as follows:class MyClass
MyConstant = "x"
end
$ rubocop my_class.rb
Inspecting 1 file
C
Offenses:
tmp/my_class.rb:2:3: C: Naming/ConstantName: Use SCREAMING_SNAKE_CASE for constants. (https://github.com/bbatsov/ruby-style-guide#screaming-snake-case)
MyConstant = "x"
^^^^^^^^^^
tmp/my_class.rb:2:16: C: Style/MutableConstant: Freeze mutable objects assigned to constants.
MyConstant = "x"
^^^
class MyClass
MyConstant = "x".freeze
end
$ rubocop my_class.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
Include the output of rubocop -V. Here's an example:
$ rubocop -V
0.51.0 (using Parser 2.4.0.2, running on ruby 2.2.2 x86_64-darwin16)
Most helpful comment
The cause:
https://github.com/bbatsov/rubocop/blob/4a0d6361d0065ca16ba19bdf3b3d6c4623e14adc/lib/rubocop/cop/naming/constant_name.rb#L27-L31