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'
Public Instance Methods
encoding()
click to toggle source
Match ‘encoding` or `coding`
# File lib/rubocop/magic_comment.rb, line 263 def encoding extract(/\A\s*\#.*\b#{KEYWORDS[:encoding]}: (#{TOKEN})/io) end
without(type)
click to toggle source
Rewrite the comment without a given token type
# File lib/rubocop/magic_comment.rb, line 268 def without(type) if @comment.match?(/\A#\s*#{self.class::KEYWORDS[type.to_sym]}/) '' else @comment end end
Private Instance Methods
extract_frozen_string_literal()
click to toggle source
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/78b95b4/parse.y#L7134-L7138
# File lib/rubocop/magic_comment.rb, line 285 def extract_frozen_string_literal extract(/\A\s*#\s*#{KEYWORDS[:frozen_string_literal]}:\s*(#{TOKEN})\s*\z/io) end
extract_typed()
click to toggle source
# File lib/rubocop/magic_comment.rb, line 293 def extract_typed extract(/\A\s*#\s*#{KEYWORDS[:typed]}:\s*(#{TOKEN})\s*\z/io) end