Skip to content

Commit

Permalink
Merge pull request #18443 from Homebrew/warnings-strict
Browse files Browse the repository at this point in the history
warnings: `typed: strict`
  • Loading branch information
MikeMcQuaid authored Sep 30, 2024
2 parents fcdd014 + 112c692 commit 4f07e2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/test/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
end
end

require_relative "../standalone"
require_relative "../warnings"

Warnings.ignore :parser_syntax do
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/warnings.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# typed: true # rubocop:todo Sorbet/StrictSigil
# typed: strict
# frozen_string_literal: true

require "warning"

# Helper module for handling warnings.
module Warnings
COMMON_WARNINGS = {
COMMON_WARNINGS = T.let({
parser_syntax: [
%r{warning: parser/current is loading parser/ruby\d+, which recognizes},
/warning: \d+\.\d+\.\d+-compliant syntax, but you are running \d+\.\d+\.\d+\./,
%r{warning: please see https://github\.com/whitequark/parser#compatibility-with-ruby-mri\.},
],
}.freeze
}.freeze, T::Hash[Symbol, T::Array[Regexp]])

def self.ignore(*warnings)
sig { params(warnings: T.any(Symbol, Regexp), _block: T.nilable(T.proc.void)).void }
def self.ignore(*warnings, &_block)
warnings.map! do |warning|
next warning if !warning.is_a?(Symbol) || !COMMON_WARNINGS.key?(warning)

Expand All @@ -25,8 +26,7 @@ def self.ignore(*warnings)
end
return unless block_given?

result = yield
yield
Warning.clear
result
end
end

0 comments on commit 4f07e2f

Please sign in to comment.