Foodcritic / foodcritic

Lint tool for Chef cookbooks.
http://foodcritic.io
MIT License
408 stars 153 forks source link

Foodcritic whining for FC048: Prefer Mixlib::ShellOut: #773

Closed Doltair closed 6 years ago

Doltair commented 6 years ago

My code block:

cmd = Mixlib::ShellOut.new("/usr/bin/echo test",
    user: (node['webhook_api']['app_username']).to_s)
    cmd.run_command

Then foodcritic stops whining when change to Mixlib::Shellout: but my code converge will fail.

Help.. Thank you

coderanger commented 6 years ago

That rule on triggers if you are using x string literals (include backticks) or the Ruby system function. You shouldn't use that anyway, use the shell_out() helper method.

Doltair commented 6 years ago

Thanks! @coderanger. Anyhow i have retained using Mixlib::ShellOut.new

Mixlib::ShellOut.new("/usr/bin/echo \"ActiveRecord::Base.logger.level = :error; ~> code snipped

and added escape sequences then removed backticks(replaced back ""). I've tried however using shell_out() but it throws me a readline require error (in a weird way) so i went back to Mixlib::ShellOut.new and it executes the cmd fine.

Overall the foodcritic stops whining and passed the tests.