Closed elbrujohalcon closed 3 years ago
More deeply:
application:get_all_env/0
, application:get_all_env/1
: an option param could be used from the list of param/values it returns.application:set_env/1
, application:set_env/2
: could we remove an option which will be set? (same for unset_env
)More deeply:
application:get_all_env/0
,application:get_all_env/1
: an option param could be used from the list of param/values it returns.
application:set_env/1
,application:set_env/2
: could we remove an option which will be set? (same forunset_env
)
Exactly. But in all those scenarios the atom corresponding to the config key will still be used in the code. That's why we should only mark as unused the atoms that are keys in config files but not present anywhere in the code.
This rule will ignore:
rebar.config
relx.config
elvis.config
*.config
files which are not parseable.It should consider the rebar.config.script
and <app-name>.app.src.script
files.
Name
Unused Configuration Options
Brief Description
This rule should detect environment parameters (the ones set in
.app.src
and.config
files) that are not consumed throughapplication:get_env(…)
anywhere.Reasoning
These are usually leftovers from a previous time when they were used as feature flags or when they configured things in the app that are no longer configurable.
Refactoring Proposal
Just remove the environment params.
Implementation Notes
This is not a simple rule to implement, for various reasons:
.config
and.app.src
files andktn_dodger
doesn't parse them yet. It might be possible to usefile:consult/1
, tho.application:get_env(…)
indirectly. For instance, with a variable (e.g.application:get_env(my_app, Param, Default)
) or even througherlang:apply(application, get_env, […])
. Maybe it would be better not to look forapplication:get_env(…)
at all and just verify if the atoms corresponding to the properties are present in the code (i.e. regardless of what they're used for).