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

New rule: no unused fields #74

Open
jfmengels opened this issue Nov 13, 2022 · 0 comments
Open

New rule: no unused fields #74

jfmengels opened this issue Nov 13, 2022 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@jfmengels
Copy link
Owner

jfmengels commented Nov 13, 2022

As some have probably already run into, NoUnused.CustomTypeConstructorArgs has some false positives, where it tells you that Int in type A = A Int is unused because it is never extracted but in some places you do value == A 0.

The way I’m currently thinking of resolving this is to register all the types that are used directly or indirectly in comparisons (== or /=), and to not report issues for those types at all. So if you have a type alias Record = { a : A, ... } and I notice that something is a Record and is being used in a comparison, then it won’t report the constructor arguments of A.

This would require (or become a lot easier?) with type information, though I think it’ll still be a difficult rule to write.

In some cases, it might still be complicated to notice that something is used as a comparison. For instance, when something is used as the key of a Dictionary (like AssocList). One option here is to look at dependencies’ code to notice that == is used in the implementation on the key, therefore whatever key is passed to an AssocList.Dict is marked as being compared. If that doesn’t work, then asking for configuration could be used as a stop-gap measure (or a temporary measure until we can visit dependencies)

I’m thinking the same thing will probably be useful for other data that is stored, like tuples and record fields. So I’m thinking maybe instead of having NoUnused.CustomTypeConstructorArgs, NoUnused.RecordFields (#15) and NoUnused.TupleFields (#16), we could have a single NoUnused.Data/NoUnused.Fields rule (name TBD).

@jfmengels jfmengels added the help wanted Extra attention is needed label Nov 13, 2022
@jfmengels jfmengels changed the title NoUnused.Fields New rule: no unused fields Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant