Be clear, concise and precise in your description of the problem.
Open an issue with a descriptive title and a summary in grammatically correct,
complete sentences.
Use the template below when reporting bugs. Please, make sure that
you're running the latest stable RuboCop and that the problem you're reporting
hasn't been reported (and potentially fixed) already.
MinSize parameter is omitted, or properly serialized when @largest_brackets is negative infinity.
Value is serialized as a string, in the display format for negative infinity (e.g. -Infinity), not the YAML syntax for negative infinity (-.inf). This results in a type mismatch in word_array.rb, around line 27 (as of RuboCop 0.38.0) because FixNum and String can't be compared with >=:
if style == :percent && array_elems.size >= min_size
add_offense(node, :expression, PERCENT_MSG)
end
I'm not sure what in the large codebase I'm applying RuboCop to is causing this outcome but the root of the problem is apparently here:
def style_detected(style, ary_size)
cfg = config_to_allow_offenses
return if cfg['Enabled'] == false
@largest_brackets ||= -Float::INFINITY
@smallest_percent ||= Float::INFINITY
if style == :percent
@smallest_percent = ary_size if ary_size < @smallest_percent
elsif ary_size > @largest_brackets
@largest_brackets = ary_size
end
if cfg['EnforcedStyle'] == style.to_s
# do nothing
elsif cfg['EnforcedStyle'].nil?
cfg['EnforcedStyle'] = style.to_s
elsif @smallest_percent <= @largest_brackets
self.config_to_allow_offenses = { 'Enabled' => false }
else
cfg['EnforcedStyle'] = 'percent'
cfg['MinSize'] = @largest_brackets + 1
end
end
We're apparently falling into the final else of the last if/else cascade, with @largest_brackets still having a value of -Float::INFINITY. Adding one to -Inf is still -Inf.
I suggest that it be fixed by changing this:
cfg['MinSize'] = @largest_brackets + 1
To this:
cfg['MinSize'] = @largest_brackets + 1 if @largest_brackets.finite? # This will guard against +inf, -inf, and nan
Include the output of rubocop -V:
$ rubocop -V
0.38.0 (using Parser 2.3.0.6, running on ruby 2.2.2 x86_64-darwin15)
See this too on rubocop 0.47.1
I want to help triage this issue, but under "Steps to reproduce the problem" is a block of Rubocop's implementation and some suggested changes. How can I reproduce this?
The lack of useful information from Rubocop when the error occurs -- because of an uncaught exception -- made it impractical to identify what exactly was triggering the problem.
I think this is a duplicate of #2740. More diagnosing has happened over there, but it hasn't been resolved yet. If either of you could contribute to that thread, it might lead to a resolution.
I recommend closing this issue as a duplicate.
I was curious whether I could reproduce this bug given that #2740 felt sort of like a murder mystery :laughing:. I was able to give a simple reproduction. See here https://github.com/bbatsov/rubocop/issues/2740#issuecomment-275007739
Most helpful comment
I was curious whether I could reproduce this bug given that #2740 felt sort of like a murder mystery :laughing:. I was able to give a simple reproduction. See here https://github.com/bbatsov/rubocop/issues/2740#issuecomment-275007739