diff --git a/.rubocop.yml b/.rubocop.yml index b43b2f141c..1eed1a8355 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,6 @@ plugins: - rubocop-on-rbs AllCops: - TargetRubyVersion: 3.4 DisabledByDefault: true Exclude: - 'vendor/bundle/**/*' diff --git a/lib/rbs/prototype/helpers.rb b/lib/rbs/prototype/helpers.rb index df28a8eed9..f508f45c5b 100644 --- a/lib/rbs/prototype/helpers.rb +++ b/lib/rbs/prototype/helpers.rb @@ -5,58 +5,25 @@ module Prototype module Helpers private - # Prism can't parse Ruby 3.2 code - if RUBY_VERSION >= "3.3" - def parse_comments(string, include_trailing:) - Prism.parse_comments(string, version: "current").yield_self do |prism_comments| # steep:ignore UnexpectedKeywordArgument - prism_comments.each_with_object({}) do |comment, hash| #$ Hash[Integer, AST::Comment] - # Skip EmbDoc comments - next unless comment.is_a?(Prism::InlineComment) - # skip like `module Foo # :nodoc:` - next if comment.trailing? && !include_trailing - - line = comment.location.start_line - body = "#{comment.location.slice}\n" - body = body[2..-1] or raise - body = "\n" if body.empty? - - comment = AST::Comment.new(string: body, location: nil) - if prev_comment = hash.delete(line - 1) - hash[line] = AST::Comment.new(string: prev_comment.string + comment.string, - location: nil) - else - hash[line] = comment - end - end - end - end - else - require "ripper" - def parse_comments(string, include_trailing:) - Ripper.lex(string).yield_self do |tokens| - code_lines = {} #: Hash[Integer, bool] - tokens.each.with_object({}) do |token, hash| #$ Hash[Integer, AST::Comment] - case token[1] - when :on_sp, :on_ignored_nl - # skip - when :on_comment - line = token[0][0] - # skip like `module Foo # :nodoc:` - next if code_lines[line] && !include_trailing - body = token[2][2..-1] or raise - - body = "\n" if body.empty? - - comment = AST::Comment.new(string: body, location: nil) - if prev_comment = hash.delete(line - 1) - hash[line] = AST::Comment.new(string: prev_comment.string + comment.string, - location: nil) - else - hash[line] = comment - end - else - code_lines[token[0][0]] = true - end + def parse_comments(string, include_trailing:) + Prism.parse_comments(string, version: "current").yield_self do |prism_comments| # steep:ignore UnexpectedKeywordArgument + prism_comments.each_with_object({}) do |comment, hash| #$ Hash[Integer, AST::Comment] + # Skip EmbDoc comments + next unless comment.is_a?(Prism::InlineComment) + # skip like `module Foo # :nodoc:` + next if comment.trailing? && !include_trailing + + line = comment.location.start_line + body = "#{comment.location.slice}\n" + body = body[2..-1] or raise + body = "\n" if body.empty? + + comment = AST::Comment.new(string: body, location: nil) + if prev_comment = hash.delete(line - 1) + hash[line] = AST::Comment.new(string: prev_comment.string + comment.string, + location: nil) + else + hash[line] = comment end end end diff --git a/lib/rbs/prototype/runtime.rb b/lib/rbs/prototype/runtime.rb index c209f9ad01..6cf73b879b 100644 --- a/lib/rbs/prototype/runtime.rb +++ b/lib/rbs/prototype/runtime.rb @@ -527,7 +527,7 @@ def generate_class(mod) generate_mixin(mod, decl, type_name, type_name_absolute) - unless mod < Struct || (RUBY_VERSION >= '3.2' && mod < Data) + unless mod < Struct || mod < Data generate_methods(mod, type_name, decl.members) unless outline end diff --git a/lib/rbs/prototype/runtime/value_object_generator.rb b/lib/rbs/prototype/runtime/value_object_generator.rb index ab984e1311..876d793dd5 100644 --- a/lib/rbs/prototype/runtime/value_object_generator.rb +++ b/lib/rbs/prototype/runtime/value_object_generator.rb @@ -212,7 +212,6 @@ def build_s_keyword_init_p class DataGenerator < ValueObjectBase def self.generatable?(target) - return false unless RUBY_VERSION >= '3.2' return false unless target < Data # Avoid direct inherited class like `class Option < Data` return false unless target.respond_to?(:members) diff --git a/rbs.gemspec b/rbs.gemspec index 65782803bc..f699e7411d 100644 --- a/rbs.gemspec +++ b/rbs.gemspec @@ -67,14 +67,10 @@ Gem::Specification.new do |spec| spec.extensions = %w{ext/rbs_extension/extconf.rb} end - if false - spec.required_ruby_version = ">= 3.4" - end - spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.required_ruby_version = ">= 3.2" + spec.required_ruby_version = ">= 3.3" spec.add_dependency "logger" spec.add_dependency "prism", ">= 1.6.0" spec.add_dependency "tsort"