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?(processed_source, comment = FROZEN_STRING_LITERAL)
click to toggle source
# File lib/rubocop/cop/mixin/frozen_string_literal.rb, line 13 def frozen_string_literal_comment_exists?(processed_source, comment = FROZEN_STRING_LITERAL) first_three_lines = [processed_source[0], processed_source[1], processed_source[2]] first_three_lines.compact! first_three_lines.any? do |line| line.start_with?(comment) end end
frozen_string_literals_enabled?(processed_source)
click to toggle source
# File lib/rubocop/cop/mixin/frozen_string_literal.rb, line 23 def frozen_string_literals_enabled?(processed_source) 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 frozen_string_literal_comment_exists?( processed_source, FROZEN_STRING_LITERAL_ENABLED ) end