Class: Reek::Smells::UncommunicativeModuleName Private
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::UncommunicativeModuleName
- Defined in:
- lib/reek/smells/uncommunicative_module_name.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 UncommunicativeModuleName
checks for
-
1-character names
-
names ending with a number
See Uncommunicative-Module-Name for details.
Constant Summary collapse
- REJECT_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The name of the config field that lists the regexps of smelly names to be reported.
'reject'
- DEFAULT_REJECT_SET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[/^.$/, /[0-9]$/]
- ACCEPT_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The name of the config field that lists the specific names that are to be treated as exceptions; these names will not be reported as uncommunicative.
'accept'
- DEFAULT_ACCEPT_SET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
['Inline::C']
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from SmellDetector
Class Method Summary collapse
-
.contexts ⇒ Object
private
:nodoc:.
- .default_config ⇒ Object private
- .smell_category ⇒ Object private
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Array<SmellWarning>
private
Checks the given
context
for uncommunicative names.
Methods inherited from SmellDetector
#config_for, #configure_with, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, #smell_category, smell_type, #smell_type, #value
Constructor Details
This class inherits a constructor from Reek::Smells::SmellDetector
Class Method Details
.contexts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
44 45 46 |
# File 'lib/reek/smells/uncommunicative_module_name.rb', line 44 def self.contexts # :nodoc: [:module, :class] end |
.default_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 40 41 42 |
# File 'lib/reek/smells/uncommunicative_module_name.rb', line 37 def self.default_config super.merge( REJECT_KEY => DEFAULT_REJECT_SET, ACCEPT_KEY => DEFAULT_ACCEPT_SET ) end |
.smell_category ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/reek/smells/uncommunicative_module_name.rb', line 33 def self.smell_category 'UncommunicativeName' end |
Instance Method Details
#examine_context(ctx) ⇒ Array<SmellWarning>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks the given context
for uncommunicative names.
:reek:Duplication { allow_calls: [ to_s ] }
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/reek/smells/uncommunicative_module_name.rb', line 54 def examine_context(ctx) @reject_names = value(REJECT_KEY, ctx, DEFAULT_REJECT_SET) @accept_names = value(ACCEPT_KEY, ctx, DEFAULT_ACCEPT_SET) exp = ctx.exp full_name = ctx.full_name name = exp.simple_name.to_s return [] if @accept_names.include?(full_name) var = name.gsub(/^[@\*\&]*/, '') return [] if @accept_names.include?(var) return [] unless @reject_names.find { |patt| patt =~ var } [SmellWarning.new(self, context: full_name, lines: [exp.line], message: "has the name '#{name}'", parameters: { name: name })] end |