Skip to content

Commit

Permalink
Building out a proper website for csharpier (#609)
Browse files Browse the repository at this point in the history
* Building out website using docusaurus

closes #505

* Some self code review

* Finishing touches
  • Loading branch information
belav authored Feb 21, 2022
1 parent e1dc833 commit e6970ac
Show file tree
Hide file tree
Showing 57 changed files with 10,485 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- name: Push to dokku
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://[email protected]:22/csharpier'
git_remote_url: 'ssh://[email protected]:22/csharpier-playground'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: --force
22 changes: 22 additions & 0 deletions .github/workflows/deploy_website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Deploy Website
on:
push:
branches: [ master ]
paths:
- 'Src/Website/**'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Cloning repo
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Push to dokku
uses: dokku/github-action@master
with:
git_remote_url: 'ssh://[email protected]:22/csharpier'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_push_flags: --force
12 changes: 12 additions & 0 deletions .idea/csharpier.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Docs/API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
hide_table_of_contents: true
---
CSharpier can be used to programmatically format code.

This requires adding the [CSharpier.Core](https://www.nuget.org/packages/CSharpier.Core/) nuget package to your project.
```bash
dotnet add package CSharpier.Core
```

```csharp

var unformattedCode = "public class ClassName { }"

var formattedCode = CodeFormatter.Format(unformattedCode);
var asyncFormattedCode = await CodeFormatter.FormatAsync(unformattedCode);

var options = new CodeFormatterOptions { Width = 60 };

var narrowerCode = CodeFormatter.Format(unformattedCode, options);
var asyncNarrowerCode = await CodeFormatter.FormatAsync(unformattedCode, options);

```
44 changes: 44 additions & 0 deletions Docs/About.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: What is CSharpier?
id: About
hide_table_of_contents: true
---

CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.
The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.

CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html) of prettier.

### Before
```csharp
public class ClassName {
public string ShortPropertyName {
get;
set;
}

public void LongUglyMethod(string longParameter1, string longParameter2, string longParameter3) {
this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
}
```

### After
```csharp
public class ClassName
{
public string ShortPropertyName { get; set; }

public void LongUglyMethod(
string longParameter1,
string longParameter2,
string longParameter3
)
{
this.LongUglyMethod(
"1234567890",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
}
4 changes: 3 additions & 1 deletion Docs/CLI.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

---
hide_table_of_contents: true
---
### Command Line Options
```console
Usage:
Expand Down
6 changes: 5 additions & 1 deletion Docs/Configuration.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
hide_table_of_contents: true
---

CSharpier has support for a configuration file. You can use any of the following files
- A ```.csharpierrc``` file in JSON or YAML.
- A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file.
Expand Down Expand Up @@ -42,4 +46,4 @@ For example in the following code block, the following symbol sets would be need

When supplying symbol sets, they will be used for all files being formatted. This will slow down formatting, and determining all symbol sets needed across all files won't be straight forward.

The long term plan is to improve Csharpier's ability to determine the symbol sets itself and to allow specifying the for individual files.
The long term plan is to improve Csharpier's ability to determine the symbol sets itself and to allow specifying the for individual files.
17 changes: 6 additions & 11 deletions Docs/EditorsAndCICD.md → Docs/ContinuousIntegration.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
## Editor Integration
### Visual Studio
Use the [official 2022 extension](https://marketplace.visualstudio.com/items?itemName=csharpier.CSharpier)
Use the [official 2019 extension](https://marketplace.visualstudio.com/items?itemName=csharpier.CSharpier2019)
### Visual Studio Code
Use the [official extension](https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode)
### Rider
Use the [official plugin](https://plugins.jetbrains.com/plugin/18243-csharpier)
---
title: Continuous Integration
hide_table_of_contents: true
---

## Continuous Integration
Normally when using a code formatter like CSharpier, you'll want to ensure that all code that makes it to your main branch has been formatted. This can be accomplished by doing the following
1. Set up a dotnet tool manifest file at `.config/dotnet-tools.json` with the following content. Replacing `[SpecificVersion]` with the version of CSharpier you are currently using.
1. Set up a dotnet tool manifest file at `.config/dotnet-tools.json` with the following content. Replacing `[SpecificVersion]` with the version of CSharpier you are currently using.
```json
{
"version": 1,
Expand All @@ -24,7 +19,7 @@ Normally when using a code formatter like CSharpier, you'll want to ensure that
}
}
```
2. Use your preferred CI/CD tool to run the following commands.
2. Use your preferred CI/CD tool to run the following commands.
```bash
dotnet tool restore
dotnet-csharpier --check
Expand Down
14 changes: 14 additions & 0 deletions Docs/Editors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Editor Integration
hide_table_of_contents: true
---

Running CSharpier on save is recommended. It will speed up your development time.

### Visual Studio
Use the [official 2022 extension](https://marketplace.visualstudio.com/items?itemName=csharpier.CSharpier)
Use the [official 2019 extension](https://marketplace.visualstudio.com/items?itemName=csharpier.CSharpier2019)
### Visual Studio Code
Use the [official extension](https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode)
### Rider
Use the [official plugin](https://plugins.jetbrains.com/plugin/18243-csharpier)
7 changes: 5 additions & 2 deletions Docs/Ignore.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Ignoring Code
---
title: Ignoring Code
hide_table_of_contents: true
---

Csharpier will ignore the following files
- Any file that begins with ```TemporaryGeneratedFile_```
Expand Down Expand Up @@ -48,4 +51,4 @@ public class ClassName
}
}

```
```
20 changes: 20 additions & 0 deletions Docs/Installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
hide_table_of_contents: true
---

CSharpier is implemented as a dotnet tool and can be installed with the following commands.

```bash
# if you don't yet have a .config/dotnet-tools.json file
dotnet new tool-manifest

dotnet tool install csharpier
```

This will as a local dotnet tool for the directory these commands are run from. This ensures the project gets the correct version of CSharpier.

Dotnet tools can also be installed globally with the following command.

```bash
dotnet tool install -g csharpier
```
7 changes: 6 additions & 1 deletion Docs/IntegratingWithLinters.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Integrating with Linters/Formatters
---
title: Integrating with Linters
hide_table_of_contents: true
---


More often than not, linters contain formatting rules that conflict with CSharpier.

### Dotnet Format
Expand Down
5 changes: 4 additions & 1 deletion Docs/MSBuild.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
### MSBuild Package
---
title: MsBuild Package
hide_table_of_contents: true
---

CSharpier can be run when a package is built by installing the CSharpier.MSBuild nuget package
```console
Expand Down
5 changes: 4 additions & 1 deletion Docs/Pre-commit.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## Precommit Hooks
---
title: Pre-commit Hook
hide_table_of_contents: true
---

CSharpier can be used with a pre-commit hook to ensure that all staged files are formatted before being committed.

Expand Down
73 changes: 5 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
## CSharpier
CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.
The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.
CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html) of prettier.

### Work In Progress
CSharpier is still in active development and the rules it uses to format code are not yet finalized and will change over time.

If you can live with the fact that the formatting will be changing over time, it is safe to use. In addition to a steadily growing set of unit tests; csharpier is tested against ~60k c# files from a range of public repositories to validate it does not result in the lose of any source code.
The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.

### Features
- It is fast. It can format a solution of ~11,000 files in ~30 seconds.
- It supports validating the syntax of the code it produces to ensure the only changes made were whitespace and line breaks.
- It formats c# <= 10.0

Try it out at [Playground](https://csharpier.com)
CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the [Option Philosophy](https://prettier.io/docs/en/option-philosophy.html) of prettier.

### Before
```c#
public class ClassName {
public string ShortPropertyName {
get;
set;
}

public void LongUglyMethod(string longParameter1, string longParameter2, string longParameter3) {
public void CallMethod() {
this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
}
Expand All @@ -33,13 +17,7 @@ public class ClassName {
```c#
public class ClassName
{
public string ShortPropertyName { get; set; }

public void LongUglyMethod(
string longParameter1,
string longParameter2,
string longParameter3
)
public void CallMethod()
{
this.LongUglyMethod(
"1234567890",
Expand All @@ -50,48 +28,7 @@ public class ClassName
}
```

## Installation

```console
dotnet tool install -g csharpier
```

### Basic Usage
Run csharpier from the directory you wish to format to recursively format all .cs files
```console
dotnet csharpier .
```

Run csharpier on a specific file
```console
dotnet csharpier /src/UglyUnformattedFile.cs
```

### MsBuild Package
If you prefer to have csharpier run when a project is built, you can use the CSharpier.MSBuild nuget package
```console
Install-Package CSharpier.MSBuild
```

### Programmatically Formatting Code
It is possible to format code programmatically using the [CSharpier.Core](https://www.nuget.org/packages/CSharpier.Core) nuget library.
```c#
using CSharpier;

var unformattedCode = "public class Class2 { }";
var formattedCode = CodeFormatter.Format(unformattedCode);
```

## Documentation
[Command Line Interface](Docs/CLI.md)
[Configuration File](Docs/Configuration.md)
[Editors and CI/CD](Docs/EditorsAndCICD.md)
[Integrating with Linters/Formatters](Docs/IntegratingWithLinters.md)
[Pre-commit Hook](Docs/Pre-commit.md)
[Ignoring Files](Docs/Ignore.md)
[ChangeLog](CHANGELOG.md)
[MSBuild Package](Docs/MSBuild.md)

### [Documentation](https://csharpier.com)

## Contributing
See [Development Readme](CONTRIBUTING.md)
Expand Down
Binary file modified Src/CSharpier.Playground/ClientApp/public/favicon.ico
Binary file not shown.
Loading

0 comments on commit e6970ac

Please sign in to comment.