Merge pull request #20557 from Homebrew/dug/typed-yard

Enable strict typing in yard extensions
This commit is contained in:
Mike McQuaid 2025-08-23 19:39:23 +00:00 committed by GitHub
commit 5e3a8d96c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -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 ")

View File

@ -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"