diff --git a/.rubocop.yml b/.rubocop.yml index c214ea3b8..e423fd810 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,8 +19,8 @@ Layout/LeadingCommentSpace: AllowRBSInlineAnnotation: true Layout/LineLength: + Enabled: true Max: 120 - AllowedPatterns: ['\A\s*#:'] Naming/InclusiveLanguage: Exclude: diff --git a/lib/tapioca/commands/abstract_dsl.rb b/lib/tapioca/commands/abstract_dsl.rb index 72ab6437b..b1f90a3d3 100644 --- a/lib/tapioca/commands/abstract_dsl.rb +++ b/lib/tapioca/commands/abstract_dsl.rb @@ -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:, diff --git a/lib/tapioca/commands/abstract_gem.rb b/lib/tapioca/commands/abstract_gem.rb index 0dc7a0b9c..b22edca6a 100644 --- a/lib/tapioca/commands/abstract_gem.rb +++ b/lib/tapioca/commands/abstract_gem.rb @@ -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:, diff --git a/lib/tapioca/commands/annotations.rb b/lib/tapioca/commands/annotations.rb index cf1ca17cc..7c53f6075 100644 --- a/lib/tapioca/commands/annotations.rb +++ b/lib/tapioca/commands/annotations.rb @@ -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, diff --git a/lib/tapioca/commands/check_shims.rb b/lib/tapioca/commands/check_shims.rb index 751d7ee75..b6db84e05 100644 --- a/lib/tapioca/commands/check_shims.rb +++ b/lib/tapioca/commands/check_shims.rb @@ -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:, diff --git a/lib/tapioca/dsl/compiler.rb b/lib/tapioca/dsl/compiler.rb index ae8857299..de440db1c 100644 --- a/lib/tapioca/dsl/compiler.rb +++ b/lib/tapioca/dsl/compiler.rb @@ -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 diff --git a/lib/tapioca/dsl/compilers/active_record_columns.rb b/lib/tapioca/dsl/compilers/active_record_columns.rb index 51d4a0d24..bbb4b3ceb 100644 --- a/lib/tapioca/dsl/compilers/active_record_columns.rb +++ b/lib/tapioca/dsl/compilers/active_record_columns.rb @@ -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, diff --git a/lib/tapioca/dsl/compilers/active_record_relations.rb b/lib/tapioca/dsl/compilers/active_record_relations.rb index af686d6ee..9c8c8269c 100644 --- a/lib/tapioca/dsl/compilers/active_record_relations.rb +++ b/lib/tapioca/dsl/compilers/active_record_relations.rb @@ -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: [], diff --git a/lib/tapioca/dsl/compilers/url_helpers.rb b/lib/tapioca/dsl/compilers/url_helpers.rb index a954046ae..75ab7dd3b 100644 --- a/lib/tapioca/dsl/compilers/url_helpers.rb +++ b/lib/tapioca/dsl/compilers/url_helpers.rb @@ -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). # @@ -78,6 +79,7 @@ module Compilers # include GeneratedUrlHelpersModule # end # ~~~ + # rubocop:enable Layout/LineLength #: [ConstantType = Module] class UrlHelpers < Compiler extend T::Sig diff --git a/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb b/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb index 9fa8db4a9..610d1800b 100644 --- a/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb +++ b/lib/tapioca/dsl/helpers/active_record_column_type_helper.rb @@ -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"] diff --git a/lib/tapioca/dsl/helpers/graphql_type_helper.rb b/lib/tapioca/dsl/helpers/graphql_type_helper.rb index 134d4156c..324ae5f72 100644 --- a/lib/tapioca/dsl/helpers/graphql_type_helper.rb +++ b/lib/tapioca/dsl/helpers/graphql_type_helper.rb @@ -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) @@ -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 diff --git a/lib/tapioca/dsl/pipeline.rb b/lib/tapioca/dsl/pipeline.rb index f93e790a9..0f0d94cce 100644 --- a/lib/tapioca/dsl/pipeline.rb +++ b/lib/tapioca/dsl/pipeline.rb @@ -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: [], @@ -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 diff --git a/lib/tapioca/gem/events.rb b/lib/tapioca/gem/events.rb index ab2cf7404..844541d7c 100644 --- a/lib/tapioca/gem/events.rb +++ b/lib/tapioca/gem/events.rb @@ -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 diff --git a/lib/tapioca/gem/listeners/methods.rb b/lib/tapioca/gem/listeners/methods.rb index acae389d9..a1c38f208 100644 --- a/lib/tapioca/gem/listeners/methods.rb +++ b/lib/tapioca/gem/listeners/methods.rb @@ -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, @@ -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) diff --git a/lib/tapioca/gem/pipeline.rb b/lib/tapioca/gem/pipeline.rb index b6b80d821..542162352 100644 --- a/lib/tapioca/gem/pipeline.rb +++ b/lib/tapioca/gem/pipeline.rb @@ -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 diff --git a/lib/tapioca/helpers/config_helper.rb b/lib/tapioca/helpers/config_helper.rb index 3beacc3af..958678c8c 100644 --- a/lib/tapioca/helpers/config_helper.rb +++ b/lib/tapioca/helpers/config_helper.rb @@ -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] diff --git a/lib/tapioca/helpers/rbi_files_helper.rb b/lib/tapioca/helpers/rbi_files_helper.rb index e40da0437..b6e133e4d 100644 --- a/lib/tapioca/helpers/rbi_files_helper.rb +++ b/lib/tapioca/helpers/rbi_files_helper.rb @@ -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 diff --git a/lib/tapioca/loaders/gem.rb b/lib/tapioca/loaders/gem.rb index 9cdaec742..504b2e02c 100644 --- a/lib/tapioca/loaders/gem.rb +++ b/lib/tapioca/loaders/gem.rb @@ -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, @@ -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() diff --git a/lib/tapioca/rbi_ext/model.rb b/lib/tapioca/rbi_ext/model.rb index 1b69cf21f..a64d600ec 100644 --- a/lib/tapioca/rbi_ext/model.rb +++ b/lib/tapioca/rbi_ext/model.rb @@ -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) diff --git a/spec/spec_with_project.rb b/spec/spec_with_project.rb index 9b2b6d118..c152f36af 100644 --- a/spec/spec_with_project.rb +++ b/spec/spec_with_project.rb @@ -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! diff --git a/spec/tapioca/dsl/compilers/active_record_associations_spec.rb b/spec/tapioca/dsl/compilers/active_record_associations_spec.rb index a35dd5b86..37a29ff7c 100644 --- a/spec/tapioca/dsl/compilers/active_record_associations_spec.rb +++ b/spec/tapioca/dsl/compilers/active_record_associations_spec.rb @@ -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.", diff --git a/tasks/generator_documentation.rake b/tasks/generator_documentation.rake index eb7276a3b..4ce58b66d 100644 --- a/tasks/generator_documentation.rake +++ b/tasks/generator_documentation.rake @@ -7,19 +7,24 @@ require "tapioca/runtime/reflection" YARD::Tags::Library.define_tag("@override", :override) -# A custom docstring parser that ignores RBS signature comments -class IgnoreRBSDocstringParser < YARD::DocstringParser +# A custom docstring parser for Tapioca documentation +class TapiocaDocstringParser < YARD::DocstringParser def parse_content(content) - # Remove RBS signature comments (lines starting with `#:` or `#|`) - # # At this point, `content` represents each line of the docstring where # the `#` has already been stripped. - super(content.sub(/^[:|].*$/, "")) + + # Remove RBS signature comments (lines starting with `#:` or `#|`) + content = content.gsub(/^[:|].*$/, "") + + # Remove Rubocop comments (lines starting with `# rubocop:disable` or `# rubocop:enable`) + content = content.gsub(/^rubocop:(enable|disable) .*$/, "") + + super(content) end end # Use our custom docstring parser for all docstrings -YARD::Docstring.default_parser = IgnoreRBSDocstringParser +YARD::Docstring.default_parser = TapiocaDocstringParser YARD::Rake::YardocTask.new(:yard_for_generate_documentation) do |task| task.files = ["lib/tapioca/dsl/compilers/**/*.rb"]