Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1098] Detect unused record fields #1099

Merged
merged 2 commits into from
Sep 30, 2021
Merged

Conversation

robertoaloi
Copy link
Member

Description

Screenshot 2021-09-30 at 08 16 39

@robertoaloi robertoaloi force-pushed the 1098-detect-unused-record-fields branch 3 times, most recently from e6c43c9 to 532a154 Compare September 30, 2021 06:19
@robertoaloi robertoaloi changed the title [1098] Detect unused record fields [#1098] Detect unused record fields Sep 30, 2021
@robertoaloi robertoaloi force-pushed the 1098-detect-unused-record-fields branch from 532a154 to 1cb142e Compare September 30, 2021 07:51
@robertoaloi robertoaloi force-pushed the 1098-detect-unused-record-fields branch from 1cb142e to e43534b Compare September 30, 2021 10:09
{RecordName, RecordField} ->
els_utils:to_binary(
lists:flatten(io_lib:format("~p/~p", [RecordName, RecordField])));
Id -> atom_to_binary(Id, utf8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which case can the Id be an atom?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's copy-paste from the Unused Macro diagnostics backend, cleaning.

case POIId of
{RecordName, RecordField} ->
els_utils:to_binary(
lists:flatten(io_lib:format("~p/~p", [RecordName, RecordField])));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: what about ~p.~p or #~p.~p? (looks more recody syntax)

FullName =
case POIId of
{RecordName, RecordField} ->
els_utils:to_binary(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

els_utils:to_binary( supports deep lists (unicode:chardata()) so no need to flatten. On the other hand should we use ~tp instead of ~p to properly print unicode atoms? (I am always confused with unicode, maybe a new atom_to_label function in els_utils could have it right once and that could be used in the whole code base)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that approach. So, I will keep it for now and handle this as a follow up (feel free to contribute on that).

find_unused_record_fields(Document) ->
Definitions = els_dt_document:pois(Document, [record_def_field]),
Usages = els_dt_document:pois(Document, [record_field]),
UsagesIds = [Id || #{id := Id} <- Usages],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimisation: UsagesIds could be an usort-ed list

@robertoaloi robertoaloi merged commit 221f4c6 into main Sep 30, 2021
@robertoaloi robertoaloi deleted the 1098-detect-unused-record-fields branch September 30, 2021 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants