Class: ImproveYourCode::CodeComment

Inherits:
Object
  • Object
show all
Defined in:
lib/improve_your_code/code_comment.rb

Constant Summary collapse

CONFIGURATION_REGEX =
/
 :improve_your_code: # prefix
 (\w+)  # smell detector e.g.: UncommunicativeVariableName
 (
   :? # legacy separator
   \s*
   (\{.*?\}) # optional details in hash style e.g.: { max_methods: 30 }
 )?
/x
SANITIZE_REGEX =

Matches ‘#’, newlines and > 1 whitespaces.

/(#|\n|\s)+/
DISABLE_DETECTOR_CONFIGURATION =
'{ enabled: false }'
MINIMUM_CONTENT_LENGTH =
2
LEGACY_SEPARATOR =
':'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comment:, line: nil, source: nil) ⇒ CodeComment

Returns a new instance of CodeComment.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/improve_your_code/code_comment.rb', line 25

def initialize(comment:, line: nil, source: nil)
  @original_comment  = comment
  @line              = line
  @source            = source
  @config            = Hash.new { |hash, key| hash[key] = {} }

  @original_comment.scan(CONFIGURATION_REGEX) do |detector_name, _option_string, options|
    @config.merge! detector_name => YAML.safe_load(options || DISABLE_DETECTOR_CONFIGURATION,
      [Regexp])
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



23
24
25
# File 'lib/improve_your_code/code_comment.rb', line 23

def config
  @config
end

Instance Method Details

#descriptive?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/improve_your_code/code_comment.rb', line 37

def descriptive?
  sanitized_comment.split(/\s+/).length >= MINIMUM_CONTENT_LENGTH
end