Remove Prettier and use eslint instead
See original GitHub issueDescription
get rid of prettier
Motivation
we don’t want prettier. it’s not configurable and doesn’t match our style.
Suggested Implementation
- remove
.prettierrc
. - configure nx to not use prettier
Alternate Implementations
use eslint instead.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to remove prettier plugin from ESLint in VS Code?
I've been using prettier plugin for ESLint for a while and now I've got project with different .eslintrc.js . My config use to...
Read more >eslint-plugin-prettier - npm
Runs Prettier as an ESLint rule and reports differences as individual ESLint issues. If your desired formatting does not match Prettier's output ...
Read more >Using Prettier and ESLint to automate formatting and fixing ...
Methods for linting and pretty-printing your code; Remove conflicting rules and run serially; Run Prettier followed by ESLint programmatically ...
Read more >Integrating with Linters - Prettier
Linters usually contain not only code quality rules, but also stylistic rules. Most stylistic rules are unnecessary when using Prettier, but worse –...
Read more >How to use Prettier with ESLint - Robin Wieruch
As mentioned earlier, whereas Prettier takes care of your code formatting, ESLint takes care of your code style. The former does everything ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@LucCADORET I’d preface the approach by saying any “customization” done to NX has future maintenance cost that must be taken into consideration. If you’re comfortable with working with the underlying tools of NX and keeping the customization updated as NX gets updated, then feel free to continue. With that said, I don’t think I’ve had to really change much to keep this particular customization working for us, since I’ve stopped using prettier with NX.
It’s been a while since I’ve stopped using prettier with NX, but AFAIK, there’s no strict technical restrictions in place to enforce prettier usage. You should be able to stop extending from prettier in the eslint config and remove prettier from npm deps. It should be as simple as that IIRC. This should be enough to simply disable prettier so that you can now configure eslint to do static analysis and styling.
However, I wanted to take it a step further and have separate npm commands to run lint for styling independently of running lint for static analysis. A step by step explanation of how to accomplish this is a bit long, but the gist of it is as follows.
The eslint configs needed to be split up and I had to move all the different flavors of eslint config into it’s own eslint config directory. A config for browsers, node apps and styling. So effectively, the project root
.eslintrc
and/or.eslintrc.json
configs were no longer being used. Interestingly enough NX (at least at the time of investigation) assumed there to be a.eslintrc
and/or.eslintrc.json
at project root. And the one thing I noticed was that the root level eslint config file was getting regenerated when doing NX upgrades so instead of removing the root level eslint config file, I replaced the contents with an empty object. This prevented the file from getting regenerated when upgrading NX or using NX commands to generate libs/apps.Then it’s a matter of pointing your app/lib specific eslint config files to the respective configs in the eslint config directory. You can take advantage of the fact that eslint (cascades) goes up the directory tree to find parent configs to have a default eslint config when one isn’t found in your app/lib specific directory. So I have a
.eslintrc.js
at project root that defaults to the browser eslint config. But only for node apps do I have a eslint config in the apps/libs directory, which extends from the node eslint config.Since I wanted two separate NPM lint commands to run (one for styling and one for static analysis), I had to put a “conditional” in the project root’s
eslintrc.js
file. Then, when I want to check for styling, I specify the styling config I want via the--eslint
flag. When I want static analysis, I just let eslint find either the eslint configs in the app/lib directory or have it cascade up to the project root directory where the default is the browser config.Hopefully, this is enough of an idea to get you on your way to your own solution that works for your project.
Can you detail how you have done it ? It seems like the nx eslint plugin enforces the use of prettier (it extends its config from it).