Class: ImproveYourCode::SmellDetectors::UncommunicativeModuleName

Inherits:
BaseDetector
  • Object
show all
Defined in:
lib/improve_your_code/smell_detectors/uncommunicative_module_name.rb

Constant Summary collapse

REJECT_KEY =
'reject'
DEFAULT_REJECT_PATTERNS =
[/^.$/, /[0-9]$/].freeze
ACCEPT_KEY =
'accept'
DEFAULT_ACCEPT_PATTERNS =
[].freeze

Constants inherited from BaseDetector

BaseDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from BaseDetector

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDetector

configuration_keys, descendants, inherited, #initialize, #run, #smell_type, smell_type, to_detector, todo_configuration_for, valid_detector?

Constructor Details

This class inherits a constructor from ImproveYourCode::SmellDetectors::BaseDetector

Class Method Details

.contextsObject



20
21
22
# File 'lib/improve_your_code/smell_detectors/uncommunicative_module_name.rb', line 20

def self.contexts
  %i[module class]
end

.default_configObject



13
14
15
16
17
18
# File 'lib/improve_your_code/smell_detectors/uncommunicative_module_name.rb', line 13

def self.default_config
  super.merge(
    REJECT_KEY => DEFAULT_REJECT_PATTERNS,
    ACCEPT_KEY => DEFAULT_ACCEPT_PATTERNS
  )
end

Instance Method Details

#sniffObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/improve_your_code/smell_detectors/uncommunicative_module_name.rb', line 24

def sniff
  fully_qualified_name = context.full_name
  module_name          = expression.simple_name

  return [] if acceptable_name?(
    module_name: module_name,
    fully_qualified_name: fully_qualified_name
  )

  [
    smell_warning(
      context: context,
      lines: [source_line],
      message: "has the name '#{module_name}'",
      parameters: { name: module_name }
    )
  ]
end