Skip to content
Open
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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Layout/LeadingCommentSpace:
AllowRBSInlineAnnotation: true

Layout/LineLength:
Enabled: true
Max: 120
AllowedPatterns: ['\A\s*#:']

Naming/InclusiveLanguage:
Exclude:
Expand Down
21 changes: 20 additions & 1 deletion lib/tapioca/commands/abstract_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ class AbstractDsl < CommandWithoutTracker
include SorbetHelper
include RBIFilesHelper

#: (requested_constants: Array[String], requested_paths: Array[Pathname], outpath: Pathname, only: Array[String], exclude: Array[String], file_header: bool, tapioca_path: String, ?skip_constant: Array[String], ?quiet: bool, ?verbose: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?gem_dir: String, ?rbi_formatter: RBIFormatter, ?app_root: String, ?halt_upon_load_error: bool, ?compiler_options: Hash[String, untyped], ?lsp_addon: bool) -> void
#: (
#| requested_constants: Array[String],
#| requested_paths: Array[Pathname],
#| outpath: Pathname,
#| only: Array[String],
#| exclude: Array[String],
#| file_header: bool,
#| tapioca_path: String,
#| ?skip_constant: Array[String],
#| ?quiet: bool,
#| ?verbose: bool,
#| ?number_of_workers: Integer?,
#| ?auto_strictness: bool,
#| ?gem_dir: String,
#| ?rbi_formatter: RBIFormatter,
#| ?app_root: String,
#| ?halt_upon_load_error: bool,
#| ?compiler_options: Hash[String, untyped],
#| ?lsp_addon: bool
#| ) -> void
def initialize(
requested_constants:,
requested_paths:,
Expand Down
21 changes: 20 additions & 1 deletion lib/tapioca/commands/abstract_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ class AbstractGem < Command
include SorbetHelper
include RBIFilesHelper

#: (gem_names: Array[String], exclude: Array[String], include_dependencies: bool, prerequire: String?, postrequire: String, typed_overrides: Hash[String, String], outpath: Pathname, file_header: bool, include_doc: bool, include_loc: bool, include_exported_rbis: bool, ?number_of_workers: Integer?, ?auto_strictness: bool, ?dsl_dir: String, ?rbi_formatter: RBIFormatter, ?halt_upon_load_error: bool, ?lsp_addon: bool?, ?verbose: bool?) -> void
#: (
#| gem_names: Array[String],
#| exclude: Array[String],
#| include_dependencies: bool,
#| prerequire: String?,
#| postrequire: String,
#| typed_overrides: Hash[String, String],
#| outpath: Pathname,
#| file_header: bool,
#| include_doc: bool,
#| include_loc: bool,
#| include_exported_rbis: bool,
#| ?number_of_workers: Integer?,
#| ?auto_strictness: bool,
#| ?dsl_dir: String,
#| ?rbi_formatter: RBIFormatter,
#| ?halt_upon_load_error: bool,
#| ?lsp_addon: bool?,
#| ?verbose: bool?
#| ) -> void
def initialize(
gem_names:,
exclude:,
Expand Down
8 changes: 7 additions & 1 deletion lib/tapioca/commands/annotations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ module Commands
class Annotations < CommandWithoutTracker
extend T::Sig

#: (central_repo_root_uris: Array[String], ?auth: String?, ?netrc_file: String?, ?central_repo_index_path: String, ?typed_overrides: Hash[String, String]) -> void
#: (
#| central_repo_root_uris: Array[String],
#| ?auth: String?,
#| ?netrc_file: String?,
#| ?central_repo_index_path: String,
#| ?typed_overrides: Hash[String, String]
#| ) -> void
def initialize(
central_repo_root_uris:,
auth: nil,
Expand Down
10 changes: 9 additions & 1 deletion lib/tapioca/commands/check_shims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ class CheckShims < CommandWithoutTracker
include SorbetHelper
include RBIFilesHelper

#: (gem_rbi_dir: String, dsl_rbi_dir: String, annotations_rbi_dir: String, shim_rbi_dir: String, todo_rbi_file: String, payload: bool, number_of_workers: Integer?) -> void
#: (
#| gem_rbi_dir: String,
#| dsl_rbi_dir: String,
#| annotations_rbi_dir: String,
#| shim_rbi_dir: String,
#| todo_rbi_file: String,
#| payload: bool,
#| number_of_workers: Integer?
#| ) -> void
def initialize(
gem_rbi_dir:,
dsl_rbi_dir:,
Expand Down
7 changes: 6 additions & 1 deletion lib/tapioca/dsl/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ def all_modules
end
end

#: (Tapioca::Dsl::Pipeline pipeline, RBI::Tree root, ConstantType constant, ?Hash[String, untyped] options) -> void
#: (
#| Tapioca::Dsl::Pipeline pipeline,
#| RBI::Tree root,
#| ConstantType constant,
#| ?Hash[String, untyped] options
#| ) -> void
def initialize(pipeline, root, constant, options = {})
@pipeline = pipeline
@root = root
Expand Down
8 changes: 7 additions & 1 deletion lib/tapioca/dsl/compilers/active_record_columns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ def column_type_option
)
end

#: (RBI::Scope klass, String name, Array[String]? methods_to_add, ?return_type: String, ?parameters: Array[RBI::TypedParam]) -> void
#: (
#| RBI::Scope klass,
#| String name,
#| Array[String]? methods_to_add,
#| ?return_type: String,
#| ?parameters: Array[RBI::TypedParam]
#| ) -> void
def add_method(klass, name, methods_to_add, return_type: "void", parameters: [])
klass.create_method(
name,
Expand Down
7 changes: 6 additions & 1 deletion lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,12 @@ def create_where_relation_method
end
end

#: ((Symbol | String) name, ?parameters: Array[RBI::TypedParam], ?relation_return_type: String, ?association_return_type: String) -> void
#: (
#| (Symbol | String) name,
#| ?parameters: Array[RBI::TypedParam],
#| ?relation_return_type: String,
#| ?association_return_type: String
#| ) -> void
def create_relation_method(
name,
parameters: [],
Expand Down
2 changes: 2 additions & 0 deletions lib/tapioca/dsl/compilers/url_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module Tapioca
module Dsl
module Compilers
# rubocop:disable Layout/LineLength
# `Tapioca::Dsl::Compilers::UrlHelpers` generates RBI files for classes that include or extend
# [`Rails.application.routes.url_helpers`](https://api.rubyonrails.org/v5.1.7/classes/ActionDispatch/Routing/UrlFor.html#module-ActionDispatch::Routing::UrlFor-label-URL+generation+for+named+routes).
#
Expand Down Expand Up @@ -78,6 +79,7 @@ module Compilers
# include GeneratedUrlHelpersModule
# end
# ~~~
# rubocop:enable Layout/LineLength
#: [ConstantType = Module]
class UrlHelpers < Compiler
extend T::Sig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ColumnTypeOption < T::Enum
class << self
extend T::Sig

#: (Hash[String, untyped] options) { (String value, ColumnTypeOption default_column_type_option) -> void } -> ColumnTypeOption
#: (
#| Hash[String, untyped] options,
#| ) { (String value, ColumnTypeOption default_column_type_option) -> void } -> ColumnTypeOption
def from_options(options, &block)
column_type_option = Persisted
value = options["ActiveRecordColumnTypes"]
Expand Down
19 changes: 17 additions & 2 deletions lib/tapioca/dsl/helpers/graphql_type_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module GraphqlTypeHelper

extend T::Sig

#: (GraphQL::Schema::Argument argument, (singleton(GraphQL::Schema::Mutation) | singleton(GraphQL::Schema::InputObject)) constant) -> String
#: (
#| GraphQL::Schema::Argument argument,
#| (singleton(GraphQL::Schema::Mutation) | singleton(GraphQL::Schema::InputObject)) constant
#| ) -> String
def type_for_argument(argument, constant)
type = if argument.loads
loads_type = ::GraphQL::Schema::Wrapper.new(argument.loads)
Expand All @@ -34,7 +37,19 @@ def type_for_argument(argument, constant)
)
end

#: ((GraphQL::Schema::Wrapper | singleton(GraphQL::Schema::Scalar) | singleton(GraphQL::Schema::Enum) | singleton(GraphQL::Schema::Union) | singleton(GraphQL::Schema::Object) | singleton(GraphQL::Schema::Interface) | singleton(GraphQL::Schema::InputObject)) type, ?ignore_nilable_wrapper: bool, ?prepare_method: Method?) -> String
#: (
#| (
#| GraphQL::Schema::Wrapper |
#| singleton(GraphQL::Schema::Scalar) |
#| singleton(GraphQL::Schema::Enum) |
#| singleton(GraphQL::Schema::Union) |
#| singleton(GraphQL::Schema::Object) |
#| singleton(GraphQL::Schema::Interface) |
#| singleton(GraphQL::Schema::InputObject)
#| ) type,
#| ?ignore_nilable_wrapper: bool,
#| ?prepare_method: Method?
#| ) -> String
def type_for(type, ignore_nilable_wrapper: false, prepare_method: nil)
unwrapped_type = type.unwrap

Expand Down
18 changes: 16 additions & 2 deletions lib/tapioca/dsl/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ class Pipeline
#: Array[String]
attr_reader :errors

#: (requested_constants: Array[Module], ?requested_paths: Array[Pathname], ?requested_compilers: Array[singleton(Compiler)], ?excluded_compilers: Array[singleton(Compiler)], ?error_handler: ^(String error) -> void, ?skipped_constants: Array[Module], ?number_of_workers: Integer?, ?compiler_options: Hash[String, untyped], ?lsp_addon: bool) -> void
#: (
#| requested_constants: Array[Module],
#| ?requested_paths: Array[Pathname],
#| ?requested_compilers: Array[singleton(Compiler)],
#| ?excluded_compilers: Array[singleton(Compiler)],
#| ?error_handler: ^(String error) -> void,
#| ?skipped_constants: Array[Module],
#| ?number_of_workers: Integer?,
#| ?compiler_options: Hash[String, untyped],
#| ?lsp_addon: bool
#| ) -> void
def initialize(
requested_constants:,
requested_paths: [],
Expand Down Expand Up @@ -119,7 +129,11 @@ def gather_active_compilers(requested_compilers, excluded_compilers)
active_compilers
end

#: (Array[Module] requested_constants, Array[Pathname] requested_paths, Array[Module] skipped_constants) -> Set[Module]
#: (
#| Array[Module] requested_constants,
#| Array[Pathname] requested_paths,
#| Array[Module] skipped_constants
#| ) -> Set[Module]
def gather_constants(requested_constants, requested_paths, skipped_constants)
Compiler.requested_constants = requested_constants
constants = Set.new.compare_by_identity
Expand Down
9 changes: 8 additions & 1 deletion lib/tapioca/gem/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ class MethodNodeAdded < NodeAdded
#: Array[[Symbol, String]]
attr_reader :parameters

#: (String symbol, Module constant, UnboundMethod method, RBI::Method node, untyped signature, Array[[Symbol, String]] parameters) -> void
#: (
#| String symbol,
#| Module constant,
#| UnboundMethod method,
#| RBI::Method node,
#| untyped signature,
#| Array[[Symbol, String]] parameters
#| ) -> void
def initialize(symbol, constant, method, node, signature, parameters) # rubocop:disable Metrics/ParameterLists
super(symbol, constant)
@node = node
Expand Down
16 changes: 14 additions & 2 deletions lib/tapioca/gem/listeners/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ def on_scope(event)
compile_directly_owned_methods(node, symbol, singleton_class_of(constant), attached_class: constant)
end

#: (RBI::Tree tree, String module_name, Module mod, ?Array[Symbol] for_visibility, ?attached_class: Module?) -> void
#: (
#| RBI::Tree tree,
#| String module_name,
#| Module mod,
#| ?Array[Symbol] for_visibility,
#| ?attached_class: Module?
#| ) -> void
def compile_directly_owned_methods(
tree,
module_name,
Expand Down Expand Up @@ -52,7 +58,13 @@ def compile_directly_owned_methods(
end
end

#: (RBI::Tree tree, String symbol_name, Module constant, UnboundMethod? method, ?RBI::Visibility visibility) -> void
#: (
#| RBI::Tree tree,
#| String symbol_name,
#| Module constant,
#| UnboundMethod? method,
#| ?RBI::Visibility visibility
#| ) -> void
def compile_method(tree, symbol_name, constant, method, visibility = RBI::Public.new)
return unless method
return unless method_owned_by_constant?(method, constant)
Expand Down
9 changes: 8 additions & 1 deletion lib/tapioca/gem/pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ def push_foreign_scope(symbol, constant, node)
@events << Gem::ForeignScopeNodeAdded.new(symbol, constant, node)
end

#: (String symbol, Module constant, UnboundMethod method, RBI::Method node, untyped signature, Array[[Symbol, String]] parameters) -> void
#: (
#| String symbol,
#| Module constant,
#| UnboundMethod method,
#| RBI::Method node,
#| untyped signature,
#| Array[[Symbol, String]] parameters
#| ) -> void
def push_method(symbol, constant, method, node, signature, parameters) # rubocop:disable Metrics/ParameterLists
@events << Gem::MethodNodeAdded.new(symbol, constant, method, node, signature, parameters)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/tapioca/helpers/config_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ def validate_config!(config_file, config)
@validating_config = false
end

#: (Hash[Symbol, Thor::Option] command_options, String config_key, Hash[untyped, untyped] config_options) -> Array[ConfigError]
#: (
#| Hash[Symbol, Thor::Option] command_options,
#| String config_key,
#| Hash[untyped, untyped] config_options
#| ) -> Array[ConfigError]
def validate_config_options(command_options, config_key, config_options)
config_options.filter_map do |config_option_key, config_option_value|
command_option = command_options[config_option_key.to_sym]
Expand Down
9 changes: 8 additions & 1 deletion lib/tapioca/helpers/rbi_files_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def location_to_payload_url(loc, path_prefix:)
url
end

#: (command: String, gem_dir: String, dsl_dir: String, auto_strictness: bool, ?gems: Array[Gemfile::GemSpec], ?compilers: T::Enumerable[singleton(Dsl::Compiler)]) -> void
#: (
#| command: String,
#| gem_dir: String,
#| dsl_dir: String,
#| auto_strictness: bool,
#| ?gems: Array[Gemfile::GemSpec],
#| ?compilers: T::Enumerable[singleton(Dsl::Compiler)]
#| ) -> void
def validate_rbi_files(command:, gem_dir:, dsl_dir:, auto_strictness:, gems: [], compilers: [])
error_url_base = Spoom::Sorbet::Errors::DEFAULT_ERROR_URL_BASE

Expand Down
16 changes: 14 additions & 2 deletions lib/tapioca/loaders/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class Gem < Loader
class << self
extend T::Sig

#: (bundle: Gemfile, prerequire: String?, postrequire: String, default_command: String, halt_upon_load_error: bool) -> void
#: (
#| bundle: Gemfile,
#| prerequire: String?,
#| postrequire: String,
#| default_command: String,
#| halt_upon_load_error: bool
#| ) -> void
def load_application(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
loader = new(
bundle: bundle,
Expand All @@ -30,7 +36,13 @@ def load

protected

#: (bundle: Gemfile, prerequire: String?, postrequire: String, default_command: String, halt_upon_load_error: bool) -> void
#: (
#| bundle: Gemfile,
#| prerequire: String?,
#| postrequire: String,
#| default_command: String,
#| halt_upon_load_error: bool
#| ) -> void
def initialize(bundle:, prerequire:, postrequire:, default_command:, halt_upon_load_error:)
super()

Expand Down
9 changes: 8 additions & 1 deletion lib/tapioca/rbi_ext/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ def create_type_variable(name, type:, variance: :invariant, fixed: nil, upper: n
create_node(RBI::TypeMember.new(name, value))
end

#: (String name, ?parameters: Array[TypedParam], ?return_type: String?, ?class_method: bool, ?visibility: RBI::Visibility, ?comments: Array[RBI::Comment]) ?{ (RBI::Method node) -> void } -> void
#: (
#| String name,
#| ?parameters: Array[TypedParam],
#| ?return_type: String?,
#| ?class_method: bool,
#| ?visibility: RBI::Visibility,
#| ?comments: Array[RBI::Comment]
#| ) ?{ (RBI::Method node) -> void } -> void
def create_method(name, parameters: [], return_type: nil, class_method: false, visibility: RBI::Public.new,
comments: [], &block)
return unless Tapioca::RBIHelper.valid_method_name?(name)
Expand Down
7 changes: 6 additions & 1 deletion spec/spec_with_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def mock_project(sorbet_dependency: true, &block)
#
# assert(@gem.file?("lib/foo.rb"))
# ~~~
#: (String name, String version, ?dependencies: Array[String], ?path: String) ?{ (MockGem gem) [self: MockGem] -> void } -> MockGem
#: (
#| String name,
#| String version,
#| ?dependencies: Array[String],
#| ?path: String
#| ) ?{ (MockGem gem) [self: MockGem] -> void } -> MockGem
def mock_gem(name, version, dependencies: [], path: default_gem_path(name), &block)
gem = MockGem.new(path, name, version, dependencies)
gem.mkdir!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ module GeneratedAssociationMethods; end

assert_equal(6, generated_errors.size)

# rubocop:disable Layout/LineLength
expected_errors = [
"Cannot generate association `has_one :author` on `Post` since the constant `Author` does not exist.",
"Cannot generate association `has_many :comments` on `Post` since the constant `Comment` does not exist.",
Expand Down
Loading
Loading