Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect additional ways to shellout to apt-get update #670

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rubocop/cop/chef/modernize/execute_apt_update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ExecuteAptUpdate < Cop
MSG = 'Use the apt_update resource instead of the execute resource to run an apt-get update package cache update'.freeze

def_node_matcher :execute_apt_update?, <<-PATTERN
(send nil? :execute (str "apt-get update"))
(send nil? :execute (str { "apt-get update" "apt-get update -y" "apt-get -y update" }))
PATTERN

def_node_matcher :notification_property?, <<-PATTERN
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/chef/modernize/execute_apt_update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@
RUBY
end

it 'registers an offense when using execute to run apt-get update -y' do
expect_offense(<<~RUBY)
execute 'apt-get update -y' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the apt_update resource instead of the execute resource to run an apt-get update package cache update
action :nothing
end
RUBY
end

it 'registers an offense when using execute to run apt-get -y update' do
expect_offense(<<~RUBY)
execute 'apt-get -y update' do
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use the apt_update resource instead of the execute resource to run an apt-get update package cache update
action :nothing
end
RUBY
end

it "registers an offense when a resource notifies 'execute[apt-get update]'" do
expect_offense(<<~RUBY)
execute 'some execute resource' do
Expand Down