-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rush] Enable Prettier integration #1573
Comments
For reference the PR #1369 discussion contains some of our rationale behind the decision to adopt Prettier. |
Status Update: This weekend I'm finally moving forward with these last couple items. @iclanton and I had a long chat about the approach for Prettier. We considered generalizing the However, we were concerned this approach will necessarily require more set up steps, and more documentation about how all the pieces work. Since Prettier is the Rush Stack bet for formatting, we decided instead to design around the goal of making Prettier easy to set up and fully integrated. The proposed design is that you simply specify (It will still be possible to not use that setting, and instead roll your own complex rule mappings using |
Design GoalUsers can simply turn on a setting ( This makes sense as a Rush-level feature because the Prettier commit hook processes a cross-section of files from multiple projects at once. By contrast, I would NOT use this design for ESLint, because we recommend to invoke ESLint as a build task. Thus ESLint's configuration is owned by the toolchain, which can very between Rush projects in a monorepo. Proposed designRush will provide a new config file for managing Prettier integration. Something like this: common/config/rush/stack-prettier.json {
// "Stack" means that the Prettier configuration is managed by Rush and uses the
// Rush Stack recommended setup.
//
// If true, "rush install" will validate that the Git hook is correctly configured.
// If false, then "rush prettier" commands will do nothing and print a warning that
// Prettier is disabled.
"stackPrettierEnabled": true,
"prettierVersion": "2.0.5"
// later this config file could also provide other features such as Prettier plugins
// or autoconfiguration of the VS Code extension for Prettier
} The Git hook will look like this: common/config/git-hooks/pre-commit
"git commit" is a very fundamental user experience, so leveraging install-run-rush.js provides some advantages:
I experimented with the pre-commit wrappers suggested by the Prettier website, but they all seem overengineered for our goals here. pretty-quick was the best one, but there are a few reasons I chose not to go with it:
Invoking Prettier as a library looks pretty easy. It seems not much work to build this directly into Rush. (If it does turn out to be complicated then I would probably go with The Rush CLI actions will be like this:
|
Another possible approach: We're considering modeling
Here's an example of how it could work: common/autoinstall/rush-prettier/package.json {
"name": "rush-prettier",
"version": "1.0.0",
"private": true,
"dependencies": {
"pretty-quick": "1.0.0",
"prettier": "2.0.5"
}
} common/config/rush/common-versions.json {
"name": "prettier",
"commandKind": "global",
"summary": "Invokes the Prettier command in a Rush repo",
// The description is not used because "shellCommandDefinesParameters"=true
// "description": "Invokes the Prettier command in a Rush repo",
"autoinstallFolder": "rush-prettier",
// This will invoke common/autoinstall/rush-prettier/node_modules/.bin/pretty-quick
"shellCommand": "pretty-quick",
"shellCommandDefinesParameters": true
} |
This PR introduced the Prettier configuration #1922 and bulk-converted our repo. |
There is a serious headache I am facing and it brings up again one of the most annoying issues related to the combination of rush+vscode+tools:
@octogonz If you enhance a bit your prettierrc config to add, let's say a plugin, any prettier plugin, you will find out that vscode extensions don't work anymore, although your command line of course still works fine and prettier itself will work fine. This is a general issue related to the impact of not having a root package.json (which lerna has, Nx has, etc...). I'm not fond of that root package.json personally, but I am seriously annoyed by the amount of time I waste to get vscode working properly in a rush repo. Do you have any feedback on this? or a proper way to get the rush auto-installer or repo tools package working with vscode? |
I'm closing this issue since we are now done with the Prettier and the approach is fully documented. @abdes Sorry I overlooked your comment here. Some general answers:
If you have further questions/concerns, please open a dedicated GitHub issue. (This issue was about Prettier.) |
Did you manage to get this working out of interest? I've got the same issue currently, trying to get "prettier-plugin-sorted" working. |
I'm running into this also with import sorting, or any other prettier plugins. Did you get far with this @prescience-data or @abdes |
@brycepolly Any update from you? I'm taking inspiration from #3230 (comment) and worked around it using the
That attempts to mimic what I tried being creative to execute |
I'm opening this issue to track the plan for replacing TSLint with the new @microsoft/eslint-config-scalable-ts package that uses ESLint+TypeScript+Prettier.
Here's a rough outline of the steps:
I've also been wondering if Rush maybe should include built-in integration for Prettier, to avoid the hassle of writing custom Git hooks.
The text was updated successfully, but these errors were encountered: