Skip to content

Commit e37b54d

Browse files
authored
Merge pull request #171 from belav/0.9.1-rc
Updating for 0.9.1
2 parents a38da1a + 861a307 commit e37b54d

File tree

7 files changed

+159
-35
lines changed

7 files changed

+159
-35
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 0.9.1
2+
3+
[diff](https://github.com/belav/csharpier/compare/0.9.0...0.9.1)
4+
5+
- Add support for .csharpierignore [#159](https://api.github.com/repos/belav/csharpier/issues/159)
6+
- Break before BinaryOperator [#152](https://api.github.com/repos/belav/csharpier/issues/152)
7+
- LeadingComments affect breaking [#149](https://api.github.com/repos/belav/csharpier/issues/149)
8+
- Ignore generated files by default [#140](https://api.github.com/repos/belav/csharpier/issues/140)
9+
- Return with BinaryExpression [#137](https://api.github.com/repos/belav/csharpier/issues/137)
10+
- IsPattern breaking inside of IfStatement [#130](https://api.github.com/repos/belav/csharpier/issues/130)
11+
- SpaceBrace causing breaking when it shouldn't [#100](https://api.github.com/repos/belav/csharpier/issues/100)
12+
- Implement Formatting Options with Configuration File [#10](https://api.github.com/repos/belav/csharpier/issues/10)

CSharpier.sln

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ ProjectSection(SolutionItems) = preProject
1414
CheckVersion.txt = CheckVersion.txt
1515
LICENSE = LICENSE
1616
README.md = README.md
17-
Scripts\CreateReviewCodePRs.ps1 = Scripts\CreateReviewCodePRs.ps1
1817
CONTRIBUTING.md = CONTRIBUTING.md
18+
CHANGELOG.md = CHANGELOG.md
1919
.csharpierignore = .csharpierignore
2020
EndProjectSection
2121
EndProject
2222
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{176BB0EA-B72B-4ACA-82AE-C16A732BE023}"
2323
ProjectSection(SolutionItems) = preProject
24-
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
24+
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
2525
.github\workflows\nuget_publish.yml = .github\workflows\nuget_publish.yml
2626
.github\workflows\playground_publish.yml = .github\workflows\playground_publish.yml
2727
.github\workflows\validatePR.yml = .github\workflows\validatePR.yml
2828
EndProjectSection
2929
EndProject
3030
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{62DCCDB3-45D3-4236-B34A-E01618028BFE}"
3131
ProjectSection(SolutionItems) = preProject
32-
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
33-
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
32+
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
33+
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
34+
Scripts/ChangeLog.ps1 = Scripts/ChangeLog.ps1
35+
Scripts/UpdateForkedRepos.ps1 = Scripts/UpdateForkedRepos.ps1
3436
EndProjectSection
3537
EndProject
3638
Global

README.md

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
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.
33

44
### Work In Progress
5-
CSharpier is currently in alpha and I'd be hesitant to recommend using it on production code.
6-
- It has been tested against a large number of public repositories to validate that the changes it makes do not lose any syntax but there is a possibility it will break your code.
5+
CSharpier is still in active development.
6+
- The rules it uses to format code are not yet finalized and some of the results are a little ugly.
7+
- The rules it uses to format your code will change over time.
8+
- It has been tested against a large number of public repositories to validate that the changes it makes do not lose any syntax but there is a possibility it will break your code.
79
- This process has been automated and runs each time code is pushed.
8-
- The rules it uses to format code are not yet finalized and some of the results are ugly.
9-
- The rules it uses to format your code will change over time.
10-
- There are currently no options exposed for formatting.
11-
- The options for what files it should format are limited.
12-
- There have been a handful of critical bugs that resulted in a loss of source code since it has entered alpha.
10+
1311

1412
I encourage you to try it out on your own code and report any bugs, code that doesn't format well, or opinions on how you think the formatting should change. If you can live with the fact that the formatting will be changing over time, it is reasonably 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.
1513

@@ -58,30 +56,74 @@ public class ClassName
5856
dotnet tool install -g csharpier
5957
```
6058

61-
## Usage
62-
### Basic Usage
59+
## Basic Usage
60+
By default csharpier will validate any files it formats by comparing the resulting syntax tree to the original.
61+
Formatting will take longer, but csharpier will validate the formatted syntax tree against the original and warn if it believes it introduced breaking changes.
62+
6363
Run csharpier from the directory you wish to format.
6464
```console
65-
# the first time running csharpier it is normally not possible to review all the changes it makes
66-
# and catch any instances of code being lost
6765
dotnet csharpier
68-
69-
# after a project has already been csharpiered, you can choose
70-
# to use the --fast flag to speed up formatting
71-
dotnet csharpier --fast
7266
```
7367

74-
### Formatting Single File
75-
```console
76-
dotnet chsarpier [PathToFile]
68+
## Configuration
69+
CSharpier has support for a configuration file. You can use any of the following files
70+
- A ```.csharpierrc``` file in JSON or YAML.
71+
- A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file.
72+
73+
### Configuration Options
74+
JSON
75+
```json
76+
{
77+
"printWidth": 100,
78+
"useTabs": false,
79+
"tabWidth": 4,
80+
"endOfLine": "lf"
81+
}
82+
```
83+
YAML
84+
```json
85+
printWidth: 100
86+
useTabs: false
87+
tabWidth: 4
88+
endOfLine: lf
7789
```
7890

79-
### More Information
80-
CSharpier currently excludes .g.cs and .cshtml.cs files.
91+
#### Print Width
92+
Specify at what point the printer will wrap content. This is not a hard limit. Some lines will be shorter or longer.
8193

82-
By default csharpier will validate any files it formats by comparing the resulting syntax tree to the original.
83-
Formatting will take longer, but csharpier will validate the formatted syntax tree against the original and warn if it believes it introduced breaking changes.
94+
Default 100
95+
#### Use Tabs
96+
Indent lines with tabs instead of spaces.
8497

98+
Default false
99+
#### Tab Width
100+
Specify the number of spaces used per indentation level.
101+
102+
Default 4
103+
#### End of Line
104+
Specify what type of line endings will be printed in files.
105+
Options
106+
- "lf" - Line feed only (\n) **Default**
107+
- "crlf" Carriage return and line feed (\r\n)
108+
109+
### Ignoring Files
110+
Csharpier will ignore the following files
111+
- Any file that begins with ```TemporaryGeneratedFile_```
112+
- Any file that ends with ```.designer.cs```
113+
- Any file that ends with ```.generated.cs```
114+
- Any file that ends with ```.g.cs```
115+
- Any file that ends with ```.g.i.cs```
116+
- Any file that begins with a comment that contains ```<autogenerated``` or ```<auto-generated```
117+
118+
Add a ```.csharpierignore``` file to ignore additional files and folders. The file uses [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format)
119+
120+
Example
121+
```
122+
Uploads/
123+
**/App_Data/*.cs
124+
```
125+
126+
### Command Line Options
85127
```console
86128
Usage:
87129
dotnet-csharpier [options] [<directoryOrFile>]
@@ -149,6 +191,7 @@ An example of CSharpier finding a file that failed validation.
149191

150192
## Contributing
151193
See [Development Readme](CONTRIBUTING.md)
152-
Join Us [![Discord](https://img.shields.io/badge/Discord-chat?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/HfAKGEZQcX)
153194

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

197+
[ChangeLog](CHANGELOG.md)

Scripts/ChangeLog.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# this uses https://github.com/microsoft/PowerShellForGitHub
2+
# you'll need to Set-GitHubAuthentication first
3+
4+
$versionNumber = "0.9.1"
5+
$previousVersionNumber = "0.9.0"
6+
7+
$repository = "https://github.com/belav/csharpier"
8+
9+
$milestones = Get-GitHubMilestone -Uri $repository -State "Open"
10+
$milestoneNumber = -1
11+
foreach($milestone in $milestones) {
12+
if ($milestone.title -eq $versionNumber) {
13+
$milestoneNumber = $milestone.number
14+
}
15+
}
16+
17+
$issues = Get-GitHubIssue -Uri https://github.com/belav/csharpier -MilestoneNumber $milestoneNumber -State All
18+
19+
$content = [System.Text.StringBuilder]::new()
20+
$content.AppendLine("# " + $versionNumber)
21+
$content.AppendLine()
22+
$content.AppendLine("[diff](https://github.com/belav/csharpier/compare/" + $previousVersionNumber + "..." + $versionNumber + ")")
23+
$content.AppendLine()
24+
foreach ($issue in $issues) {
25+
if ($issue.title.ToLower().Contains("checklist")) {
26+
continue
27+
}
28+
$content.AppendLine("- " + $issue.title + " [#" + $issue.number +"](" + $issue.url + ")")
29+
}
30+
31+
Write-Output $content.ToString()

Scripts/CreateReviewCodePRs.ps1

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ if ($version -eq "") {
2626
$csharpierRepo = "C:\Projects\csharpier"
2727
$csharpierRepos = "C:\Projects\csharpierForkedRepos"
2828

29-
# TODO also add another script for basically updating these with the actual release
30-
# should that script merge PRs? or just format directly on master? Maybe closing the existing PRs?
3129
& dotnet build $csharpierRepo\Src\CSharpier\CSharpier.csproj -c Release
3230

3331
$versionWithQuotes = "`"" + $version + "`"";
3432

33+
$prs = @()
34+
3535
foreach($folder in Get-ChildItem $csharpierRepos) {
3636
Write-Output $folder.FullName
3737

38-
Set-Location $folder.FullName
38+
Push-Location $folder.FullName
3939

40-
#TODO a lot of the git commands look like they fail, but really succeed, wtf?
40+
#TODO git writes to stderr or some stupid shit
4141
& git checkout main
4242
& git reset --hard
4343
& git branch -d $version
@@ -49,6 +49,9 @@ foreach($folder in Get-ChildItem $csharpierRepos) {
4949
& git commit -m $versionWithQuotes
5050
& git push --set-upstream origin $version
5151
#uses https://github.com/github/hub/releases
52-
& hub pull-request -b belav:main -m $versionWithQuotes
53-
# TODO keep track of the PRs created to write out all the links at the end
54-
}
52+
$newPr = & hub pull-request -b belav:main -m $versionWithQuotes
53+
$prs += $newPr
54+
Pop-Location
55+
}
56+
57+
Write-Output $prs

Scripts/UpdateForkedRepos.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
param (
2+
[string]$version
3+
)
4+
5+
if ($version -eq "") {
6+
Write-Output "need version"
7+
exit 1
8+
}
9+
$csharpierRepos = "C:\Projects\csharpierForkedRepos"
10+
11+
$versionWithQuotes = "`"" + $version + "`"";
12+
13+
foreach($folder in Get-ChildItem $csharpierRepos) {
14+
if ($folder.FullName.Contains("aspnetcore")) {
15+
continue
16+
}
17+
Write-Output $folder.FullName
18+
19+
Push-Location $folder.FullName
20+
21+
#TODO a lot of the git commands look like they fail, but really succeed, wtf?
22+
& git checkout main
23+
& git reset --hard
24+
25+
dotnet csharpier
26+
27+
& git add -A
28+
& git commit -m $versionWithQuotes
29+
& git tag $version
30+
& git push origin
31+
& git push origin --tags
32+
Pop-Location
33+
}

Src/CSharpier/CSharpier.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<TargetFramework>net5.0</TargetFramework>
88
<RootNamespace>CSharpier</RootNamespace>
99
<PackAsTool>true</PackAsTool>
10-
<Version>0.9.0</Version>
10+
<Version>0.9.1</Version>
1111
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1212
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
1313
<RepositoryType>git</RepositoryType>

0 commit comments

Comments
 (0)