Class: RuboCop::Cop::EightyFourCodes::RubyVersionFile
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::EightyFourCodes::RubyVersionFile
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/eighty_four_codes/ruby_version_file.rb
Overview
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.
Constant Summary collapse
- MSG =
"Control Ruby version via .ruby-version, fix by replacing with File.read('.ruby-version')"
- RESTRICT_ON_SEND =
%i[ruby].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# 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| = format(MSG, source: source) add_offense(source_node, message: ) do |corrector| corrector.replace(source_node, "File.read('.ruby-version')") end end end |