nx icon indicating copy to clipboard operation
nx copied to clipboard

Ability to turn off prettier

Open flippidippi opened this issue 2 years ago • 13 comments

Add the ability to turn off prettier, specifically in generators. Currently, prettier is installed automatically with npm 7/8, which there is no way to completely turn it off.

Description

For teams that dislike prettier, it would be nice to be able to turn it completely off.

Motivation

Prettier can cause headaches in larger teams and unnecessary code changes to review.

Suggested Implementation

Take into account the .prettierignore for all prettier tasks.

Alternate Implementations

Either add a setting in nx.json, or change prettier to be optionalDependencies and checking if installed before using.

flippidippi avatar Oct 19 '21 16:10 flippidippi

On VS Code you can easily disable prettier on a specific workspace by just going on extensions and disabling it. I am sure other IDE have something similar.

adlion avatar Oct 20 '21 15:10 adlion

On VS Code you can easily disable prettier on a specific workspace by just going on extensions and disabling it. I am sure other IDE have something similar.

I'm not talking about prettier in IDE here. I don't have that plugin installed. This is about the nx generators using prettier.

flippidippi avatar Oct 20 '21 16:10 flippidippi

Could you please provide a repo with repro steps to get the error you are seeing?

prettier should already be optional so this is a bug :sweat:

Please help us reproduce it and we can fix it.

FrozenPandaz avatar Oct 22 '21 21:10 FrozenPandaz

From the npm documentation: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#peerdependencies

In npm versions 3 through 6, peerDependencies were not automatically installed, and would raise a warning if an invalid version of the peer dependency was found in the tree. As of npm v7, peerDependencies are installed by default.

So just create a new nx workspace on npm 7 or 8, and you'll see it install prettier automatically.

image

As you can see prettier is added to the package.json and also installed via peerDependencies.

Even upgrading to nx 13 and removing prettier from the package.json, it will still be installed.

image

Repo: https://github.com/flippidippi/nx-prettier-bug

flippidippi avatar Oct 23 '21 18:10 flippidippi

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Nov 07 '21 00:11 github-actions[bot]

Reopen. Still an issue.

flippidippi avatar Nov 08 '21 13:11 flippidippi

Hi,

This is still an issue in NX version 13.8.0. With the prettier packages removed (prettier, eslint-config-prettier, eslint-plugin-prettier), eslint fails with the following error:

UnhandledPromiseRejectionWarning:` Error: Failed to load config "prettier" to extend from.
Referenced from: .../node_modules/@nrwl/eslint-plugin-nx/src/index.js
    at configInvalidError (.../node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2596:9)

I had to remove prettier from the extends attribute of the default eslint configs in:

@nrwl/eslint-plugin-nx/src/configs/javascript.js
@nrwl/eslint-plugin-nx/src/configs/typescript.js

nawilson avatar Feb 09 '22 01:02 nawilson

I have also encountered this same issue. I would like to not use prettier but keep eslint. Can it be possible to have prettier be optional?

root0x avatar Feb 11 '22 16:02 root0x

This is an issue. We are not using prettier though the eslint-plugin-nx wants to extend the config of it. Please decouple the extension in the configs.

Rugshtyne avatar Mar 02 '22 10:03 Rugshtyne

@FrozenPandaz can we reopen this issue? Also seeing

Failed to load config "prettier" to extend from.
Referenced from: @nrwl/eslint-plugin-nx/src/index.js

johnameyer avatar Mar 06 '22 23:03 johnameyer

You are right @johnameyer, I will reopen this issue.

meeroslav avatar Mar 31 '22 08:03 meeroslav

I can see .prettierignore in the root of the repo maybe we can just add

/apps /libs

into it while this issue still the case?

B-R-Bender avatar Apr 28 '22 10:04 B-R-Bender

Until this issue is fixed, one can simply merge eslint config from the following files from @nrwl/eslint-plugin-nx into their root eslint config (of course, without prettier extension):

Don’t forget to remove these extends from your eslint config:

  • plugin:@nrwl/nx/typescript;
  • plugin:@nrwl/nx/javascript.

tukusejssirs avatar Aug 10 '22 10:08 tukusejssirs

hey @meeroslav , this PR has added about 6+ seconds of lint overhead to our current project. It's particularly bad because it's a mono repo, and this is doing an npm ls 4 times, which is costly.

Overall we have 28 total libs/apps in our NX monorepo, each which incurs a 6 second hit when using run-many. now our lint build has gone from ~40 seconds to 7+ minutes. this will not scale well for us as we add more.

Is this something we can look into?

danielwong2268 avatar Sep 08 '22 04:09 danielwong2268

Hey @danielwong2268,

The performance impact you are mentioning has been fixed a few weeks ago in this PR: https://github.com/nrwl/nx/pull/11603 and landed in v14.5.7.

Please update to the latest version of nx.

meeroslav avatar Sep 08 '22 10:09 meeroslav

👍 thank you

danielwong2268 avatar Sep 08 '22 17:09 danielwong2268

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Mar 21 '23 22:03 github-actions[bot]