Class: RuboCop::MagicComment Abstract
- Inherits:
-
Object
- Object
- RuboCop::MagicComment
- Defined in:
- lib/rubocop/magic_comment.rb
Overview
parent of three different magic comment handlers
Parse different formats of magic comments.
Direct Known Subclasses
Defined Under Namespace
Classes: EditorComment, EmacsComment, SimpleComment, VimComment
Constant Summary collapse
- TOKEN =
/[[:alnum:]\-_]+/
Class Method Summary collapse
-
.parse(comment) ⇒ RuboCop::MagicComment
Detect magic comment format and pass it to the appropriate wrapper.
Instance Method Summary collapse
- #any? ⇒ Boolean
- #encoding_specified? ⇒ Boolean
-
#frozen_string_literal ⇒ Boolean, ...
Expose the ‘frozen_string_literal` value coerced to a boolean if possible.
-
#frozen_string_literal? ⇒ Boolean
Does the magic comment enable the frozen string literal feature.
-
#frozen_string_literal_specified? ⇒ Boolean
Was a magic comment for the frozen string literal found?.
-
#initialize(comment) ⇒ MagicComment
constructor
A new instance of MagicComment.
Constructor Details
#initialize(comment) ⇒ MagicComment
Returns a new instance of MagicComment.
25 26 27 |
# File 'lib/rubocop/magic_comment.rb', line 25 def initialize(comment) @comment = comment end |
Class Method Details
.parse(comment) ⇒ RuboCop::MagicComment
Detect magic comment format and pass it to the appropriate wrapper.
16 17 18 19 20 21 22 23 |
# File 'lib/rubocop/magic_comment.rb', line 16 def self.parse(comment) case comment when EmacsComment::FORMAT then EmacsComment.new(comment) when VimComment::FORMAT then VimComment.new(comment) else SimpleComment.new(comment) end end |
Instance Method Details
#any? ⇒ Boolean
29 30 31 |
# File 'lib/rubocop/magic_comment.rb', line 29 def any? frozen_string_literal_specified? || encoding_specified? end |
#encoding_specified? ⇒ Boolean
68 69 70 |
# File 'lib/rubocop/magic_comment.rb', line 68 def encoding_specified? specified?(encoding) end |
#frozen_string_literal ⇒ Boolean, ...
Expose the ‘frozen_string_literal` value coerced to a boolean if possible.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubocop/magic_comment.rb', line 57 def frozen_string_literal return unless (setting = extract_frozen_string_literal) case setting when 'true' then true when 'false' then false else setting end end |
#frozen_string_literal? ⇒ Boolean
Does the magic comment enable the frozen string literal feature.
Test whether the frozen string literal value is ‘true`. Cannot just return `frozen_string_literal` since an invalid magic comment like `# frozen_string_literal: yes` is possible and the truthy value `’yes’‘ does not actually enable the feature
41 42 43 |
# File 'lib/rubocop/magic_comment.rb', line 41 def frozen_string_literal? frozen_string_literal == true end |
#frozen_string_literal_specified? ⇒ Boolean
Was a magic comment for the frozen string literal found?
48 49 50 |
# File 'lib/rubocop/magic_comment.rb', line 48 def frozen_string_literal_specified? specified?(frozen_string_literal) end |