forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix rubocop#12910] Ensure that RuboCop runs warning-free
This is inspired by how Rails approaches this
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |