Prettier C# Plugin
raw JSON → 0.6.0-development verified Sat Apr 25 auth: no javascript
A Prettier plugin to format C# code using Prettier's opinionated style. Current version is 0.6.0-development, indicating pre-release status with active development. Released under a permissive license. Differentiator: brings Prettier's zero-config, deterministic formatting to C# projects, unlike other C# formatters that require extensive configuration. However, due to its early stage, it may break code and is not ready for production use.
Common errors
error Error: Cannot find module 'prettier-plugin-csharp' ↓
cause Plugin not installed or Prettier cannot locate it.
fix
Ensure prettier-plugin-csharp is installed in the same node_modules as prettier.
error Prettier encountered an error while formatting file.cs: ... unexpected token ↓
cause C# syntax not supported by the ANTLR grammar used.
fix
Simplify the code or contribute to the grammar; avoid unsupported features.
error prettier-plugin-csharp: not a valid plugin ↓
cause Installed version incompatible with Prettier's plugin API.
fix
Use exact versions: yarn add --dev --exact prettier prettier-plugin-csharp
Warnings
breaking Plugin is under active development and may break your code. ↓
fix Do not use on production code; test on a copy first.
gotcha Relies on a fork of an unofficial ANTLR grammar; may not fully support all C# constructs. ↓
fix Review formatted output for correctness, especially with advanced features.
gotcha No unit tests; only a single regression test exists. ↓
fix Manually test formatting on your codebase.
Install
npm install prettier-plugin-csharp yarn add prettier-plugin-csharp pnpm add prettier-plugin-csharp Imports
- default wrong
Trying to import plugin directly: `import prettierPluginCsharp from 'prettier-plugin-csharp'`correctNo import needed; plugin auto-detected by Prettier when installed.
Quickstart
yarn add --dev --exact prettier prettier-plugin-csharp
prettier --write "**/*.cs"