boblancer

boblancer

Auto code formatting in CI pipeline

Hi
Wanted opinion about what would be the best practice to enforce auto formatting in CI pipeline

I was thinking that I could run mix format and commit it repo before merge

Most Liked

lucaong

lucaong

One simple way is to run mix format --check-formatted as a check on the CI pipeline, so that it would fail if the code is not properly formatted. Here you can see an example with GitHub Action on my CubDB project. The action is run for every pull request as part of the build.

I often include the same check as a pre-push Git hook, so I get informed of format issues even before I push my code.

Note that this won’t fix the format issues, but rather just inform about them and cause the pipeline to fail. It is also possible to auto-fix the format and push a new commit, but I normally prefer not to, as it opens up possible issues with concurrent pipelines.

Sebb

Sebb

I do the checks in a pre-commit hook

#!/bin/sh

mix format --check-formatted
if [ $? -ne 0 ]; then exit 1; fi

mix credo --strict > /dev/null
if [ $? -ne 0 ]; then mix credo --strict; exit 1; fi

mix dialyzer > /dev/null
if [ $? -ne 0 ]; then mix dialyzer; exit 1; fi

mix test --warnings-as-errors > /dev/null
if [ $? -ne 0 ]; then mix test --warnings-as-errors; exit 1; fi
kwando

kwando

I don’t want CI to “rewrite” my code, but I’m all for a mix format --check-formatted step in CI :slight_smile:

Where Next?

Popular in Discussions Top

blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
sashaafm
I’m trying to evaluate the best combo/stack for a BEAM Web app. Right now I’m exploring Yaws a bit, after having dealt with Phoenix for a...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19204 150
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement