Formatter adding tabs to blank lines that follow a tabbed (non blank) line

I’ve recently moved to a new machine and now whenever I save a file (in Atom), any blank line that follows an indented line will have a similar indentation added to it.
I don’t format manually on the CL.
The machine change also came with a change from 1.7 to 1.12

My .formatter.exs has not changed in any way.

Does anyone know why this might be happening?
It’s starting to get rather irritating.

Thanks in advance,
S.

Does this only occur if you save via atom, or does it also occur if you do mix format ?

I don’t use mix format but I’ve just run it and it touched every file in the codebase with the exception of the ones that I have already affected through atom.
I’ll be discarding those changes.
Thank God for git
:grin:

I checked the versions of the atom-elixir-formatter Atom package and it differs between the two machines but as far as I can tell this just runs mix format so I wouldn’t expect it to affect how formatting is actually carried out.
Am I wrong on this?

S.

Atom may well have its own tabs and spaces logic that is being applied after the elixir formatter is running, I’m not sure. My point in having you run mix format wasn’t because I was trying to ruin your code base :smiley: but rather to show you that it isn’t the thing adding the spaces.

I bet if you look at the file that has the spaces, and then run mix format, you’ll see that the spaces go away.

2 Likes

Should have said earlier, I’m amazed at the speed and helpfulness of the response @benwilson512, thanks.

Unfortunately that wasn’t the case mix format doesn’t affect the files that have the spaces and for the files that had none, it added them.

I might have to bite the bullet and let it do it’s thing for the entire codebase. My code reviewer keeps getting a shock whenever she sees a file with 100+ lines changed only to find that maybe three of them are actual code changes. :rofl:

It’s not that big a deal but understanding how it works is more valuable to me than avoiding the issue.

1 Like

Ah yeah, in my view the mix formatter should be used 100% on a code base, or not at all. It causes giant pains if it only fires when certain people touch the files. We even integrate it into our CI so that if a non formatted file is checked in the build fails. Helps catch issues early.

3 Likes

I would suggest you to split a change like that apart to not stress your reviewer:

First communicate with your team / your reviewers that you want to use the mix formatter.

If all agree you first just run the formatter over as much as possible and get that merged. That review might have lots of line changes but it’s just formatting so should be easy to merge.

Only after that is done you go and change the three lines of code you actually wanted changed. Give that to your reviewer and they can easily see what you really intented to change.

This is not what mix format does by default (and I don’t think it’s configurable either). I just tested it on a file, I added spaces/tabs for indentation on empty lines and mix format removed them. It must be something in your Atom config or some other thing that’s affecting it.

2 Likes