Skip to content

struct-new-override

Rubysuspiciousno fixdefault: warnruby/rubocop

Reports a Struct.new member that has the name of a method of Struct (:hash, :size, :count).

The generated accessor replaces the method of Struct, which other code and the class itself depend on. hash breaks use as a hash key and size breaks code that reads the members.

To fix, rename the member.

Reported
...
h.key?(x.id)
...
2.times { f }
Struct.new(:hash, :name)
...
ruby:
lint:
rules:
struct-new-override: warn # off, warn (default), error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line struct-new-override in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/StructNewOverride full