|
1 | | -file = Dir.glob("..") |
2 | | -p file |
3 | | -load file.first |
4 | | - |
5 | | -# This module flags methods in rails tests and blows up ours |
6 | | -module ActiveSupport |
7 | | - module RaiseWarnings # :nodoc: |
8 | | - begin |
9 | | - allowed = remove_const(:ALLOWED_WARNINGS) |
10 | | - const_set(:ALLOWED_WARNINGS, Regexp.union(allowed, /previous definition of/)) |
11 | | - end |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +$VERBOSE = true |
| 4 | +Warning[:deprecated] = true |
| 5 | + |
| 6 | +module RailsStrictWarnings # :nodoc: |
| 7 | + class WarningError < StandardError; end |
| 8 | + |
| 9 | + PROJECT_ROOT = File.expand_path("../", __dir__) |
| 10 | + ALLOWED_WARNINGS = Regexp.union( |
| 11 | + /circular require considered harmful.*delayed_job/, # Bug in delayed job. |
| 12 | + |
| 13 | + # Expected non-verbose warning emitted by Rails. |
| 14 | + /Ignoring .*\.yml because it has expired/, |
| 15 | + /Failed to validate the schema cache because/, |
| 16 | + /previous definition of/ |
| 17 | + ) |
| 18 | + |
| 19 | + SUPPRESSED_WARNINGS = Regexp.union( |
| 20 | + # TODO: remove if https://github.com/mikel/mail/pull/1557 or similar fix |
| 21 | + %r{/lib/mail/parsers/.*statement not reached}, |
| 22 | + %r{/lib/mail/parsers/.*assigned but unused variable - disp_type_s}, |
| 23 | + %r{/lib/mail/parsers/.*assigned but unused variable - testEof} |
| 24 | + ) |
| 25 | + |
| 26 | + def warn(message, ...) |
| 27 | + return if SUPPRESSED_WARNINGS.match?(message) |
| 28 | + |
| 29 | + super |
| 30 | + |
| 31 | + return unless message.include?(PROJECT_ROOT) |
| 32 | + return if ALLOWED_WARNINGS.match?(message) |
| 33 | + return unless ENV["RAILS_STRICT_WARNINGS"] || ENV["BUILDKITE"] |
| 34 | + |
| 35 | + raise WarningError.new(message) |
12 | 36 | end |
13 | 37 | end |
| 38 | + |
| 39 | +Warning.singleton_class.prepend(RailsStrictWarnings) |
0 commit comments