class RuboCop::Cop::EightyFourCodes::RubyVersionFile
Read Ruby version from a .ruby-version file
Instead of staticly defining the Ruby runtime version in Gemfile, load it from a .ruby-version file definition. As this Ruby version file is read by rbenv, chruby etc it's much easier for the developer to work with multiple projects with different versions.
@example
# bad ruby 2.6.6 # good ruby File.read('.ruby-version')
Constants
- MSG
- RESTRICT_ON_SEND
Public Instance Methods
on_send(node)
click to toggle source
# File lib/rubocop/cop/eighty_four_codes/ruby_version_file.rb, line 30 def on_send(node) return unless File.basename(processed_source.file_path).eql?('Gemfile') static_version_found?(node) do |source_node, source| message = format(MSG, source: source) add_offense( source_node, message: message ) do |corrector| corrector.replace( source_node, "File.read('.ruby-version')" ) end end end