Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins:
- rubocop-on-rbs

AllCops:
TargetRubyVersion: 3.4
DisabledByDefault: true
Exclude:
- 'vendor/bundle/**/*'
Expand Down
71 changes: 19 additions & 52 deletions lib/rbs/prototype/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rbs/prototype/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/rbs/prototype/runtime/value_object_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions rbs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading