class Reek::SmellDetectors::UncommunicativeMethodName
An Uncommunicative Name is a name that doesn’t communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what’s going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.
Currently UncommunicativeMethodName
checks for
-
1-character names
-
names ending with a number
-
names containing a capital letter (assuming camelCase)
See {file:docs/Uncommunicative-Method-Name.md} for details.
Constants
- ACCEPT_KEY
- DEFAULT_ACCEPT_PATTERNS
- DEFAULT_REJECT_PATTERNS
- REJECT_KEY
Public Class Methods
Source
# File lib/reek/smell_detectors/uncommunicative_method_name.rb, line 28 def self.default_config super.merge( REJECT_KEY => DEFAULT_REJECT_PATTERNS, ACCEPT_KEY => DEFAULT_ACCEPT_PATTERNS) end
Calls superclass method
Reek::SmellDetectors::BaseDetector::default_config
Public Instance Methods
Source
# File lib/reek/smell_detectors/uncommunicative_method_name.rb, line 39 def sniff name = context.name.to_s return [] if acceptable_name?(name) [smell_warning( lines: [source_line], message: "has the name '#{name}'", parameters: { name: name })] end
Checks the given context
for uncommunicative names.
@return [Array<SmellWarning>]
Private Instance Methods
Source
# File lib/reek/smell_detectors/uncommunicative_method_name.rb, line 60 def accept_patterns Array value(ACCEPT_KEY, context) end
Source
# File lib/reek/smell_detectors/uncommunicative_method_name.rb, line 51 def acceptable_name?(name) accept_patterns.any? { |accept_pattern| name.match accept_pattern } || reject_patterns.none? { |reject_pattern| name.match reject_pattern } end
Source
# File lib/reek/smell_detectors/uncommunicative_method_name.rb, line 56 def reject_patterns Array value(REJECT_KEY, context) end