rodjek / puppet-lint

Check that your Puppet manifests conform to the style guide
MIT License
819 stars 204 forks source link

WARNING: double quoted string containing no variables #895

Closed mitchdubdub closed 5 years ago

mitchdubdub commented 5 years ago

We started receiving failures on the new version of puppet-lint, we are getting a warning " WARNING: double quoted string containing no variables"

onlyif => "test $( subscription-manager refresh >/dev/null 2>&1; echo $? ) -ne 0 ",

It seems to follow the style guide for quotes.

https://puppet.com/docs/puppet/6.4/style_guide.html#quoting

puppet-lint 2.3.6 manifests/subscription_manager.pp

puppet-lint 2.4.1 manifests/subscription_manager.pp WARNING: double quoted string containing no variables on line 19 WARNING: double quoted string containing no variables on line 36

dioni21 commented 5 years ago

The warning is correct! There are NO PUPPET variables inside string. You should use single quotes.

BTW, Why complicate? Just use:

unless => 'subscription-manager refresh >/dev/null 2>&1',

rodjek commented 5 years ago

Hi @mitchdubdub,

As @dioni21 mentioned, this is actually the expected behaviour.

Looking at how that string was tokenised in 2.3.6, the lack of a warning previously was the result of an unknown bug that caused the string to be tokenised into multiple tokens rather than the single :STRING token that it should have been.

[
  <Token :DQPRE (test ) @1:2>,
  <Token :DQMID ($) @1:7>,
  <Token :DQMID (( subscription-manager refresh >/dev/null 2>&1; echo ) @1:9>,
  <Token :DQMID ($) @1:61>, <Token :DQPOST (? ) -ne 0 ) @1:63>
]

You are correct that the style guide says that this should be valid, but puppet-lint was written at a time when the style guide only preferred the use of single quotes and has not been updated to support the preference of double quotes.

mitchdubdub commented 5 years ago

Thanks. We'll fix our code.