Class: RuboCop::Cop::Style::MagicCommentFormat::CommentRange
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
SimpleForwardable
|
|
Inherits: | Object |
Defined in: | lib/rubocop/cop/style/magic_comment_format.rb |
Overview
Value object to extract source ranges for the different parts of a magic comment
Constant Summary
-
DIRECTIVE_REGEXP =
# File 'lib/rubocop/cop/style/magic_comment_format.rb', line 110Regexp.union(MagicComment::KEYWORDS.map do |_, v| Regexp.new(v, Regexp::IGNORECASE) end).freeze
-
VALUE_REGEXP =
# File 'lib/rubocop/cop/style/magic_comment_format.rb', line 114Regexp.new("(?:#{DIRECTIVE_REGEXP}:\s*)(.*?)(?=;|$)")
Class Method Summary
- .new(comment) ⇒ CommentRange constructor
Instance Attribute Summary
- #comment readonly
Instance Method Summary
-
#directives
A magic comment can contain one directive (normal style) or multiple directives (emacs style).
-
#values
A magic comment can contain one value (normal style) or multiple directives (emacs style).
Constructor Details
.new(comment) ⇒ CommentRange
Instance Attribute Details
#comment (readonly)
[ GitHub ]# File 'lib/rubocop/cop/style/magic_comment_format.rb', line 117
attr_reader :comment
Instance Method Details
#directives
A magic comment can contain one directive (normal style) or multiple directives (emacs style)
# File 'lib/rubocop/cop/style/magic_comment_format.rb', line 125
def directives @directives ||= begin matches = [] text.scan(DIRECTIVE_REGEXP) do offset = Regexp.last_match.offset(0) matches << loc.expression.adjust(begin_pos: offset.first) .with(end_pos: loc.expression.begin_pos + offset.last) end matches end end
#values
A magic comment can contain one value (normal style) or multiple directives (emacs style)
# File 'lib/rubocop/cop/style/magic_comment_format.rb', line 141
def values @values ||= begin matches = [] text.scan(VALUE_REGEXP) do offset = Regexp.last_match.offset(1) matches << loc.expression.adjust(begin_pos: offset.first) .with(end_pos: loc.expression.begin_pos + offset.last) end matches end end