ku1ik / rainbow

Ruby gem for colorizing printed text on ANSI terminals
MIT License
813 stars 68 forks source link

Issues with Ruby 2.2.1 #25

Closed justin808 closed 9 years ago

justin808 commented 9 years ago

For some reason, gems that include rainbow, like RuboCop, are failing when used with Ruby 2.2.1. This might be a bug with Ruby's 2.2.x refinements feature.

private method `color' called for "An error occurred while Style/MultilineOperationIndentation":String
/Users/justin/.rvm/gems/ruby-2.2.1@madrone/gems/rubocop-0.30.1/lib/rubocop/cop/team.rb:93:in `block (2 levels) in process_commissioner_errors'

UPDATE

Actually, I'm seeing this with Ruby 2.1.5. Researching.

justin808 commented 9 years ago

This is caused when both "rainbow" and "colorize" gems are used. Avoid using both as both monkey patch String, and colorize puts a private method on String called color.

https://github.com/fazibear/colorize/blob/master/lib/colorize/instance_methods.rb

I would suggest that rainbow eventually use the refinements feature in 2.2.1.

ku1ik commented 9 years ago

Rainbow 2.0 doesn't monkey patch String by default. It can do that if you want it to be compatible with Rainbow 1.0, but that's not recommended anyway.

What would be needed to support refinements?

justin808 commented 9 years ago

@sickill,

I don't know. This is easy to reproduce by creating a rails project with a Gemfile that contains rubocop and colorize, and then run rake rubocop.

I solved the issue by switching to rainbow from colorize in my gemfile.

Maybe the bug is that RuboCop should not be doing the monkeypatching? But once it's done...