Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure only constants that extend Module are parsed from requested paths #2084

Merged
merged 2 commits into from
Nov 25, 2024
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
4 changes: 3 additions & 1 deletion lib/tapioca/commands/abstract_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ def constantize(constant_names, ignore_missing: false)
raise Thor::Error, ""
end

processable_constants.map { |_, constant| constant }
processable_constants
.map { |_, constant| constant }
.grep(Module)
end

sig { params(compiler_names: T::Array[String]).returns(T::Array[T.class_of(Tapioca::Dsl::Compiler)]) }
Expand Down
59 changes: 59 additions & 0 deletions spec/tapioca/cli/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,65 @@ def saved_change_to_reviewer?; end

assert_success_status(result)
end

it "generates RBIs for ActiveResource containing arbitrary constants, and referenced by file path" do
@project.require_real_gem("activeresource")
@project.bundle_install!
@project.write!("lib/post.rb", <<~RUBY)
require "active_resource"

class Post < ActiveResource::Base
SOME_CONSTANT = 123

schema do
integer 'id'
end
end
RUBY

result = @project.tapioca("dsl lib/post.rb")

assert_stdout_equals(<<~OUT, result)
Loading DSL extension classes... Done
Loading Rails application... Done
Loading DSL compiler classes... Done
Compiling DSL RBI files...

create sorbet/rbi/dsl/post.rbi

Done

Checking generated RBI files... Done
No errors found

All operations performed in working directory.
Please review changes and commit them.
OUT

assert_empty_stderr(result)

assert_project_file_equal("sorbet/rbi/dsl/post.rbi", <<~RUBY)
# typed: true

# DO NOT EDIT MANUALLY
# This is an autogenerated file for dynamic methods in `Post`.
# Please instead update this file by running `bin/tapioca dsl Post`.


class Post
sig { returns(Integer) }
def id; end

sig { params(value: Integer).returns(Integer) }
def id=(value); end

sig { returns(T::Boolean) }
def id?; end
end
RUBY

assert_success_status(result)
end
end

describe "verify" do
Expand Down
Loading