Class: Reek::CodeComment
- Inherits:
-
Object
- Object
- Reek::CodeComment
- Defined in:
- lib/reek/code_comment.rb
Overview
A comment header from an abstract syntax tree; found directly above module, class and method definitions.
Defined Under Namespace
Classes: CodeCommentValidator
Constant Summary collapse
- CONFIGURATION_REGEX =
/ :reek: # prefix (\w+) # smell detector e.g.: UncommunicativeVariableName (:?\s*) # separator (\{.*?\})? # 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
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#line ⇒ Object
readonly
private
Returns the value of attribute line.
-
#original_comment ⇒ Object
readonly
private
Returns the value of attribute original_comment.
-
#source ⇒ Object
readonly
private
Returns the value of attribute source.
Instance Method Summary collapse
- #descriptive? ⇒ Boolean
- #escalate_legacy_separator(separator) ⇒ Object private
-
#initialize(comment:, line: nil, source: nil) ⇒ CodeComment
constructor
A new instance of CodeComment.
- #sanitized_comment ⇒ Object private
Constructor Details
#initialize(comment:, line: nil, source: nil) ⇒ CodeComment
Returns a new instance of CodeComment.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/reek/code_comment.rb', line 34 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, separator, | escalate_legacy_separator separator validator = CodeCommentValidator.new(detector_name: detector_name, original_comment: original_comment, line: line, source: source, options: ) validator.validate @config.merge! detector_name => validator. end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/reek/code_comment.rb', line 27 def config @config end |
#line ⇒ Object (readonly, private)
Returns the value of attribute line.
58 59 60 |
# File 'lib/reek/code_comment.rb', line 58 def line @line end |
#original_comment ⇒ Object (readonly, private)
Returns the value of attribute original_comment.
58 59 60 |
# File 'lib/reek/code_comment.rb', line 58 def original_comment @original_comment end |
#source ⇒ Object (readonly, private)
Returns the value of attribute source.
58 59 60 |
# File 'lib/reek/code_comment.rb', line 58 def source @source end |
Instance Method Details
#descriptive? ⇒ Boolean
52 53 54 |
# File 'lib/reek/code_comment.rb', line 52 def descriptive? sanitized_comment.split(/\s+/).length >= MINIMUM_CONTENT_LENGTH end |
#escalate_legacy_separator(separator) ⇒ Object (private)
67 68 69 70 71 72 73 |
# File 'lib/reek/code_comment.rb', line 67 def escalate_legacy_separator(separator) return unless separator.start_with? ':' raise Errors::LegacyCommentSeparatorError.new(original_comment: original_comment, source: source, line: line) end |
#sanitized_comment ⇒ Object (private)
60 61 62 63 64 65 |
# File 'lib/reek/code_comment.rb', line 60 def sanitized_comment @sanitized_comment ||= original_comment. gsub(CONFIGURATION_REGEX, ''). gsub(SANITIZE_REGEX, ' '). strip end |