hauleth/mix_unused

Handling false positives

Maxximiliann opened this issue · 1 comments

hint: AppDB.TableOne.__changeset__/0 is unused
    lib/Schemas/TableOne.ex:5

hint: AppDB.TableOne.__schema__/1 is unused
    lib/Schemas/TableOne.ex:5

hint: AppDB.TableOne.__schema__/2 is unused
    lib/Schemas/TableOne.ex:5

hint: AppDB.TableOne.__struct__/0 is unused
    lib/Schemas/TableOne.ex:5

hint: AppDB.TableOne.__struct__/1 is unused
    lib/Schemas/TableOne.ex:5

hint: AppDB.TableOne.changeset/2 is unused
    lib/Schemas/TableOne.ex:15

hint: Server.Alpha.child_spec/1 is unused
    lib/GenServers/Server.Alpha.ex:2

hint: Server.Alpha.start_link/1 is unused
    lib/GenServers/Server.Alpha.ex:4

hint: Supervisor.Main.child_spec/1 is unused
    lib/Life Cycle Managers/Supervisor.Main.ex:2

hint: AppDB.Repo.child_spec/1 is unused
    lib/Schemas/repo.ex:2

hint: AppDB.Repo.query/3 is unused
    lib/Schemas/repo.ex:1

hint: AppDB.Repo.query!/3 is unused
    lib/Schemas/repo.ex:1

hint: AppDB.Repo.to_sql/2 is unused
    lib/Schemas/repo.ex:1

First off, great project it's been a life-saver! :) Quick question: how can I keep these false positives from triggering?

Ok, I see I should probably add additional feature to automatically filter out __struct__/{0,1}. About the rest there is a way to configure it via project/0 :unused configuration key. So in your case it can be:

unused: [
  ignore: [
    AppDB.Repo, # Ignore all functions of all arities in `AppDB.Repo` module, as these functions are generated
    {:_, :start_link, 1}, # Ignore all functions `start_link/1` in all modules
    {:_, :child_spec, 1}, # Ignore all functions `child_spec/1` in all modules
    {:_, :__struct__, 0..1}, # Ignore all functions (or macros in this case) `__struct__/{0,1}`
    {:_, :__changeset__, 0} # Ignore all functions `__changeset__/0` in all modules
  ]
]

I see that this part of the configuration confuses a lot of people, so if you have any suggestions how to improve it, it will be welcomed (also if you are interested, then with enough PRs you can get free T-Shirt, as this repo participates in Hacktoberfest).