Class: RuboCop::DirectiveComment
- Inherits:
-
Object
- Object
- RuboCop::DirectiveComment
- Defined in:
- lib/rubocop/directive_comment.rb
Overview
This class wraps the ‘Parser::Source::Comment` object that represents a special `rubocop:disable` and `rubocop:enable` comment and exposes what cops it contains.
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
Instance Method Summary collapse
-
#cops ⇒ Object
Return all the cops specified in the directive.
-
#initialize(comment) ⇒ DirectiveComment
constructor
A new instance of DirectiveComment.
-
#match?(cop_names) ⇒ Boolean
Checks if this directive contains all the given cop names.
- #range ⇒ Object
Constructor Details
#initialize(comment) ⇒ DirectiveComment
Returns a new instance of DirectiveComment.
10 11 12 |
# File 'lib/rubocop/directive_comment.rb', line 10 def initialize(comment) @comment = comment end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
8 9 10 |
# File 'lib/rubocop/directive_comment.rb', line 8 def comment @comment end |
Instance Method Details
#cops ⇒ Object
Return all the cops specified in the directive
15 16 17 18 19 20 21 |
# File 'lib/rubocop/directive_comment.rb', line 15 def cops match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP) return unless match cops_string = match.captures[1] cops_string.split(/,\s*/).uniq.sort end |
#match?(cop_names) ⇒ Boolean
Checks if this directive contains all the given cop names
24 25 26 |
# File 'lib/rubocop/directive_comment.rb', line 24 def match?(cop_names) cops == cop_names.uniq.sort end |
#range ⇒ Object
28 29 30 |
# File 'lib/rubocop/directive_comment.rb', line 28 def range comment.location.expression end |