https://github.com/warrenseine/prettier-plugin-csharp
Prettier C# Plugin
https://github.com/warrenseine/prettier-plugin-csharp
antlr csharp formatter grammar javascript prettier
Last synced: 6 months ago
JSON representation
Prettier C# Plugin
- Host: GitHub
- URL: https://github.com/warrenseine/prettier-plugin-csharp
- Owner: warrenseine
- License: mit
- Created: 2018-03-15T08:46:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-11T21:22:39.000Z (about 2 years ago)
- Last Synced: 2024-04-26T18:22:12.197Z (over 1 year ago)
- Topics: antlr, csharp, formatter, grammar, javascript, prettier
- Language: JavaScript
- Size: 3.19 MB
- Stars: 251
- Watchers: 10
- Forks: 15
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
❌ This repository is unmaintained and the project is incomplete, don't expect anything else than a toy C# project to reformat correctly! ❌
Have a look at CSharpier instead.
![]()
![]()
Prettier C# Plugin
## Intro
Prettier C# adds C# support to the [Prettier](https://github.com/prettier/prettier) code formatter. Like Prettier, it is opinionated and restricts style options to a minimum. It runs where Prettier runs, including CI and pre-commit hooks.
## Unmaintained
This repository is unmaintained and the project is incomplete, don't expect anything else than a toy C# project to reformat correctly! **It will break your code.**
Preview the result with this [diff example](https://github.com/warrenseine/prettier-csharp-demo/pull/1/commits/8652271a499740b726e6342346e97447abd23162).
## Install
```bash
yarn add --dev --exact prettier prettier-plugin-csharp
```## Use
```bash
prettier --write "**/*.cs"
```## How it works
The plugin is written in JavaScript. It depends on the JavaScript port of ANTLR and relies on a fork of an [unofficial C# 6 grammar from ANTLR](https://github.com/antlr/grammars-v4/tree/master/csharp). The grammar is precompiled to plain JavaScript and ready to use in the project.
## Contributing
### Installing dependencies
Use your favorite Node package manager:
```bash
yarn
```### Updating the grammar
The grammar supports C# 6 as a baseline, and tries to catch up with recent additions. Contributions are welcome. To update the grammar:
- Update `src/csharp/*.g4` files.
- Ensure you have Java 8+ installed on your machine.
- Fetch a local copy of ANTLR:```bash
yarn fetch-antlr
```- Generate the JavaScript parser:
```bash
yarn generate-parser
```### Testing
The project is developed against a single grammar-complete regression test. There are no unit tests for the moment.
Run the test with:
```bash
yarn test
```To test it out on an actual C# file:
- Clone this repository.
- Run `yarn`.
- Run `yarn prettier Your/File.cs` to check the output.## Maintainers