Skip to content

Commit

Permalink
bumping version, updating change log, updating readme
Browse files Browse the repository at this point in the history
closes #172
  • Loading branch information
belav committed May 17, 2021
1 parent 0c0bfaf commit a65c7a6
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 143 deletions.
36 changes: 24 additions & 12 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
# 0.9.3

[diff](https://github.com/belav/csharpier/compare/0.9.2...0.9.3)

- RecordDeclaration with Generics produces invalid code [#201](https://github.com/belav/csharpier/issues/201)
- Formatting of auto implemented properties with access modifiers [#188](https://github.com/belav/csharpier/issues/188)
- Verbatim string literals take into account EndOfLine configuration [#183](https://github.com/belav/csharpier/issues/183)
- CSharpierIgnore & CSharpierRC from parent directories should be respected. [#181](https://github.com/belav/csharpier/issues/181)
- Break apart readme [#172](https://github.com/belav/csharpier/issues/172)
- PatternMatching includes extra spaces [#167](https://github.com/belav/csharpier/issues/167)
- Re-add async file reads [#127](https://github.com/belav/csharpier/issues/127)
- Dictionary Initializer inserts extra new line [#103](https://github.com/belav/csharpier/issues/103)

#0.9.2
[diff](https://github.com/belav/csharpier/compare/0.9.1...0.9.2)

- Support "auto" for endOfLine [#147](https://api.github.com/repos/belav/csharpier/issues/147)
- Long Parameter Attribute should break after ending brace [#174](https://api.github.com/repos/belav/csharpier/issues/174)
- Attribute on parameter should have space [#104](https://api.github.com/repos/belav/csharpier/issues/104)

- Support "auto" for endOfLine [#147](https://github.com/belav/csharpier/issues/147)
- Long Parameter Attribute should break after ending brace [#174](https://github.com/belav/csharpier/issues/174)
- Attribute on parameter should have space [#104](https://github.com/belav/csharpier/issues/104)

# 0.9.1

[diff](https://github.com/belav/csharpier/compare/0.9.0...0.9.1)

- Add support for .csharpierignore [#159](https://api.github.com/repos/belav/csharpier/issues/159)
- Break before BinaryOperator [#152](https://api.github.com/repos/belav/csharpier/issues/152)
- LeadingComments affect breaking [#149](https://api.github.com/repos/belav/csharpier/issues/149)
- Ignore generated files by default [#140](https://api.github.com/repos/belav/csharpier/issues/140)
- Return with BinaryExpression [#137](https://api.github.com/repos/belav/csharpier/issues/137)
- IsPattern breaking inside of IfStatement [#130](https://api.github.com/repos/belav/csharpier/issues/130)
- SpaceBrace causing breaking when it shouldn't [#100](https://api.github.com/repos/belav/csharpier/issues/100)
- Implement Formatting Options with Configuration File [#10](https://api.github.com/repos/belav/csharpier/issues/10)
- Add support for .csharpierignore [#159](https://github.com/belav/csharpier/issues/159)
- Break before BinaryOperator [#152](https://github.com/belav/csharpier/issues/152)
- LeadingComments affect breaking [#149](https://github.com/belav/csharpier/issues/149)
- Ignore generated files by default [#140](https://github.com/belav/csharpier/issues/140)
- Return with BinaryExpression [#137](https://github.com/belav/csharpier/issues/137)
- IsPattern breaking inside of IfStatement [#130](https://github.com/belav/csharpier/issues/130)
- SpaceBrace causing breaking when it shouldn't [#100](https://github.com/belav/csharpier/issues/100)
- Implement Formatting Options with Configuration File [#10](https://github.com/belav/csharpier/issues/10)
3 changes: 3 additions & 0 deletions CSharpier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{7C99AEA7-E608-40B5-9B2E-353B6E4C9DBE}"
ProjectSection(SolutionItems) = preProject
Docs/EditorsAndCICD.md = Docs/EditorsAndCICD.md
Docs/Configuration.md = Docs/Configuration.md
Docs/CLI.md = Docs/CLI.md
Docs/Ignore.md = Docs/Ignore.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpier.Benchmarks", "Src\CSharpier.Benchmarks\CSharpier.Benchmarks.csproj", "{A338903F-69AD-4950-B827-8EE75F98B620}"
Expand Down
55 changes: 55 additions & 0 deletions Docs/CLI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

### Command Line Options
```console
Usage:
dotnet-csharpier [options] [<directoryOrFile>]

Arguments:
<directoryOrFile> A path to a directory containing files to format or a file to format. If a path is not specified the current directory is used

Options:
--check Check that files are formatted. Will not write any changes.
--fast Skip comparing syntax tree of formatted file to original file to validate changes.
--skip-write Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures.
--version Show version information
-?, -h, --help Show help and usage information


```

### \<directoryOrFile\>
Currently CSharpier only supports being passed a directory to recursively scan for .cs files or a single file to format.
If a directory is not supplied, it will use the current directory.

### --check
Used to check if your files are already formatted. Outputs any files that have not already been formatted.
This will return exit code 1 if there are unformatted files which is useful for CI pipelines.

### --fast
CSharpier validates the changes it makes to a file.
It does this by comparing the syntax tree before and after formatting, but ignoring any whitespace trivia in the syntax tree.
If a file fails validation, CSharpier will output the lines that differ. If this happens it indicates a bug in CSharpier's code.
This validation may be skipped by passing the --fast argument. Validation appears to increase the formatting time by ~50%.

An example of CSharpier finding a file that failed validation.
```
\src\[Snip]\AbstractReferenceFinder_GlobalSuppressions.cs - failed syntax tree validation
Original: Around Line 280
}
if (prefix.Span[^2] is < 'A' or > 'Z')
{
return false;
}
if (prefix.Span[^1] is not ':')
Formatted: Around Line 330
}
if (prefix.Span[^2] is )
{
return false;
}
if (prefix.Span[^1] is not ':')
```
40 changes: 40 additions & 0 deletions Docs/Configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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.

### Configuration Options
JSON
```json
{
"printWidth": 100,
"useTabs": false,
"tabWidth": 4,
"endOfLine": "auto"
}
```
YAML
```json
printWidth: 100
useTabs: false
tabWidth: 4
endOfLine: auto
```

#### Print Width
Specify at what point the printer will wrap content. This is not a hard limit. Some lines will be shorter or longer.

Default 100
#### Use Tabs
Indent lines with tabs instead of spaces.

Default false
#### Tab Width
Specify the number of spaces used per indentation level.

Default 4
#### End of Line
Specify what type of line endings will be printed in files.
Options
- "auto" - Detects which type of line ending to used based on the first one it encounters in the file **Default**
- "lf" - Line feed only (\n)
- "crlf" Carriage return and line feed (\r\n)
16 changes: 16 additions & 0 deletions Docs/Ignore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Ignoring Files
Csharpier will ignore the following files
- Any file that begins with ```TemporaryGeneratedFile_```
- Any file that ends with ```.designer.cs```
- Any file that ends with ```.generated.cs```
- Any file that ends with ```.g.cs```
- Any file that ends with ```.g.i.cs```
- Any file that begins with a comment that contains ```<autogenerated``` or ```<auto-generated```

Add a ```.csharpierignore``` file to ignore additional files and folders. The file uses [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format)

Example
```
Uploads/
**/App_Data/*.cs
```
138 changes: 13 additions & 125 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 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 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.
Expand Down Expand Up @@ -41,12 +43,13 @@ public class ClassName
public void LongUglyMethod(
string longParameter1,
string longParameter2,
string longParameter3)
{
string longParameter3
) {
this.LongUglyMethod(
"1234567890",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
}
```
Expand All @@ -57,134 +60,19 @@ dotnet tool install -g csharpier
```

## Basic Usage
By default csharpier will validate any files it formats by comparing the resulting syntax tree to the original.
Formatting will take longer, but csharpier will validate the formatted syntax tree against the original and warn if it believes it introduced breaking changes.

Run csharpier from the directory you wish to format.
```console
dotnet csharpier
```

## Configuration
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.

### Configuration Options
JSON
```json
{
"printWidth": 100,
"useTabs": false,
"tabWidth": 4,
"endOfLine": "auto"
}
```
YAML
```json
printWidth: 100
useTabs: false
tabWidth: 4
endOfLine: auto
```

#### Print Width
Specify at what point the printer will wrap content. This is not a hard limit. Some lines will be shorter or longer.

Default 100
#### Use Tabs
Indent lines with tabs instead of spaces.

Default false
#### Tab Width
Specify the number of spaces used per indentation level.

Default 4
#### End of Line
Specify what type of line endings will be printed in files.
Options
- "auto" - Detects which type of line ending to used based on the first one it encounters in the file **Default**
- "lf" - Line feed only (\n)
- "crlf" Carriage return and line feed (\r\n)

### Ignoring Files
Csharpier will ignore the following files
- Any file that begins with ```TemporaryGeneratedFile_```
- Any file that ends with ```.designer.cs```
- Any file that ends with ```.generated.cs```
- Any file that ends with ```.g.cs```
- Any file that ends with ```.g.i.cs```
- Any file that begins with a comment that contains ```<autogenerated``` or ```<auto-generated```

Add a ```.csharpierignore``` file to ignore additional files and folders. The file uses [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format)

Example
```
Uploads/
**/App_Data/*.cs
```

### Command Line Options
```console
Usage:
dotnet-csharpier [options] [<directoryOrFile>]

Arguments:
<directoryOrFile> A path to a directory containing files to format or a file to format. If a path is not specified the current directory is used

Options:
--check Check that files are formatted. Will not write any changes.
--fast Skip comparing syntax tree of formatted file to original file to validate changes.
--skip-write Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures.
--version Show version information
-?, -h, --help Show help and usage information


```

### \<directoryOrFile\>
Currently CSharpier only supports being passed a directory to recursively scan for .cs files or a single file to format.
If a directory is not supplied, it will use the current directory.

### --check
Used to check if your files are already formatted. Outputs any files that have not already been formatted.
This will return exit code 1 if there are unformatted files which is useful for CI pipelines.

### --fast
CSharpier validates the changes it makes to a file.
It does this by comparing the syntax tree before and after formatting, but ignoring any whitespace trivia in the syntax tree.
If a file fails validation, CSharpier will output the lines that differ. If this happens it indicates a bug in CSharpier's code.
This validation may be skipped by passing the --fast argument. Validation appears to increase the formatting time by ~50%.

An example of CSharpier finding a file that failed validation.
```
\src\[Snip]\AbstractReferenceFinder_GlobalSuppressions.cs - failed syntax tree validation
Original: Around Line 280
}
if (prefix.Span[^2] is < 'A' or > 'Z')
{
return false;
}
if (prefix.Span[^1] is not ':')
Formatted: Around Line 330
}
if (prefix.Span[^2] is )
{
return false;
}
if (prefix.Span[^1] is not ':')
```

## More Documentation
[Editors and CI/CD](Docs/EditorsAndCICD.md)
## Documentation
[Command Line Interface](Docs/CLI.md)
[Configuration File](Docs/Configure.md)
[Editors and CI/CD](Docs/EditorsAndCICD.md)
[Ignoring Files](Docs/Ignore.md)
[ChangeLog](CHANGELOG.md)

## Contributing
See [Development Readme](CONTRIBUTING.md)

Join Us [![Discord](https://img.shields.io/badge/Discord-chat?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/HfAKGEZQcX)

[ChangeLog](CHANGELOG.md)
7 changes: 4 additions & 3 deletions Scripts/ChangeLog.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# this uses https://github.com/microsoft/PowerShellForGitHub
# you'll need to Set-GitHubAuthentication first

$versionNumber = "0.9.1"
$previousVersionNumber = "0.9.0"
$versionNumber = "0.9.3"
$previousVersionNumber = "0.9.2"

$repository = "https://github.com/belav/csharpier"

Expand All @@ -25,7 +25,8 @@ foreach ($issue in $issues) {
if ($issue.title.ToLower().Contains("checklist")) {
continue
}
$content.AppendLine("- " + $issue.title + " [#" + $issue.number +"](" + $issue.url + ")")

$content.AppendLine("- " + $issue.title + " [#" + $issue.number +"](" + $issue.html_url + ")")
}

Write-Output $content.ToString()
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/LineEndingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void Escaped_LineEndings_In_Verbatim_String_Should_Remain(
string escapedNewLine,
EndOfLine endOfLine
) {
var code = @$"class ClassName
var code =
@$"class ClassName
{{
string value = @""one{escapedNewLine}two"";
}}
Expand Down
3 changes: 2 additions & 1 deletion Src/CSharpier.Tests/SyntaxNodeComparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public ConstructorWithBase(string value)
[Test]
public void MissingAttribute()
{
var left = @"class Resources
var left =
@"class Resources
{
[Obsolete]
public Resources()
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier/CSharpier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>CSharpier</RootNamespace>
<PackAsTool>true</PackAsTool>
<Version>0.9.2</Version>
<Version>0.9.3</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit a65c7a6

Please sign in to comment.