Code formatting in source repository

Simple question: what kind of source code formatting is applied to the source repository? I’ve seen a .prettierc which suggests prettier, however, prettier has pretty much re-done all existing formatting for me, which makes contributing pull requests so much more difficult. Are there any assumptions about prettier version?

this is a good question for @sebavan or @RaananW

We check on build with TSLint (should move to jslint soon cause yup we forgot) and I think @RaananW added the equivalent prettier config ??? I use prettier locally without issues, it is strange it changes it all for you :frowning:

We use prettier. I have recently made a change to the max width parameter. It used to be 300, and is now 180. If you see a problem with it, we can refer it back to 180.

Oh, and something important - some files were never formatted since we added prettier. So it might be the case here. We know formatting is required in certain files and will of course accept PRs with mostly-formatting. We do that too from time to time as well

So far, I’ve seen the following discrepancies (Prettier 2.2.1):

  • endOfLine, which is set to lf since Prettier 2.0 (Options · Prettier). It seems that .gitattributes do not really work as intended – on my Linux box I’m getting DOS line endings.

  • quotes – Babylon.JS uses single-quotes in most files I’ve seen, while Prettier changes them to double quotes by default (Options · Prettier). Also, quotes around object keys are removed

  • Some spacing is adjusted

  • TSX files are getting basically rewritten from scratch, too many changes to make sense of.

1 Like

I don’t mind adding some options to the prettier configuration file, if that will solve some of your issues :slight_smile:

We are mostly windows users, so we probably don’t notice the issue which you are facing. It can also be an issue with the way some commit their code - git for windows does convert windows-style newline to unix-style newline, but not per default. Some of us might simply set it to windows-style checkout and windows-style commit as well.

About quotes and tsx. The prettier file is rather new. I would say a few months old. Until then we either used the vscode formatter (which doesn’t care about many things like quotes) or none at all. The .prettier added a bit of structure, but we are still only checking formatting with tslint and not with prettier when running our CIs.

What I get from what you are saying is -

  1. it will be great if we checked formatting to all commits done
  2. it will be great if we commited unix-style (which i totally agree with)
  3. it will be great if we ran a pass at the entire repository, formatting all files.

About task 3 - that is on my todo list for 5.0. I can add 1 and 2 (2 seems to be a simple option in prettier, so that would be the quickest). Until then, we will accept any PR that pushes formatting changes along with the actual commit. I know it might be a bit messy (especially with the tsx files, i agree with that as well :-)), but it is the quickest solution until we unify everything.

1 Like