The opinionated code formatter Prettier packed as dotnet tool.
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
GitHub - prettier/prettier: Prettier is an opinionated code formatter.
It is written in javascript and requires node to run.
PackedPrettier packs prettier in an executable for various platforms.
Including node.
You can install it using dotnet tool install, both as global and local tool.
Install as local dotnet tool:
- If you haven't used any other dotnet tools yet, create a tool manifest first:
dotnet new tool-manifest
- Install PackedPrettier
dotnet tool install PackedPrettier
In the terminal:
dotnet pprettier --help❗ The command is named
pprettierfor brevity and internallyprettieris executed.
In Visual Studio
-
Install RunOnSave: A Visual Studio extension that can run commands on files when they're saved.
-
Create a
.onsaveconfigwith this content:[*.{js,jsx,ts,tsx,css,less,scss,vue,json,gql,md}] command = dotnet arguments = pprettier --write "{file}"
When you save a file in VS, prettier will reformat it
Prettier has migrated to es modules. This means that the prettier package is no longer compatible with pkg and PackedPrettier v2. Previously the pkg package has been used to pack prettier into an executable. This is no longer possible. The new version of PackedPrettier uses a different approach to pack prettier into an executable: deno. deno compiles prettier into an single executable. This executable is then used by the PackedPrettier loader to run prettier in the same way as before.
Deno does not allow to import modules at runtime, see denoland/deno#8655 for details.
That means but plugins and javascript config files (for example prettier.config.js) are not supported anymore.
If this is a showstopper for you, please open an issue and we can discuss a solution. A potential solution could be to use bun to pack prettier. But bun has no stable release for windows yet.
I still consider the windows build of PackedPrettier as experimental. If you encounter any issues, please open an issue.
Compared to run prettier with node there are some restrictions:
- Plugins are not supported (see denoland/deno#8655 for details)
- Javascript config files (for example
prettier.config.js) are not supported - All restrictions of
denoapply
This is because deno does not allow to import modules at runtime.
If this is a showstopper for you, please open an issue and we can discuss a solution. A potential solution could be to use bun to pack prettier. But bun has no stable release for windows yet.
There is a (sort of) port of prettier that supports cs files:
Checkout belav/csharpier: an opinionated code formatter for c#. and install it as dotnet tool. Then add this to your .onsaveconfig file:
[*.cs]
command = dotnet
arguments = csharpier "{file}"
prettier is compiled for
-
Windows x64
-
Linux x64
and the loader requires either
-
.Net 6
-
.Net 7
-
.Net 8
❗ Support for .NET Core 3.1 and .NET 5 has been dropped because they are out of support.
This is not possible because executable has to be signed (with either an adhoc signature) or an Apple Developer ID.
Checkout the official pkg readme for historical details. The same restrictions apply to deno, too.
Please create an issue.
Pull requests are always welcome 😍
This software is released under the MIT License.