From 73bb781d1d6bd6959621acc89a831ecbd27113b6 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sat, 23 Aug 2025 09:23:25 -0700 Subject: [PATCH] Enable strict typing in yard extensions --- Library/Homebrew/yard/docstring_parser.rb | 6 +++++- .../Homebrew/yard/templates/default/docstring/html/setup.rb | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/yard/docstring_parser.rb b/Library/Homebrew/yard/docstring_parser.rb index b36262a254..947289a9ab 100644 --- a/Library/Homebrew/yard/docstring_parser.rb +++ b/Library/Homebrew/yard/docstring_parser.rb @@ -1,6 +1,9 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true +require "sorbet-runtime" +require_relative "../extend/module" + # from https://github.com/lsegal/yard/issues/484#issuecomment-442586899 module Homebrew module YARD @@ -18,6 +21,7 @@ module Homebrew private_constant :SELF_EXPLANATORY_METHODS end + sig { params(content: T.nilable(String)).returns(String) } def parse_content(content) # Convert plain text to tags. content = content&.gsub(/^\s*(TODO|FIXME):\s*/i, "@todo ") diff --git a/Library/Homebrew/yard/templates/default/docstring/html/setup.rb b/Library/Homebrew/yard/templates/default/docstring/html/setup.rb index ab197a0fe6..c747ba0d98 100644 --- a/Library/Homebrew/yard/templates/default/docstring/html/setup.rb +++ b/Library/Homebrew/yard/templates/default/docstring/html/setup.rb @@ -1,12 +1,13 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true # This follows the docs at https://github.com/lsegal/yard/blob/main/docs/Templates.md#setuprb # rubocop:disable Style/TopLevelMethodDefinition +sig { void } def init # `sorbet` is available transitively through the `yard-sorbet` plugin, but we're # outside of the standalone sorbet config, so `checked` is enabled by default - T.bind(self, T.all(Class, YARD::Templates::Template), checked: false) + T.bind(self, T.all(T::Class[T.anything], YARD::Templates::Template), checked: false) super return if sections.empty? @@ -14,6 +15,7 @@ def init sections[:index].place(:internal).before(:private) end +sig { returns(T.nilable(String)) } def internal T.bind(self, YARD::Templates::Template, checked: false) erb(:internal) if object.has_tag?(:api) && object.tag(:api).text == "internal"