Skip to content

Commit

Permalink
[Fix rubocop#12910] Ensure that RuboCop runs warning-free
Browse files Browse the repository at this point in the history
This is inspired by how Rails approaches this
  • Loading branch information
Earlopain committed May 27, 2024
1 parent a9bce34 commit 1250aa6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
require 'rainbow'
Rainbow.enabled = false

require_relative 'support/strict_warnings'
StrictWarnings.enable!

require 'rubocop'
require 'rubocop/cop/internal_affairs'
require 'rubocop/server'
Expand Down
32 changes: 32 additions & 0 deletions spec/support/strict_warnings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module StrictWarnings
class WarningError < StandardError; end

# Warnings from 3rd-party gems
SUPPRESSED_WARNINGS = Regexp.union(
%r{lib/parser/builders/default.*Unknown escape},
%r{lib/parser/builders/default.*character class has duplicated range},
/internal.*Float.*out of range/ # also from the parser gem
)

def warn(message, ...)
return if SUPPRESSED_WARNINGS.match?(message)

super
# RuboCop uses `warn` to display some of its output and tests assert against
# that Assume that warnings are intentional when stderr is redirected.
return if $stderr.is_a?(StringIO)
# Ignore warnings from dev/rc ruby versions. Things are subject to change and
# contributors should not be bothered by them with red CI.
return if RUBY_PATCHLEVEL == -1

raise WarningError
end

def self.enable!
$VERBOSE = true
Warning[:deprecated] = true
Warning.singleton_class.prepend(self)
end
end

0 comments on commit 1250aa6

Please sign in to comment.