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::REGEXP then EmacsComment.new(comment)
  when VimComment::REGEXP   then VimComment.new(comment)
  else
    SimpleComment.new(comment)
  end
end

def any?

def any?
  frozen_string_literal_specified? ||
    encoding_specified? ||
    shareable_constant_value_specified? ||
    typed_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 shareable_constant_value

Returns:
  • (String) - for shareable_constant_value config
def shareable_constant_value
  extract_shareable_constant_value
end

def shareable_constant_value_specified?

Returns:
  • (Boolean) -
def shareable_constant_value_specified?
  specified?(shareable_constant_value)
end

def specified?(value)

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

def typed

def typed
  extract_typed
end

def typed_specified?

Returns:
  • (Boolean) -
def typed_specified?
  specified?(extract_typed)
end

def valid?

def valid?
  @comment.start_with?('#') && any?
end

def valid_literal_value?

def valid_literal_value?
  [true, false].include?(frozen_string_literal)
end

def valid_shareable_constant_value?

def valid_shareable_constant_value?
  %w[none literal experimental_everything experimental_copy].include?(shareable_constant_value)
end