codeclimate/codeclimate

View on GitHub
lib/cc/analyzer/engine_output.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
97%

#to_json requires an optional argument to be parsable via JSON.generate(obj).
Open

      def to_json
        if issue?
          as_issue.to_json
        elsif measurement?
          Measurement.new(name, raw_output).to_json
Severity: Minor
Found in lib/cc/analyzer/engine_output.rb by rubocop

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

There are no issues that match your filters.

Category
Status