Skip to content

Commit

Permalink
Merge pull request #171 from belav/0.9.1-rc
Browse files Browse the repository at this point in the history
Updating for 0.9.1
  • Loading branch information
belav authored May 5, 2021
2 parents a38da1a + 861a307 commit e37b54d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 35 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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)
10 changes: 6 additions & 4 deletions CSharpier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ ProjectSection(SolutionItems) = preProject
CheckVersion.txt = CheckVersion.txt
LICENSE = LICENSE
README.md = README.md
Scripts\CreateReviewCodePRs.ps1 = Scripts\CreateReviewCodePRs.ps1
CONTRIBUTING.md = CONTRIBUTING.md
CHANGELOG.md = CHANGELOG.md
.csharpierignore = .csharpierignore
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{176BB0EA-B72B-4ACA-82AE-C16A732BE023}"
ProjectSection(SolutionItems) = preProject
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
.github\workflows\format_repositories.yml = .github\workflows\format_repositories.yml
.github\workflows\nuget_publish.yml = .github\workflows\nuget_publish.yml
.github\workflows\playground_publish.yml = .github\workflows\playground_publish.yml
.github\workflows\validatePR.yml = .github\workflows\validatePR.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{62DCCDB3-45D3-4236-B34A-E01618028BFE}"
ProjectSection(SolutionItems) = preProject
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
Scripts/RunLinuxTests.ps1 = Scripts/RunLinuxTests.ps1
Scripts/CreateReviewCodePRs.ps1 = Scripts/CreateReviewCodePRs.ps1
Scripts/ChangeLog.ps1 = Scripts/ChangeLog.ps1
Scripts/UpdateForkedRepos.ps1 = Scripts/UpdateForkedRepos.ps1
EndProjectSection
EndProject
Global
Expand Down
89 changes: 66 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
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.

### Work In Progress
CSharpier is currently in alpha and I'd be hesitant to recommend using it on production code.
- 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.
CSharpier is still in active development.
- The rules it uses to format code are not yet finalized and some of the results are a little ugly.
- The rules it uses to format your code will change over time.
- 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.
- This process has been automated and runs each time code is pushed.
- The rules it uses to format code are not yet finalized and some of the results are ugly.
- The rules it uses to format your code will change over time.
- There are currently no options exposed for formatting.
- The options for what files it should format are limited.
- There have been a handful of critical bugs that resulted in a loss of source code since it has entered alpha.


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.

Expand Down Expand Up @@ -58,30 +56,74 @@ public class ClassName
dotnet tool install -g csharpier
```

## Usage
### Basic Usage
## 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
# the first time running csharpier it is normally not possible to review all the changes it makes
# and catch any instances of code being lost
dotnet csharpier

# after a project has already been csharpiered, you can choose
# to use the --fast flag to speed up formatting
dotnet csharpier --fast
```

### Formatting Single File
```console
dotnet chsarpier [PathToFile]
## 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": "lf"
}
```
YAML
```json
printWidth: 100
useTabs: false
tabWidth: 4
endOfLine: lf
```

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

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.
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
- "lf" - Line feed only (\n) **Default**
- "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>]
Expand Down Expand Up @@ -149,6 +191,7 @@ An example of CSharpier finding a file that failed validation.

## 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)

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)
31 changes: 31 additions & 0 deletions Scripts/ChangeLog.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# this uses https://github.com/microsoft/PowerShellForGitHub
# you'll need to Set-GitHubAuthentication first

$versionNumber = "0.9.1"
$previousVersionNumber = "0.9.0"

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

$milestones = Get-GitHubMilestone -Uri $repository -State "Open"
$milestoneNumber = -1
foreach($milestone in $milestones) {
if ($milestone.title -eq $versionNumber) {
$milestoneNumber = $milestone.number
}
}

$issues = Get-GitHubIssue -Uri https://github.com/belav/csharpier -MilestoneNumber $milestoneNumber -State All

$content = [System.Text.StringBuilder]::new()
$content.AppendLine("# " + $versionNumber)
$content.AppendLine()
$content.AppendLine("[diff](https://github.com/belav/csharpier/compare/" + $previousVersionNumber + "..." + $versionNumber + ")")
$content.AppendLine()
foreach ($issue in $issues) {
if ($issue.title.ToLower().Contains("checklist")) {
continue
}
$content.AppendLine("- " + $issue.title + " [#" + $issue.number +"](" + $issue.url + ")")
}

Write-Output $content.ToString()
17 changes: 10 additions & 7 deletions Scripts/CreateReviewCodePRs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ if ($version -eq "") {
$csharpierRepo = "C:\Projects\csharpier"
$csharpierRepos = "C:\Projects\csharpierForkedRepos"

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

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

$prs = @()

foreach($folder in Get-ChildItem $csharpierRepos) {
Write-Output $folder.FullName

Set-Location $folder.FullName
Push-Location $folder.FullName

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

Write-Output $prs
33 changes: 33 additions & 0 deletions Scripts/UpdateForkedRepos.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
param (
[string]$version
)

if ($version -eq "") {
Write-Output "need version"
exit 1
}
$csharpierRepos = "C:\Projects\csharpierForkedRepos"

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

foreach($folder in Get-ChildItem $csharpierRepos) {
if ($folder.FullName.Contains("aspnetcore")) {
continue
}
Write-Output $folder.FullName

Push-Location $folder.FullName

#TODO a lot of the git commands look like they fail, but really succeed, wtf?
& git checkout main
& git reset --hard

dotnet csharpier

& git add -A
& git commit -m $versionWithQuotes
& git tag $version
& git push origin
& git push origin --tags
Pop-Location
}
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.0</Version>
<Version>0.9.1</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down

0 comments on commit e37b54d

Please sign in to comment.