class RuboCop::MagicComment

@abstract parent of three different magic comment handlers
Parse different formats of magic comments.

def self.parse(comment)

Returns:
  • (RuboCop::MagicComment) -

Parameters:
  • comment (String) --
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

def any?

def any?
  frozen_string_literal_specified? || encoding_specified?
end

def encoding_specified?

def encoding_specified?
  specified?(encoding)
end

def extract(pattern)

Returns:
  • (nil) - otherwise
  • (String) - if pattern matched

Parameters:
  • pattern (Regexp) --
def extract(pattern)
  @comment[pattern, 1]
end

def frozen_string_literal

Returns:
  • (String) - if comment is found but isn't true or false
  • (nil) - if frozen_string_literal comment isn't found
  • (Boolean) - if value is `true` or `false`
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

def frozen_string_literal?

Returns:
  • (Boolean) -
def frozen_string_literal?
  frozen_string_literal == true
end

def frozen_string_literal_specified?

Returns:
  • (Boolean) -
def frozen_string_literal_specified?
  specified?(frozen_string_literal)
end

def initialize(comment)

def initialize(comment)
  @comment = comment
end

def specified?(value)

def specified?(value)
  !value.nil?
end