Skip to content

Commit

Permalink
[Fix #6793] Clarify ruby version error
Browse files Browse the repository at this point in the history
Showing it came from `RuboCop`.
  • Loading branch information
tejasbubane authored and bbatsov committed Jun 25, 2019
1 parent ca01b3e commit 445b342
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/rubocop/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,13 @@ def check_target_ruby
return if KNOWN_RUBIES.include?(target_ruby_version)

msg = if OBSOLETE_RUBIES.include?(target_ruby_version)
"Unsupported Ruby version #{target_ruby_version} found in " \
"#{target_ruby_source}. #{target_ruby_version}-compatible " \
"RuboCop found unsupported Ruby version #{target_ruby_version} " \
"in #{target_ruby_source}. #{target_ruby_version}-compatible " \
'analysis was dropped after version ' \
"#{OBSOLETE_RUBIES[target_ruby_version]}."
else
"Unknown Ruby version #{target_ruby_version.inspect} found in " \
"#{target_ruby_source}."
'RuboCop found unknown Ruby version ' \
"#{target_ruby_version.inspect} in #{target_ruby_source}."
end

msg += "\nSupported versions: #{KNOWN_RUBIES.join(', ')}"
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/processed_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ def parser_class(ruby_version)
require 'parser/ruby27'
Parser::Ruby27
else
raise ArgumentError, "Unknown Ruby version: #{ruby_version.inspect}"
raise ArgumentError,
"RuboCop found unknown Ruby version: #{ruby_version.inspect}"
end
end
# rubocop:enable Metrics/MethodLength
Expand Down
9 changes: 5 additions & 4 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1615,8 +1615,8 @@ def method(foo, bar, qux, fred, arg5, f) end #{'#' * 45}
TargetRubyVersion: 2.8
YAML
expect(cli.run([])).to eq(2)
expect($stderr.string.strip).to match(
/\AError: Unknown Ruby version 2.8 found in `TargetRubyVersion`/
expect($stderr.string.strip).to start_with(
'Error: RuboCop found unknown Ruby version 2.8 in `TargetRubyVersion`'
)
expect($stderr.string.strip).to match(
/Supported versions: 2.3, 2.4, 2.5, 2.6, 2.7/
Expand All @@ -1632,8 +1632,9 @@ def method(foo, bar, qux, fred, arg5, f) end #{'#' * 45}
YAML

expect(cli.run([])).to eq(2)
expect($stderr.string.strip).to match(
/\AError: Unsupported Ruby version 2.0 found in `TargetRubyVersion`/
expect($stderr.string.strip).to start_with(
'Error: RuboCop found unsupported Ruby version 2.0 in '\
'`TargetRubyVersion`'
)

expect($stderr.string.strip).to match(
Expand Down

0 comments on commit 445b342

Please sign in to comment.