class RuboCop::MagicComment::SimpleComment
Wrapper for regular magic comments not bound to an editor.
Simple comments can only specify one setting per comment.
@example frozen string literal comments
comment1 = RuboCop::MagicComment.parse('# frozen_string_literal: true') comment1.frozen_string_literal # => true comment1.encoding # => nil
@example encoding comments
comment2 = RuboCop::MagicComment.parse('# encoding: utf-8') comment2.frozen_string_literal # => nil comment2.encoding # => 'utf-8'
Constants
- FSTRING_LITERAL_COMMENT
Public Instance Methods
Source
# File lib/rubocop/magic_comment.rb, line 269 def encoding extract(/\A\s*\#\s*(#{FSTRING_LITERAL_COMMENT})?\s*#{KEYWORDS[:encoding]}: (#{TOKEN})/io) end
Match ‘encoding` or `coding`
Source
# File lib/rubocop/magic_comment.rb, line 282 def new_frozen_string_literal(value) "# frozen_string_literal: #{value}" end
Source
# 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
Rewrite the comment without a given token type
Private Instance Methods
Source
# File lib/rubocop/magic_comment.rb, line 295 def extract_frozen_string_literal extract(/\A\s*#\s*#{KEYWORDS[:frozen_string_literal]}:\s*#{TOKEN}\s*\z/io) end
Extract ‘frozen_string_literal`.
The ‘frozen_string_literal` magic comment only works if it is the only text in the comment.
Case-insensitive and dashes/underscores are acceptable. @see github.com/ruby/ruby/blob/78b95b49f8/parse.y#L7134-L7138
Source
# File lib/rubocop/magic_comment.rb, line 303 def extract_typed extract(/\A\s*#\s*#{KEYWORDS[:typed]}:\s*#{TOKEN}\s*\z/io) end