Skip to content

Commit

Permalink
Building out website using docusaurus
Browse files Browse the repository at this point in the history
closes #505
  • Loading branch information
belav committed Feb 14, 2022
1 parent 8f03baa commit d40f102
Show file tree
Hide file tree
Showing 41 changed files with 10,312 additions and 68 deletions.
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.

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
20 changes: 20 additions & 0 deletions Src/Website/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
3 changes: 3 additions & 0 deletions Src/Website/.idea/.gitignore

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

12 changes: 12 additions & 0 deletions Src/Website/.idea/Website.iml

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

8 changes: 8 additions & 0 deletions Src/Website/.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 Src/Website/.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 Src/Website/.idea/vcs.xml

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

9 changes: 9 additions & 0 deletions Src/Website/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

semi: true
tabWidth: 4
trailingComma: "all"
singleQuote: false
arrowParens: "avoid"
printWidth: 120
endOfLine: "auto"

41 changes: 41 additions & 0 deletions Src/Website/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Website

This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.

### Installation

```
$ yarn
```

### Local Development

```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

### Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
3 changes: 3 additions & 0 deletions Src/Website/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
23 changes: 23 additions & 0 deletions Src/Website/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 Src/Website/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"
);
}
}
Loading

0 comments on commit d40f102

Please sign in to comment.