lib/cc/analyzer/engine_output.rb
#to_json
requires an optional argument to be parsable via JSON.generate(obj). Open
Open
def to_json
if issue?
as_issue.to_json
elsif measurement?
Measurement.new(name, raw_output).to_json
- Read upRead up
- Exclude checks
Checks to make sure #to_json
includes an optional argument.
When overriding #to_json
, callers may invoke JSON
generation via JSON.generate(your_obj)
. Since JSON#generate
allows
for an optional argument, your method should too.
Example:
class Point
attr_reader :x, :y
# bad, incorrect arity
def to_json
JSON.generate([x, y])
end
# good, preserving args
def to_json(*args)
JSON.generate([x, y], *args)
end
# good, discarding args
def to_json(*_args)
JSON.generate([x, y])
end
end