I wanted to share with everyone some elm-review rules I’ve written for reviewing Elm ports and hopefully avoid a few pain points that I’ve come across learning to work with ports.
There are three rules in the package so far:
- NoDuplicatePorts - Ensure that port names are unique across your project.
- NoUnsafePorts - Forbid unsafe types in ports.
- NoUnusedPorts - Ensure that all defined ports have been used.
Inspired by the information about Verifying Flags in the Elm guide, this rule reports any ports that do not send or receive a
This rule reports any ports that are not used anywhere in the project. A port is only considered used if it can be traced to a
app.ports object will be
This was a surprisingly tricky rule to write as it takes quite a lot of effort to trace a function all the way to
main. One bonus of doing this though is that the rule can point at where it lost the trace. Here’s an example of what that report looks like: