Skip to content

Commit

Permalink
Merge pull request #732 from chef/ResourceOverridesProvidesMethod
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 authored Sep 2, 2020
2 parents 09fc220 + 6baf359 commit 13445df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ module ChefDeprecations
#
class ResourceOverridesProvidesMethod < Base
MSG = "Don't override the provides? method in a resource provider. Use provides :SOME_PROVIDER_NAME instead. This will cause failures in Chef Infra Client 13 and later."
RESTRICT_ON_SEND = [:provides?].freeze

def_node_search :provides, '(send nil? :provides ...)'

def on_def(node)
return unless node.method_name == :provides?

add_offense(node, message: MSG, severity: :warning) if provides(processed_source.ast).count == 0
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ def provides?
end
RUBY
end

it "doesn't register an offense with any old method" do
expect_no_offenses(<<~RUBY)
def foo
true
end
RUBY
end
end

0 comments on commit 13445df

Please sign in to comment.