forked from troessner/reek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility_function.rb
33 lines (30 loc) · 926 Bytes
/
utility_function.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'reek/smells/smell_detector'
require 'reek/smell_warning'
module Reek
module Smells
#
# A Utility Function is any instance method that has no
# dependency on the state of the instance.
#
# Currently +UtilityFunction+ will warn about any method that:
#
# * is non-empty
# * does not override an inherited method
# * calls at least one method on another object
# * doesn't use any of self's instance variables
# * doesn't use any of self's methods
#
class UtilityFunction < SmellDetector
#
# Checks whether the given +method+ is a utility function.
# Remembers any smells found.
#
def examine_context(method)
return false if method.calls.keys.length == 0 or
method.num_statements == 0 or
method.depends_on_instance?
found(method, "doesn't depend on instance state")
end
end
end
end