seattlerb / ruby_parser

ruby_parser is a ruby parser written in pure ruby. It outputs s-expressions which can be manipulated and converted back to ruby via the ruby2ruby gem.
http://www.zenspider.com/projects/ruby_parser.html
476 stars 100 forks source link

Release with 3.2 support #334

Closed sebfie closed 1 year ago

sebfie commented 1 year ago

Hello,

Do you plan to make a release with 3.2 support, I have warning :

NOTE: RubyParser::V32 undefined, using RubyParser::V31. NOTE: RubyParser::V32 undefined, using RubyParser::V31. NOTE: RubyParser::V32 undefined, using RubyParser::V31. NOTE: RubyParser::V32 undefined, using RubyParser::V31. NOTE: RubyParser::V32 undefined, using RubyParser::V31. NOTE: RubyParser::V32 undefined, using RubyParser::V31.

Thank you for you work !

rsanheim commented 1 year ago

For now, you can monkeypatch RubyParser to silence these warnings. We are using HairTrigger in our Rails app, which depends on ruby_parser, so we get these warnings for every db/migration releated rails task. This takes care of it as a temporary workaround in an initializer:

diff --git a/apps/api/config/initializers/00_ruby_parser_patch.rb b/apps/api/config/initializers/00_ruby_parser_patch.rb
new file mode 100644
index 000000000..071d12b14
--- /dev/null
+++ b/apps/api/config/initializers/00_ruby_parser_patch.rb
@@ -0,0 +1,18 @@
+require "ruby_parser"
+
+class RubyParser
+  def self.for_current_ruby
+    name = "V#{RUBY_VERSION[/^\d+\.\d+/].delete "."}"
+    klass = if const_defined? name
+      const_get name
+    else
+      latest = VERSIONS.first
+      # Silence warnings from this for now - can go away once RubyParser gets a proper 3.2 release
+      # See also https://github.com/seattlerb/ruby_parser/issues/334
+      # warn "NOTE: RubyParser::#{name} undefined, using #{latest}."
+      latest
+    end
+
+    klass.new
+  end
+end

Thanks for all the OSS work you've contributed over the years @zenspider !

zenspider commented 1 year ago

done