Class: RuboCop::MagicComment::SimpleComment
- Inherits:
-
RuboCop::MagicComment
- Object
- RuboCop::MagicComment
- RuboCop::MagicComment::SimpleComment
- Defined in:
- lib/rubocop/magic_comment.rb
Overview
Wrapper for regular magic comments not bound to an editor.
Simple comments can only specify one setting per comment.
Constant Summary collapse
- FSTRING_LITERAL_COMMENT =
'frozen_string_literal:\s*(true|false)'
Constants inherited from RuboCop::MagicComment
Instance Method Summary collapse
-
#encoding ⇒ Object
Match ‘encoding` or `coding`.
- #new_frozen_string_literal(value) ⇒ Object
-
#without(type) ⇒ Object
Rewrite the comment without a given token type.
Methods inherited from RuboCop::MagicComment
#any?, #encoding_specified?, #frozen_string_literal, #frozen_string_literal?, #frozen_string_literal_specified?, #initialize, parse, #shareable_constant_value, #shareable_constant_value_specified?, #typed, #typed_specified?, #valid?, #valid_literal_value?, #valid_shareable_constant_value?
Constructor Details
This class inherits a constructor from RuboCop::MagicComment
Instance Method Details
#encoding ⇒ Object
Match ‘encoding` or `coding`
269 270 271 |
# File 'lib/rubocop/magic_comment.rb', line 269 def encoding extract(/\A\s*\#\s*(#{FSTRING_LITERAL_COMMENT})?\s*#{KEYWORDS[:encoding]}: (#{TOKEN})/io) end |
#new_frozen_string_literal(value) ⇒ Object
282 283 284 |
# File 'lib/rubocop/magic_comment.rb', line 282 def new_frozen_string_literal(value) "# frozen_string_literal: #{value}" end |
#without(type) ⇒ Object
Rewrite the comment without a given token type
274 275 276 277 278 279 280 |
# File 'lib/rubocop/magic_comment.rb', line 274 def without(type) if @comment.match?(/\A#\s*#{self.class::KEYWORDS[type.to_sym]}/io) '' else @comment end end |