Class: RuboCop::MagicComment::SimpleComment
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
MagicComment
|
|
|
Instance Chain:
self,
MagicComment
|
|
| Inherits: |
MagicComment
|
| 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
-
FSTRING_LITERAL_COMMENT =
# File 'lib/rubocop/magic_comment.rb', line 282'frozen_string_literal:\s*(true|false)'
Instance Method Summary
-
#encoding
Match #encoding or
coding. - #new_frozen_string_literal(value)
-
#without(type)
Rewrite the comment without a given token type.
-
#extract_frozen_string_literal
private
Extract #frozen_string_literal.
- #extract_rbs_inline_value private
- #extract_shareable_constant_value private
- #extract_typed private
Instance Method Details
#encoding
Match encoding or coding
# File 'lib/rubocop/magic_comment.rb', line 285
def encoding extract(/\A\s*\#\s*(#{FSTRING_LITERAL_COMMENT})?\s*#{KEYWORDS[:encoding]}: (#{TOKEN})/io) end
#extract_frozen_string_literal (private)
The RuboCop::MagicComment#frozen_string_literal magic comment only works if it is the only text in the comment.
Case-insensitive and dashes/underscores are acceptable.
# File 'lib/rubocop/magic_comment.rb', line 311
def extract_frozen_string_literal extract(/\A\s*#\s*#{KEYWORDS[:frozen_string_literal]}:\s*#{TOKEN}\s*\z/io) end
#extract_rbs_inline_value (private)
[ GitHub ]#extract_typed (private)
[ GitHub ]#new_frozen_string_literal(value)
[ GitHub ]# File 'lib/rubocop/magic_comment.rb', line 298
def new_frozen_string_literal(value) "# frozen_string_literal: #{value}" end
#without(type)
Rewrite the comment without a given token type
# File 'lib/rubocop/magic_comment.rb', line 290
def without(type) if @comment.match?(/\A#\s*#{self.class::KEYWORDS[type.to_sym]}/io) '' else @comment end end