0.5.0-development • Published 5 years ago

prettier-csharp v0.5.0-development

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Intro

Prettier C# adds C# support to the 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.

WORK IN PROGRESS

Please note that this plugin is under active development, and might not be ready to run on production code yet. It will break your code.

Preview the result with this diff example.

Install

yarn add --dev --exact prettier prettier-csharp

Use

prettier --plugin=prettier-csharp --parser=cs --write "**/*.cs"

How it works

The plugin is written in JavaScript. It depends on the JavaScript port of ANTLR and an unmodified unofficial C# 6 grammar from ANTLR. The grammar is precompiled to plain JavaScript and ready to use in the project.

Contributing

Updating the grammar

  • Copy the latest version of the grammar to asset/csharp
  • Install ANTLR:
brew install antlr4 # on macOS
  • Generate the JavaScript parser:
yarn install
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:

yarn test

To test it out on an actual C# file:

  • Clone this repository.
  • Run yarn.
  • Create a file called test.cs.
  • Run yarn prettier test.cs to check the output.

Maintainers