module RuboCop::Cop::FrozenStringLiteral

Common functionality for dealing with frozen string literals.

Constants

FROZEN_STRING_LITERAL
FROZEN_STRING_LITERAL_ENABLED
FROZEN_STRING_LITERAL_TYPES

Public Instance Methods

frozen_string_literal_comment_exists?() click to toggle source
# File lib/rubocop/cop/mixin/frozen_string_literal.rb, line 13
def frozen_string_literal_comment_exists?
  leading_comment_lines.any? do |line|
    MagicComment.parse(line).frozen_string_literal_specified?
  end
end
frozen_string_literals_enabled?() click to toggle source
# File lib/rubocop/cop/mixin/frozen_string_literal.rb, line 19
def frozen_string_literals_enabled?
  ruby_version = processed_source.ruby_version
  return false unless ruby_version
  return true if ruby_version >= 3.0
  return false unless ruby_version >= 2.3

  leading_comment_lines.any? do |line|
    MagicComment.parse(line).frozen_string_literal?
  end
end

Private Instance Methods

leading_comment_lines() click to toggle source
# File lib/rubocop/cop/mixin/frozen_string_literal.rb, line 32
def leading_comment_lines
  processed_source[0..2].compact
end