Feature #10168
openNative Object#inspect method should single quote strings that don't need to be double quoted
Description
When these strings get printed, copied and pasted into source code, RuboCop will complain, eg:
spec/recipes/default_spec.rb:23:24: C: Prefer single-quoted strings when you don't need string interpolation or special symbols.
stub_data_bag_item("jenkins-cluster", "default").and_return(
^^^^^^^^^^^^^^^^^
which resulted from the following code
signature = "#{type}(#{options[:args].map(&:inspect).join(', ')})"
If we believe that the default rules for RuboCop are good then it seems to me that they should be applied by Ruby where appropriate. In this case the strings should be single quoted.
From my point of view this is a suggestion to increase overall productivity as I use tools that use this method to print things that I then copy and paste quite a bit - not having to then replace the quotes will save me time. Not using or always changing the defaults for RuboCop seems to be the wrong approach
Updated by jwmittag (Jörg W Mittag) almost 9 years ago
Peter Halliday wrote:
From my point of view this is a suggestion to increase overall productivity as I use tools that use this method to print things that I then copy and paste quite a bit - not having to then replace the quotes will save me time. Not using or always changing the defaults for RuboCop seems to be the wrong approach
The output of #inspect
is intended for reading by humans, not machines. The format is not specified, and not guaranteed to be stable. In particular, the output of #inspect
is not intended and not guaranteed to even be parseable at all, let alone conform to some arbitrary rules from some arbitrary third-party style checker.
If you want serialization, use serialization. If you want round-trippable source code, such that some_object == eval(some_object.some_method)
, that's an interesting proposal, but #inspect
is not that method.