Found this issue #305 (currently closed).
We must have an option to disable code formatting during generation. I suggest that by default it is disabled and will automatically format the code for you. This automatic behavior was introduced (correct me if i'm wrong) with this commit: https://github.com/nrwl/nx/commit/e7481a790f5becffc46e794ec46c0835a2114319
Previous versions allows disabling the auto-formatting during generation.
This was due to these lines https://github.com/nrwl/nx/blob/eb42a4e34fb23a5a268ce9326695bf209b0f450a/packages/shared/tasks.ts#L15-L20
It is executed every time generate command is called.
Here is an easy way to disable formatting. Make the relevant bit of your package.json look like so.
"format": "echo DONT ./node_modules/.bin/nx format write",
"format:write": "echo DONT ./node_modules/.bin/nx format write",
(So far I've been forced to do this because I haven't been able to find a way (admittedly, very little effort looking) to disable the formatter from combining long series of (for example) imports in a module definition, onto the same line. In our work here, we rely on having these things split onto separate lines, for easier and more pleasant code review and merges. The default settings for the formatting tool seem to be unaware of the impact on certain formatting choices on code merging; on large projects, merges can end up as an unpleasant, expensive part of the development cycle. Every little bit of making them easier helps.)
I recently found a neat or should i call it a dirty hack? create a .prettierignore file in the directories to be ignored and add this line inside the ignore file **/*.ts.
Had to create two .prettierignore files 1 in apps folder and 1 in libs folder.
I am also using the ignore approach: https://prettier.io/docs/en/ignore.html
I am using the inline approach:
// prettier-ignore
Also works when creating a .prettierignore file in the root directory and excluding all files that is needed to be excluded.
AFAIK, This should be at least documented and pointed out.
And, make also this as an option during generation
@JamesHenry - can you add some wiki docs or readme regarding above ^ ?
As I understood, @vsavkin approach is not to give flexibility for this.
You can hear him explaining it here:
https://youtu.be/qYNiOKDno_I?t=30m15s
https://youtu.be/qYNiOKDno_I?t=38m1s
I agree with the concepts he shared but there should be some sort of leeway to this one. Sample scenario is that you migrated an existing Angular CLI codebase to the Nrwl's Nx. I'm pretty sure you have some code styleguide already set there before you decided to migrate it.
Another scenario is that other teams might opt to use Nx in newer projects but decided to opt-out in the auto-formatting code. @kylecordes usage is a sample here.
That's why i suggested an option to disable it. By default, the code formatting will still be enforced. Anyway, it's only a suggestion.
I actually agree with @vsavkin on this, broadly. I think the approach Google Go takes is brilliant for example, a broad swath of format/layout issues are skipped. Instead of each developer/user developing a different code layout style, everyone uses go format. Many hours and dollars saved.
However, in the particular case of lists of imports declarations etc. in a NgModule, prettier causes a quantifiable difficulty. It makes the following change:

... Which seems starkly unwise. These are arrays very likely to be edited by different branches concurrently. Listing these entries on a single line maximizes the opportunity for merge conflicts and maximizes the effort in reviewing a change. Listing the entries on separate lines saves time and money. I believe this is a reasonably objective estimation, not a subjective preference.
(Common, automatic code formatting is more important than following subjective preferences.)
So I think prettier is a good idea in general, but I think this bit needs to somehow be fixed or changed before I could recommend using it in its current form across a large angular application.
We have changed the setup to only format untracked files on generation. In this case if you move an existing project into a workspace, you won't have to reformat it.
If you want to disable formatting, you can do it like this:
"format": "exit 0",
"format:write": "exit 0",
Or use .prettierignore.
Ideally, though, you should be able to gradually reformat all the files in your workspace, and you can do it by running:
yarn format:write --base=master --head=HEAD
and
yarn format:check --base=master --head=HEAD
These will only reformat and check the files changed by your PRs. @JamesHenry has been working on a tool called precise-commits, which allows you to only reformat the lines changed by your PR.
Finally, you don't have to use prettier--just change the format:write script to invoke, say, clang-format.
Most helpful comment
I actually agree with @vsavkin on this, broadly. I think the approach Google Go takes is brilliant for example, a broad swath of format/layout issues are skipped. Instead of each developer/user developing a different code layout style, everyone uses
go format. Many hours and dollars saved.However, in the particular case of lists of imports declarations etc. in a NgModule, prettier causes a quantifiable difficulty. It makes the following change:
... Which seems starkly unwise. These are arrays very likely to be edited by different branches concurrently. Listing these entries on a single line maximizes the opportunity for merge conflicts and maximizes the effort in reviewing a change. Listing the entries on separate lines saves time and money. I believe this is a reasonably objective estimation, not a subjective preference.
(Common, automatic code formatting is more important than following subjective preferences.)
So I think prettier is a good idea in general, but I think this bit needs to somehow be fixed or changed before I could recommend using it in its current form across a large angular application.