elm-review Tips

We revisit elm-review with some tips, useful workflows, and helpful packages that have come out since our intro to elm-review episode.
January 4, 2021

Some tricks to easily try elm-review with no setup:

npx elm-review --template jfmengels/elm-review-unused/example

Init with a given template:

npx elm-review init --template jfmengels/elm-review-unused/example

Incremental adoption

Useful packages and workflow


Hello, Jeroen.
Hello, Dillon.
Well, here we are again several months later, and it's time to look back on Elm Review.
Yeah, I love these episodes.
We should do way more.
Way more Elm Review episodes.
Just each week, let's do an Elm Review episode.
Yeah, let's do that.
Sometimes we can talk about your tools.
You know them, mine are better.
Oh yeah?
Well, you can, your tools can review my tools.
Can your tools review mine?
Your tool just reviewed my tool before this episode, which was fun.
Got a personal walkthrough with Jeroen on the Elm pages code base.
And he has a lot of dead code.
You haven't fixed everything.
That's true.
I still have some dead code.
And with your nose, you've been a naughty boy.
Cool for me this year.
If you clean your projects by Monday, then maybe Santa will come and give you some gifts.
Well, you better check that list twice.
Check the Elm Review rules twice.
All right.
So the idea was just to give you, no, let's grab that sentence.
So we talked about Elm Review in episode three, and I think we gave a pretty good foundation
of like the concept and what it is.
To reiterate, it's a way to review your Elm code written in Elm.
You can write your own rules or you can install other Elm packages for Elm Review rules that
others have written.
And it's more than just a linter.
It can enforce best practices in a particular code base following the norms that you have
in your team.
It can do static analysis.
Today we're kind of going to look back at some of the lessons learned, some of the tips
that you've found to be useful when using Elm Review, some tips on getting started,
some cool use cases.
So we're kind of going to look at some of the things you've learned over the past few
So one of the things that I noticed is that a lot of people don't try the tool.
So yeah, unless you put it right in front of the noses, they just won't try it out.
And then they won't notice that it's good or that it's helpful for them.
So I tried to make it easier for them.
So you're a good example because you haven't tried this before.
Well, I have used your try version actually.
But sometimes I tried setting it up on a live stream once, but then I found some issue that
I didn't get past, which I probably could have with a little more time and didn't stick
with it.
Now it's bug free, by the way.
But just having a way to just try it from the command line without any setup I think
is really useful.
And I think I agree with your theory that people should just try it out and they'll
enjoy it once they get using it.
And especially like in a team environment, actually one of my clients recently started
using Elm Review.
And it was really nice to see these unused bits of code and I really enjoyed that workflow
as part of the refactoring experience because you sort of try to refactor and expose some
unused code, remove that and the tool can sort of help you with that refactoring.
We'll go through that afterwards.
So yeah, what I noticed is that a lot of people don't even try it out.
I just thought I would make it easier to try it out.
So there's one thing that comes with NPM, which is called NPX.
So I think that's since NPM 6.
Where you can just do NPX, the name of a JavaScript NPM binary, and then it goes to download it
and it runs it.
It takes a long time, but you can try things out without installing it globally or in your
So that is very nice.
And then I also added a dash dash templates flag to Elm Review.
So what it does is Elm Review needs a configuration to work.
And I don't want to impose a default configuration for several reasons that we can talk about
later if you want.
So if you don't have a configuration, Elm Review won't do anything.
So what dash dash template does is it fetches a configuration on GitHub, downloads it, and
then it runs Elm Review with that configuration.
So you can try Elm Review without pre configuring it.
So if you do NPX Elm Review dash dash templates and then some GitHub repository, then you
can just try it out like this.
So the example that I would usually give is NPX Elm Review dash dash templates, JFM angles,
that's my name, slash Elm Review unused with dashes between them.
And then you say slash example, so we use the example configuration that is on the GitHub
And then you just try it out and see what it reports and see if you like it.
So basically the template flag in the Elm Review CLI in conjunction with NPX to sort
of execute a package that you don't have in your NPM setup, you can run NPX Elm Review,
pass in a template, use a GitHub repository and use the configuration, which the config
is an Elm file, an Elm folder, an Elm project, it has an Elm.json with dependencies, and
you can just point it at one of these in a GitHub repository and run those rules.
So that's, it's awesome.
You should definitely try out the Elm Review unused example and just particularly try letting
it auto fix your unused code.
So yeah, once you've tried that out and if you find that you like it and you like those
rules, what you can do is initialize your project.
So there's an Elm Review init command, which initializes, which creates a blank project,
but you can also do init dash dash templates, which then just copies that configuration
from GitHub to your project.
So if you liked it, reuse it.
And then if you find new rules, then you will have to add them manually.
It's not as scary as it seems.
The init command just creates a folder called review, which has a module called review config,
and it has an Elm.json, which has dependencies, which will include some Elm Review packages.
And that's it.
And when you run Elm Review from your root directory, it goes into that review directory
and runs that Elm project.
That's all it is.
So init just creates that for you, and then you run Elm Review and you can add rules to
that list of rules in your review config.elm.
So what do you recommend for the CI workflow for, you know, if somebody is using GitHub
actions or something like that?
Yeah, well, first of all, I really, really recommend to put Elm Review in your CI.
If you put Elm Review in your project, don't enforce the rules on CI, especially when you're
working on a team that will just lead to chaos.
From having to try it out several times, it's not a good idea.
If you have tests or static analysis tools and whatever checks, you need to enforce them
on the CI.
Even if you enforce them using GitHub locally, that is not enough.
I've seen it go wrong many times.
Yeah, right.
It's better to have a smaller number of rules that are being checked that are checked in
CI and completely clean rather than a large number of rules with some noise of things
that are not following those rules and it not checked in CI.
Because at that point, that defeats the whole purpose because it doesn't allow you to just
run it and see everything is green.
So you don't know.
Although I think you did work a little bit on this backsliding workflow at some point.
I'm not sure where that stands.
Have you come to any conclusions about that workflow of having a number of failures and
saying it shouldn't go beyond this number of failures?
Have you tried it and decided it's a bad idea?
Or where do you stand with that?
That is still something I really want to have.
Just haven't worked on it and haven't figured out a nice way of using it yet.
Of capturing the exact errors?
The thing is, you have a configuration that says what rules you want to enforce on your
project and you also have ignored problems.
Currently you can use ignore errors for files or ignore errors for directories to say this
rule or all rules should not report problems for these.
Those are ideally used for vendor code or generated code that you don't want to be linted
or reported.
But sometimes you want to enable rule bit by bit.
What you need to do is either fix everything in one go or you need to use those two functions.
The idea would be to have another function that says Elm Review should ignore these errors
here and there, but only temporarily.
If things get worse, like for instance, we used to allow five errors and now there are
six, then Elm Review will report things because things got worse.
It will tell you to update the configuration if it gets less.
So that is something I really want.
I just haven't worked on it yet.
The problem is that you've got a configuration, a set of rules that you want, and then there's
how should it apply to my specific projects.
Those are the ignored files.
Ideally if your company uses the same configuration for several projects, then you would like
to share those.
But if you have ignored errors, then that doesn't work anymore because those ignored
errors are specific to some projects.
So there's two worlds that I just can't fit together yet.
It's a difficult problem because these sort of workflows can really be crutches as well.
One of the things that I think is most powerful in building software is this concept of minimizing
work in progress, not having too many balls in the air at once.
Whether that's building one feature rather than having 20 work in progress features that
are partially working.
You should see something through all the way, all the way through end to end.
You should build a feature and not just build the front end piece for five different features
and then start building and implementing the back ends.
Build it all the way through.
So this concept of reducing work in progress and seeing something through all the way is
something that I really believe increases quality and efficiency in building things.
This is sort of like this lean concept of pushing something through rather than kind
of this mass manufacturing, do a bunch of things on the production line.
It can really increase quality and make things much more efficient.
I think that the same applies to static analysis tools.
Turn on one rule, turn on no unused functions, and then fix all of them.
If there are some cases where you're like, wait a minute, but this is unused, but I need
to use it.
And so I need to, you know, instead of just saying, well, let's come around to that later.
We've got one problem.
We fixed all of the unused functions except for this one that it's complaining about.
Let's go add these other rules now and then have like a few issues in several different
It's a better use of your time to just take the time to clean up all of the unused functions,
get that completely sorted out, get it in your CI.
Now you have at least one rule and it's completely clean and you can trust it and it's integrated
into your workflow.
And if there are any unused things, your CI is going to catch it before you get that code
into production.
So I think that's in general, I think you would recommend that process as well, that
like just follow one rule through until it's fully integrated.
I'm not sure.
In our workplace, we tried turning on quite a few of them and fixing them all automatically
when possible.
But then we still got a lot of errors that required a lot of work or just decisions because
you don't always know whether something that is unused should be used or whether it can
be removed.
Like probably someone aimed to use it, but it didn't got used for some reason.
That might've been a mistake.
You don't know if you should remove it or whether you should keep it and use it.
And what we did was we added a lot of ignore errors for files.
And then we hoped that someone would fix those issues.
And well, that took a while for us to prioritize.
I mean, there's always version control though, right?
Like if it's in version control, then why not just delete something that's not being
Well, it does become harder to find.
But yeah, as we went along, we were thinking more and more like Yagni, you ain't going
to need it.
So just delete it.
And hopefully if we need it back, then someone will remember it, that it was there at some
So yeah, we had a lot of ignored errors, but we at least caught a lot of more errors.
So yeah, I don't know.
I think there's a lot of value in fixing everything, but depending on how hard it will be, maybe
a mix of the two would be nice.
I'm not so dogmatic at least.
But either way, step one should be a CI process, a build that is running your Elm review rules
and passing.
However you get there, that's step zero.
And if you need to ignore some files or minimize the number of rules you're using or whatever
you need to do to get there, that's step zero.
And then you build from there.
So it might be interesting to say why you need to enforce it at CI.
So imagine that I run Elm review on my machine, which I obviously do, and I fix a lot of errors.
So everything's green now.
I push it to master, someone pulls it, then commit something, then I pull again and I
get some errors and I'm like, no, no.
If you don't enforce it at CI, then someone will introduce things.
And well, the one who will have to fix it is the one that is running it.
But if it's running CI, then everyone has to fix it.
And it's a shared responsibility.
This is actually a principle that I think of in terms of lean thinking as well.
Sometimes people use the term Kanban in the software world, that you want to minimize
the amount of time that something is in progress.
And you want to tighten all these feedback loops.
So the shorter the amount of time between finding and fixing a bug, or the shorter the
amount of time you can have a unit test failing, the shorter the amount of time you can work
on a feature.
So rather than working on a giant feature, you work on a tiny slice of a feature and
get it all the way through and done.
The better.
If you don't have your continuous integration server as a shared single source of truth
that things are good, then you're going to get drift where things are drifting away from
a stable green state.
And you want that feedback loop as short as possible.
So we mentioned that we need to fix a lot of issues to get everything clean.
And Elm Review does provide automatic fixes, as we have mentioned briefly.
So it comes with two flags, dash dash fix and dash dash fix dash all.
So what fix does is that it runs Elm Review, finds at least one error with an automatic
fix and then it tells you, hey, I've found this error and I can fix it like this.
Do you want me to do that?
And then you say yes or no.
And then it will go to the next one.
It's like an interactive prompt, like a git commit dash P or that sort of thing.
Yeah, definitely.
Or git add dash P. Yeah.
If you're new to Elm Review, I really recommend using that because if you do fix all, then
you will see a lot of deleted code or changed code.
And that might be a bit frightening, but if you go through them all one by one, then you
will know why something was removed or something was changed with a lot of details because
we do try to make very good error messages.
So yeah, go through them all.
And once you're familiar with the process or the errors that are reported, then you
can go and use fix all.
So the fix all is very useful also.
So at first I was against having a fix all, but I turned around and I love it now.
But it can be a bit slow, especially when you run it on a very big project, which has
a lot of unused code.
So it speeds up when that unused code is removed.
At least that's what I've heard.
So the way it works is that it does that interactive fix in memory.
So it finds one fix, it applies it, it re reviews everything again, and it finds one
that has an automatic fix, it applies it, and over and over and over again.
It's not very optimized yet.
So if you have a lot of dead code and a very big project, it can take a long, long time.
I do plan on improving that, but I haven't succeeded yet, fortunately.
And the good news is that it's a reliable process just finding all the unused spots.
So you just run it and you can just commit it and your code is going to keep compiling.
And if you don't feel comfortable just committing it directly, then you can use a git diff tool
and go in and choose the pieces of dead code that you're comfortable committing as removed.
What you can do to speed it up is to use the rules flag.
So that says run this configuration, but only run this and that rule.
You separate them by comma and you can just run it with a dash dash rules, no unused
exports and no unused variables.
So those are the main ones that will delete a lot of code.
Running only with those two will speed things up a lot.
And hopefully later on, it will be as fast as just running those two.
So you can also use the rules flag to run a single rule, which can be useful to run
a new rule that you've just installed, for instance.
Or when you only want to fix one kind of error, just like Tindon said, go one way, go one
rule and do it all the way down.
What you can also do, and that is I think my favorite feature in Elm review is the watch
So the watch mode is going to run the Elm review process, but not stop it after it has
reviewed your project.
And every time you touch it, every time you touch a file or remove a file, add a file,
it will rerun Elm review and report the new things.
So you can run that next to your ID, for instance, and then it will report things as you type.
It works quite well with updating your review config as well.
Yeah, it also watches that and reruns it.
So is that your typical workflow?
You've got like a window with a review Elm review watch running as you're writing code
and you've got that like on the side of your monitor as you're writing your Elm code?
Is your workflow something like that?
Sometimes yeah.
It's always sometimes I just run it at the end because it's mostly about unused code.
The rest I'm aware of what I should need to do myself.
But what I usually do when I do that is I run Elm review dash dash watch dash dash
fix all because those work together.
So every time I'm done with what I'm working on Elm review will let me know about all the
code that can be removed or all the fixes that I can apply automatically.
I just go to my terminal and say yes and commit that.
And that is my usual workflow when I do that.
For unused functions does that mean that you don't hit save until you've used a function
somewhere or does that mean that you define a function by calling like invoking the function
and then use your IDE to define it or something like that?
How does that work?
I just write my code as usual and when I'm done then I go to the terminal and press enter
because even in fix all it asks you.
It asks you to remove the code or not.
So it's not like you have to use things that you define and stop pressing save.
You want to know about it if that happens at some point and you may or may not mean
to have unused code.
But I only look at that when I'm out of the flow that it was in.
You know when you're doing like TDD, I'm running the codes as ugly as possible but I'm going
to get a test to pass.
Once that is done then I clean up.
That makes sense.
So you've got like a green mode and a refactor mode and if you're like implementing something
then you're not in refactor mode.
That makes sense.
I'm looking at the unused functions when I'm trying to make things pass.
That said looking at Elm review can tell me like hey it's not working because you're not
using that function that you just defined.
But yeah usually I do find the problems.
So since we talked about this last back in April a lot of new packages have emerged that
you've written and that other people have written and I'm sure you've got some cool
like internal workflows at Humia that you're using and have heard about others that other
people are using in their own companies.
So let's talk about some specific review rules and some use cases.
So like what are some of the new review rules that you're excited about and some of the
cool use cases you've heard about?
Do you mean the ones that are used specific for Humia or do you mean in general?
Just any you know the most useful rules that you've used or heard of people using.
What are some of the sort of new things that have come out since we last spoke about this?
One of my favorite ones is one that is very niche.
It's only for package authors.
Maybe even just for Elm review package authors.
So in the Elm review packages there's always a link to the different rules.
In the readme there's a link to no unused variables and that one needs to link to the
version of this package.
So you need to link to version 1.2.0 of the no unused variables rule.
You don't want to link to latest because otherwise links get broken when new versions arise.
You don't want to always link to 1.0.0 because then you have outdated documentation.
Or you're sending to outdated documentation.
So what I have is a rule that reads the Elm JSON file, finds the version and then everywhere
in the readme and later on in the rest of the documentation finds those links and replaces
the version.
So every time I'm going to publish a version I do Elm bump and I do Elm review fix all
and it fixes all the dead links.
Oh that's cool.
So now I don't have any outdated docs and I don't have any links that send to latest.
So I'm very happy about that.
That sounds great.
I mean yeah those types of workflows are so helpful.
Like I've been using Elm verify examples a lot in this package I've been developing recently
and it's the kind of thing where having the examples in the documentation and having that
be not just useful documentation but executable documentation is so valuable because otherwise
you end up like I was finding myself writing these like beautiful meaningful test cases
and then in the documentation I'm like hmm that unit test I had was a really nice example.
I should include that in the documentation for this function.
And then I'm like well but what if it gets out of sync?
So it just works so nicely that you have this example it executes it it checks the output
in the example and your documentation is always up to date.
But I think that same sort of workflow can equally apply to internal documentation.
You know you could imagine it applying to API documentation or maybe some sort of internal
design system that you need to have some example of everything in your design system or something
like that.
But so that ability to traverse your Elm code as well as your Elm JSON and readme is really
So are those the are they set to those specific files that you traverse or can you sort of
arbitrarily list files to traverse?
No you can only look at files that are related to Elm projects.
So the Elm JSON file, the readme, you have some knowledge about the dependencies and
then it's the Elm files.
You could always use code generation to create some sort of file that tells you about that.
Yeah exactly.
That's one of the examples that I sometimes use for CSS checking.
Like you can take your CSS files and compile an Elm file containing all the list of all
classes that are used in there and then you can use those for checking that you don't
have any unused CSS classes.
Or the other way around that you don't have any CSS classes that are used but never defined.
Yeah that's cool.
Yeah I've been thinking a lot about whether I should allow to look at other files but
then it gets pretty complicated I think with how to set up Elm review.
So that's also always a trade off that I need to make.
This example of updating the documentation, you can either use code generation or you
can use Elm review.
Sometimes one will be better than the other.
Like code generation will usually be better if you have information somewhere else.
Like in the readme, some of the information you only find in the readme so you need to
update it.
So in that case Elm review makes more sense.
Right, right.
Yes Elm review is only looking at files specific to an Elm project and the only way to get
other information right now is through code generation or something like that.
Okay so you sort of before this call you hinted at some new thinking that you have about the
regex rule which we talked about in Elm Radio episode 3.
We talked about the idea of using Elm review to inspect regexes and make sure that they're
valid regexes before in your build process so that you don't have to deal with regex.never
and worry about that maybe case.
So I actually went all in in that philosophy.
So I made a blog post called safe unsafe operations in Elm which basically makes use of the Elm
compiler and Elm review to make sure that you always have safe regexes at least when
they're literals.
So yeah I have enabled that rule at Humio.
So we have a no unsafe regex rule that looks at calls of regex.fromliteral.
If the literal is not a valid regex then it reports it.
Right meaning regex.fromliteral doesn't return a maybe unlike regex.fromstring.
Yeah so under the hood it's using an unsafe thing pretty much an infinite recursion.
Well no it could use an infinite recursion.
It could or it could use a maybe with default regex.never.
Yeah so in the case of regex we do have that option so that is what I'm using.
Right but you're proving that that code will never be executed through static analysis
so it's effectively the same thing.
Yeah exactly and I think I also report when regex.fromstring is used with a literal so
that you're forced to use fromliteral where you will get the guarantee that it works well.
And during the episode the last episode I mentioned that I would like to publish that
and now I'm thinking no and it's only for like a tiny reason but I don't want to so
you need to have that regex.fromliteral function in your code and I want you to set it up yourself
and if you don't set it up yourself then.
So essentially is it that you don't want to publish a package which has a function called
regex.fromliteral which can be potentially used without remembering to apply that elm
review rule?
So someone, Emma Bastas is the user name I don't know what the real name is.
They wanted to publish a package to interpolate strings so you have some kind of function
that puts values in that function.
Yeah I was actually discussing that in Slack as well that was a really interesting conversation.
Yeah and they wanted to publish a elm review package next to that to make sure that people
use it well.
The thing is people will use it without the elm review rule or without even having elm
review at all.
So you have just published something that is potentially broken for people.
Yeah because you can't make this impossible state impossible that there's a good state
of you're not using it fine or you're using it and you're remembering to use the elm review
rule to check that you're using this unsafe thing only when it's guaranteed to be statically
analyzed to be safe.
But then there's this impossible state of you're using the function but you're not using
the elm review rule and you can't prove that that's not happening.
Yeah so you're walking on a tightrope but you have not set up the safety net.
And that might be a very opinionated but I think that we as tooling authors we really
want to not get people to that situation.
So what do you think about like is the concern that people would not remember to wire in
that elm review rule or is the concern that they wouldn't be using elm review at all potentially?
Because I could imagine if it's about not using elm review at all I could imagine some
sort of technique where you I don't know where elm review does some code generation or something
like that and the only way that this generated code occurs is if elm review handles it and
then you could have some unsafe things that you could actually guarantee that you could
potentially guarantee through some code generation on the elm review side that the only way you
can use these things is with the type that's generated by elm review so you're guaranteed
to have at least used elm review initially with it.
Yeah yeah yeah my concern is mostly that people don't use elm review or the associated rule
because I think that people would mostly just find a package of oh this looks cool and because
it allows me to to make strings in an easier way and they don't read the documentation
fully or they don't know what elm review is and it sounds like a hassle or they...
Right but they want the safety they want the safe regex that never fails or the safe string
interpolation that's proven correct.
Yeah I think people mostly want just the easier version like oh I can build a regex without
having to handle the error case.
Yeah that sounds good.
Yeah yeah it's an interesting one we should brainstorm a little bit because I feel like
there might be some clever way to use a combination of code generation opaque types techniques
like that to actually gain some confidence that like elm review has blessed this code
and it's an elm review is actually being used otherwise it wouldn't generate the code you
need to use this unsafe thing safely.
Yeah but would you would you be able to publish it as a package and that is a question.
Well you could potentially publish it we need to brainstorm.
Yeah I feel like I feel like it might be possible.
Okay I'm interested.
If you get clever yeah yeah so and if people are interested in this general technique which
I think you're saying that you you think it's a good technique but you're reluctant to just
publish a package for these concerns but you think that people should use this technique
in their own code bases and build their own tools using this technique to use static analysis
to do things that would otherwise be unsafe.
Yeah definitely but they need to do everything and just publishing parts of it is not good.
Right for anyone who wants to read more about this you published a blog post called safe
unsafe operations in elm that is linked to in the show notes that's a really nice post.
Okay other other use cases and elm review rules that you think are really useful.
Yeah so we had one quite odd case at humio so we we have a very big main file with which
handles a lot of pages and we're trying to get somewhere to we're trying to get to a
state where we use something like elm SBA but the thing is we have a lot of pages that
acts like components which have sub pages under them.
Yeah they've got the mini t elm architecture trip triples or whatever.
Yeah but also some pages have their own router and they those pages also have their own router
so it's quite complex it makes things very hard to to refactor so we're trying to get
that to that elm SBA like thing thing that we we quite like.
Right see our see our elm radio episode about Brian Haskell God's elm SBA framework.
So we built our own version of that so that it better fits our needs but basically every
one of those pages they have a config page configuration variable that they expose and
that gets used in main but since we have a lot of pages we couldn't do them all in one
go so so we need we still need to do a lot of wiring in our main file manually and we
need to make sure that every page calls that the view from and we need to make sure that
the main file calls that pages view that is defined in the page configuration that it
calls the update function defining page configuration and so on and then it doesn't use the update
function directly because the code will still compile but it would use the wrong version
of the update function it would use the wrong version of the view function.
So what we did is we added an elm review rule that says if you use page configuration you're
not allowed to expose a view configuration a view function or an update function or a
subscription functions they should all go through the page configuration and just doing
that removed a lot of problems that we could have ended up in.
Oh that's a great use case yeah and then because of that you also necessarily reminded us in
the main file you should update the boilerplate code.
Right so yeah that was one rule that I like to write so at some point we needed to make
sure that our dependencies were using licenses that were approved by our company and we need
to update our docs using that so what I did was I wrote a elm review rule to make sure
that all dependencies have this or that license and if it didn't it was reported.
So there's this this rule that has a configuration that says these licenses are allowed these
are forbidden because we we have checked them and the legal team says we cannot use them
and all the others are reported for us to to contact the legal team and ask them is
this okay to use or not.
Very cool yeah that's a great use case and this is possible because we don't look only
at the elm files it's because we can look at the elm json file and the info about the
Do you fetch that information like the license information of the dependencies as part of
elm review or are you doing some special like extra step?
So the I download the dependencies docs.json file and the elm.json file and the license
is in the elm json file.
Oh cool that makes sense yeah.
So we talked about the regex rule and I think there's a mindset to to creating those kind
of rules are because if you don't know that a static analysis tool is something that can
solve your problem it's something that needs that you need to to be aware of and think
about more and more.
So now I see elm review as kind of a hammer and everything is nails so I'm trying to remind
myself that it's only a single tool or a specific kind of hammer.
But you need to I try to remind people that it is a hammer that they can use and sometimes
it is appropriate.
So usually when I try to use elm review is when I want to prevent people from doing something
like we found a bug and we want people to stop falling into that bug again.
So what I usually recommend is to use type design to to fix the problem so making impossible
states impossible because the compiler is much better at doing this kind of thing and
every elm developer knows those tricks.
I mean you could have like a you could have like an enum style elm custom type with three options and you could create an elm review rule that it's only one of three strings but represented as a string
and that's not the right tool for the job even though you could do that you should you
should have a very good reason to to reach for elm review rather than the elm type system
when possible.
Yeah exactly.
Unfortunately sometimes that is not enough.
Because you cannot forbid a problem prevent a problem from happening again using the type
Right you can't inspect literal values in elm and sometimes you want to be able to make
guarantees about literal values that are being used.
So in that case elm review comes in and can save the day and sometimes it is not possible
to do with either of those things but you can use them together.
So like the regex.fromLiteral function that is a good example good example because you
you force people to write in a certain way but then you can check that sub part that's
subsection of all possible things and you can give the guarantee that in whatever subsection
we are in I can tell you that this is wrong or that this is correct.
So you use both API design type design and elm review and that's usually how I try to
think about things.
What are some elm review packages that you you think are worth taking a look at if you're
you know if you're getting started with elm review maybe you've tried like you know some
of the unused rules and you want to broaden your horizons a little bit and try some different
rules what are some that are worth taking a look at?
Yeah so there's a elm review debug which is under mining which reports when you use debug.log
[00:41:02] do or to string.
I recently made a change to debug.log where it auto fixes the debug log so it removes
them and very happy about that one.
Yeah that's awesome.
Yeah but apart from that it doesn't do much.
It seems like there's there's a philosophy of keeping the elm review packages very focused
sort of Unix toolchain philosophy style.
Yeah they try to do well.
There's a elm review common which has some rules that yeah the name is just too common.
I couldn't find anything more specific without alienating some rules.
So they care about how you import things how you export things they care about type rotations
and they make sure that in your packages you don't forget to expose some things that should
be part of the package that should be exposed as part of the package.
You should definitely enable the last one if you have a package author.
There's also elm review the elm architecture also under my name which forbids some patterns
that we see sometimes in elm code but that is very much frowned upon.
I like calling update inside updates.
That's a good one.
Also defining subscriptions that are empty and forgetting to call the subscriptions of
a module if you use the update function.
So whenever now I define a subscription function I know that it will be used correctly.
It will not be forgotten.
Oh I see cool.
Phil Sparks also made the elm review ports package which makes sure that you don't have
any unused ports in your project because you know that one of the crashes that beginners
fall are because you know that when you don't use a port you get a nice sorry ah fuck.
So in elm when you have defined a port in elm and you use it in javascript but you don't
use it in elm you get a crash.
Oh yes oh I know and me you're in and me and you.
No I mean it's perfectly normal you know you like you define a port and then you you know
for some reason like comment out someplace that uses that port and and it crashes because
it's saying that it's an unused you know function does not exist on your app dot ports.
Yeah that's a nice one.
Yeah that's actually like a production bug that you can avoid by using a static analysis
The reason why I say beginners fall into that one yeah is because often they come to slack
and they say hey what's happening.
Sure sure.
Once you've met it then you know what the problem is.
You know what to do about it at least yeah.
Are you still you still don't sleep quite as soundly at night knowing that one day you
might forget and ship something to production that will just crash.
Especially if some tool just removed a quarter of your code you know.
A bunch of your unused code.
Well no but it can and covers right those kind of problems.
It makes sense yeah.
Yeah I mean you can create those problems.
Right right.
And then Max also worked on Elm Review imports.
So now review ports and imports to create consistent aliases for your imports.
Yeah that's awesome.
We talked about that concept in our earlier episode.
That's a really useful one.
There's still some work to be done on there but if you push him I'm sure you will resume
work on it.
Sometimes motivation is all you need you know.
Mm hmm.
Yeah just knowing that people find it useful.
Yeah good stuff.
Most of my work has has gone into the Elm Review unused package.
That is the most complex one and I think also the most useful one at least as a linting
Yeah yeah.
Yeah I think a lot of the most useful things other than unused code rules are going to
be enforcing your own company specific standards.
And like things like you're talking about where hey if we have this page configuration
type and it's being used in this certain way then you know something's wrong.
If it's not being wired in then that should be an error.
One good rule of thumb for whether Elm Review can be a good solution for your problem is
can you detect this problem just by code reviewing it.
Just by looking at the code can you see a problem.
And if you can then a static analysis tool can do the same work.
That means that it can find most problems but it can get pretty complicated.
So I want to go through real quick how no unused all the unused rules work.
So we have a lot of rules in there.
So there is no unused variables.
There's no unused custom type constructors, custom type constructor arguments, exports,
modules, dependencies, parameters and patterns.
So each one does like one thing except variables which does variables and imports for some
It's the oldest one.
And the thing is like you like they all do one thing and they're going to fix one thing
at a time.
So if you have like a let variable which calls a function but you notice that the variable
is not used then Elm Review can remove it.
So that is one step.
So we can commit here and we can compile and we can push to production.
Once you do that what Elm Review will find is that the function that it was now what
Elm Review can find is that the function call that was the only function call in the whole
project for that function.
So what we can do is we can remove that function altogether.
So instead of doing it as two steps where there's an unused function but within that
unused function it's calling another function which is otherwise unused.
Is that the case you're talking about?
I didn't get it.
So there's a function called foo which is unused and that function calls a function
called bar and that's the only place that bar is called in the unused function foo.
Oh no.
Then we first remove foo.
So you do two steps.
You call Elm Review fix all.
It removes foo.
Then you call it again and it says oh I found a new problem and then it removes bar.
Yeah exactly.
And it does all these tiny things one step at a time.
So you can stop at any time and whenever you think oh it's going too far because this actually
does need to be used then you can stop, fix the problem or ignore the rule at this point
in time.
But yeah you do it one step at a time and that is kind of like the incremental steps
or the tiny steps that we talked about but just as a tool.
Right right.
And when you apply all these tiny tiny things like even removing the patterns or the parameters
well it uncovers a lot of things.
Like even just a let underscore equals something if you remove that maybe you can find that
you remove a dependency.
Right if you have a custom type constructor which has some data value and you, an Elm
review rule tells you that data value is never read, turn it to underscore and then you follow
that fix, turn it to an underscore and then you find that that constructor is not being
used anywhere.
Yeah the argument is never used.
The argument is never used and then you can keep following that thread and perhaps that
variant is no longer needed.
Yeah exactly.
So yeah you do all those tiny things and at the end you will remove a lot of code.
Some colleague of mine they were able to remove 7000, over 7000 lines of code recently and
that was because of all those tiny steps.
Like if you just like looked at the unused top level functions then maybe you could remove
a tiny portion of that.
But if you apply all those things you move a lot more.
And then maybe a little bit of manual assistance in between to connect the dots.
Yeah sometimes because Elm review won't automatically fix things where it will trigger a compiler
So some people they want their names to be there for like patterns.
Like you do you put a match on the results and you have okay okay and error error.
If you don't use the error then people want it to stay, they want the name to remain.
With a meaningful name.
Yeah exactly.
But if you remove that one then it becomes much more easy for a static analysis tool
to figure out other things.
So that's one reason why I try to not care about that one because I know that the tooling
will help me out.
There will be some gains.
Well any final words of wisdom for people getting started with Elm review?
gmpx elm review dash dash templates jfm angles slash elm review unused slash example.
Or if you prefer copy pasting look at our show notes.
Yeah there will be less error prone.
Great stuff.
All right well good checking back in on this Jeroen and have a great day.
You too.
Thanks for watching.