unused_record_fields (rebar3_hank v2.0.0)

View Source

A rule to detect unused record fields.

The rule will detect fields that are defined as part of a record but never actually used anywhere.

To avoid this warning, remove the unused record fields.

Notes

Native Records

Keep in mind that this rule only works with tuple records. It ignores native records altogether.

Record Name Collisions

Note that for header files, this rule will fail to detect some unused fields. Particularly, in the case where you have an unused field defined in a header file and another record with the same name and the same field defined somewhere else that is used.

Since determining precisely what files are included in each -include attribute is not trivial, Hank will act conservatively and not make any effort to verify where each record field that's used is defined.

So, if you have a project with multiple definitions of the same record with the same field... well... as long as one of them is used, none of them will be reported as unused.

Tuple Access

This rule assumes that your code will never use the underlying tuple structure of your records directly. If you do so, you can add an ignore rule in rebar.config for it.

Summary

Functions

Rule ignore specifications. Example

Functions

ignored/2

-spec ignored(hank_rule:ignore_pattern(), term()) -> boolean().

Rule ignore specifications. Example:

-hank([{unused_record_fields,
         [a_record, %% Will ignore all fields in #a_record
          {a_record, a_field} %% Will ignore #a_record.a_field
         ]}]).