Skip to content

Commit a8c1c6a

Browse files
authored
Releasing 0.23.0 (#844)
* Releasing 0.23.0 * update docs
1 parent 336dd74 commit a8c1c6a

8 files changed

Lines changed: 264 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,218 @@
1+
# 0.23.0
2+
## Breaking Changes
3+
#### Make compile errors public when using CSharpier.Core [#799](https://github.com/belav/csharpier/issues/799)
4+
Previously `CodeFormatter.Format(unformattedCode)` and its overloads returned only the formatted code. It now returns a result object.
5+
```c#
6+
public class CodeFormatterResult
7+
{
8+
public string Code { get; }
9+
public IEnumerable<Diagnostic> CompilationErrors { get; }
10+
}
11+
```
12+
13+
This is a breaking change. There were also a number of types that should not have been `public` that were made `internal`.
14+
15+
Thanks go to @verdverm for the suggestion
16+
## What's Changed
17+
#### Allow comment-description suffix on csharpier-ignore comments [#835](https://github.com/belav/csharpier/issues/835)
18+
It is now possible to include a suffix on `csharpier-ignore` comments. The description must be seperated from the comment by at least one - character.
19+
```c#
20+
// csharpier-ignore - class copied as-is from another project
21+
public class Unformatted {
22+
private string unformatted;
23+
}
24+
25+
// csharpier-ignore-start -- class copied as-is from another project
26+
public class Unformatted1 { }
27+
public class Unformatted2 { }
28+
// csharpier-ignore-end
29+
```
30+
Thanks go to @strepto for the suggestion
31+
32+
#### Fix formatting for open generics [#832](https://github.com/belav/csharpier/issues/832)
33+
```c#
34+
// 0.22.1
35+
typeof(AnExceptionallyLongAndElaborateClassNameToMakeAnExampleRegardingOpenGenerics<
36+
,
37+
>).MakeGenericType(typeof(string), typeof(int));
38+
39+
// 0.23.0
40+
typeof(AnExceptionallyLongAndElaborateClassNameToMakeAnExampleRegardingOpenGenerics<,>).MakeGenericType(
41+
typeof(string),
42+
typeof(int)
43+
);
44+
```
45+
46+
47+
Thanks go to @jonstodle for reporting the issue
48+
49+
#### #region should be indented based on context [#812](https://github.com/belav/csharpier/issues/812)
50+
Previously the preceding whitespace was left as is on `#region` and `#endregion` which resulted undesired formatting.
51+
```c#
52+
// 0.22.1
53+
public class ClassName
54+
{
55+
#region Ugly methods
56+
public int LongUglyMethod()
57+
{
58+
return 42;
59+
}
60+
#endregion
61+
}
62+
63+
// 0.23.0
64+
public class ClassName
65+
{
66+
#region Ugly methods
67+
public int LongUglyMethod()
68+
{
69+
return 42;
70+
}
71+
#endregion
72+
}
73+
```
74+
Thanks go to @jods4 for reporting the issue
75+
#### Return statement followed by linq query syntax not indenting correctly [#811](https://github.com/belav/csharpier/issues/811)
76+
```c#
77+
// 0.22.1
78+
return from i in Enumerable.Range(0, 10)
79+
let i2 = i * i
80+
where i2 < 100
81+
select new { Square = i2, Root = i };
82+
83+
// 0.23.0
84+
return from i in Enumerable.Range(0, 10)
85+
let i2 = i * i
86+
where i2 < 100
87+
select new { Square = i2, Root = i };
88+
```
89+
90+
Thanks go to @jods4 for reporting the issue
91+
92+
#### Array and dictionary initializers should break in some cases to improve readability [#809](https://github.com/belav/csharpier/issues/809)
93+
```c#
94+
// 0.22.1
95+
var dictionaryInitializer = new Dictionary<int, string> { { 1, "" }, { 2, "a" }, { 3, "b" } };
96+
int[,,] cube = { { { 111, 112 }, { 121, 122 } }, { { 211, 212 }, { 221, 222 } } };
97+
int[][] jagged = { { 111 }, { 121, 122 } };
98+
99+
// 0.23.0
100+
var dictionaryInitializer = new Dictionary<int, string>
101+
{
102+
{ 1, "" },
103+
{ 2, "a" },
104+
{ 3, "b" }
105+
};
106+
int[,,] cube =
107+
{
108+
{
109+
{ 111, 112 },
110+
{ 121, 122 }
111+
},
112+
{
113+
{ 211, 212 },
114+
{ 221, 222 }
115+
}
116+
};
117+
int[][] jagged =
118+
{
119+
{ 111 },
120+
{ 121, 122 }
121+
};
122+
```
123+
#### List initializer inside object initializer breaks poorly [#802](https://github.com/belav/csharpier/issues/802)
124+
```c#
125+
// 0.22.1
126+
var someObject = new SomeObject { SomeArray = new SomeOtherObject[]
127+
{
128+
new SomeOtherObject { SomeProperty = 1 },
129+
new SomeOtherObject()
130+
}.CallMethod().CallMethod() };
131+
132+
// 0.23.0
133+
var someObject = new SomeObject
134+
{
135+
SomeArray = new SomeOtherObject[]
136+
{
137+
new SomeOtherObject { SomeProperty = 1 },
138+
new SomeOtherObject()
139+
}
140+
.CallMethod()
141+
.CallMethod()
142+
};
143+
144+
```
145+
146+
Thanks go to @shocklateboy92 for reporting the issue
147+
#### Allow passing --config-path to cli [#777](https://github.com/belav/csharpier/issues/777)
148+
It is now possible to pass `--config-path` to the cli for cases where it is not in the root or you want to bypass the auto location and speed up formatting requests.
149+
```bash
150+
dotnet csharpier . --config-path "./config/.csharpierrc"
151+
```
152+
153+
Thanks go to @bdovaz for the suggestion
154+
155+
#### Allow blank lines in query syntax [#754](https://github.com/belav/csharpier/issues/754)
156+
It is now possible to add blank lines in query syntax expressions which can aid in readability
157+
```c#
158+
var result = await (
159+
from post in dbContext.Posts
160+
join blog in dbContext.Blogs on post.BlogId equals blog.Id
161+
162+
let count = dbContext.Posts.Count(p => p.Name == post.Name)
163+
164+
where post.Id == 1
165+
select new
166+
{
167+
Post = post,
168+
Blog = blog,
169+
SamePostNameCount = count
170+
}
171+
)
172+
.AsNoTracking()
173+
.FirstAsync();
174+
```
175+
176+
Thanks go to @TwentyFourMinutes for the suggestion
177+
178+
#### #if causes line after it to break when it contains an if [#666](https://github.com/belav/csharpier/issues/666)
179+
```c#
180+
// 0.22.1
181+
class ClassName
182+
{
183+
public void MethodName()
184+
{
185+
#if !IF_STATEMENT_HERE_SHOULD_NOT_BREAK_INVOCATION_AFTER_ENDIF
186+
if (true)
187+
{
188+
return;
189+
}
190+
#endif
191+
SomeObject
192+
.CallMethod()
193+
.CallOtherMethod(shouldNotBreak);
194+
}
195+
}
196+
197+
// 0.23.0
198+
class ClassName
199+
{
200+
public void MethodName()
201+
{
202+
#if !IF_STATEMENT_HERE_SHOULD_NOT_BREAK_INVOCATION_AFTER_ENDIF
203+
if (true)
204+
{
205+
return;
206+
}
207+
#endif
208+
SomeObject.CallMethod().CallOtherMethod(shouldNotBreak);
209+
}
210+
}
211+
212+
```
213+
214+
**Full Changelog**: https://github.com/belav/csharpier/compare/0.22.0...0.23.0
215+
1216
# 0.22.1
2217
## What's Changed
3218
#### Fix for CSharpier.MsBuild so it selects a compatible framework if the project does not target net6 or net7 [#797](https://github.com/belav/csharpier/pull/797)

CSharpier.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.22.1</Version>
3+
<Version>0.23.0</Version>
44
<PackageLicenseExpression>MIT</PackageLicenseExpression>
55
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
66
<RepositoryType>git</RepositoryType>

Docs/CLI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public class ClassName
127127
```
128128

129129
### --config-path
130+
_First available in 0.23.0_
130131
If your configuration file lives in a location that CSharpier would not normally resolve it (such as in a config folder)
131132
you can pass the path for the configuration file to CSharpier.
132133
```bash

Src/CSharpier/PublicAPI.Shipped.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ CSharpier.CodeFormatterOptions
44
CSharpier.CodeFormatterOptions.CodeFormatterOptions() -> void
55
CSharpier.CodeFormatterOptions.Width.get -> int
66
CSharpier.CodeFormatterOptions.Width.init -> void
7-
static CSharpier.CodeFormatter.Format(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null) -> string!
8-
static CSharpier.CodeFormatter.Format(string! code, CSharpier.CodeFormatterOptions? options = null) -> string!
9-
static CSharpier.CodeFormatter.FormatAsync(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
10-
static CSharpier.CodeFormatter.FormatAsync(string! code, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
7+
CSharpier.CodeFormatterResult
8+
CSharpier.CodeFormatterResult.Code.get -> string!
9+
CSharpier.CodeFormatterResult.CompilationErrors.get -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Diagnostic!>!
10+
static CSharpier.CodeFormatter.Format(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null) -> CSharpier.CodeFormatterResult!
11+
static CSharpier.CodeFormatter.Format(string! code, CSharpier.CodeFormatterOptions? options = null) -> CSharpier.CodeFormatterResult!
12+
static CSharpier.CodeFormatter.FormatAsync(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<CSharpier.CodeFormatterResult!>!
13+
static CSharpier.CodeFormatter.FormatAsync(string! code, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<CSharpier.CodeFormatterResult!>!
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
CSharpier.CodeFormatterResult
2-
CSharpier.CodeFormatterResult.Code.get -> string!
3-
CSharpier.CodeFormatterResult.CompilationErrors.get -> System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.Diagnostic!>!
4-
static CSharpier.CodeFormatter.Format(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null) -> CSharpier.CodeFormatterResult!
5-
static CSharpier.CodeFormatter.Format(string! code, CSharpier.CodeFormatterOptions? options = null) -> CSharpier.CodeFormatterResult!
6-
static CSharpier.CodeFormatter.FormatAsync(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<CSharpier.CodeFormatterResult!>!
7-
static CSharpier.CodeFormatter.FormatAsync(string! code, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<CSharpier.CodeFormatterResult!>!
8-
*REMOVED*static CSharpier.CodeFormatter.Format(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null) -> string!
9-
*REMOVED*static CSharpier.CodeFormatter.Format(string! code, CSharpier.CodeFormatterOptions? options = null) -> string!
10-
*REMOVED*static CSharpier.CodeFormatter.FormatAsync(Microsoft.CodeAnalysis.SyntaxTree! syntaxTree, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
11-
*REMOVED*static CSharpier.CodeFormatter.FormatAsync(string! code, CSharpier.CodeFormatterOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<string!>!
1+


Src/Website/docs/API.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ This requires adding the [CSharpier.Core](https://www.nuget.org/packages/CSharpi
88
dotnet add package CSharpier.Core
99
```
1010

11+
Some examples of working with the class `CodeFormatter`
12+
1113
```csharp
1214

13-
var unformattedCode = "public class ClassName { }"
15+
var unformattedCode = "public class ClassName { }";
1416

15-
var formattedCode = CodeFormatter.Format(unformattedCode);
16-
var asyncFormattedCode = await CodeFormatter.FormatAsync(unformattedCode);
17+
var formattedCode = CodeFormatter.Format(unformattedCode).Code;
18+
var asyncFormattedCode = await CodeFormatter.FormatAsync(unformattedCode).Code;
1719

1820
var options = new CodeFormatterOptions { Width = 60 };
19-
2021
var narrowerCode = CodeFormatter.Format(unformattedCode, options);
2122
var asyncNarrowerCode = await CodeFormatter.FormatAsync(unformattedCode, options);
2223

24+
var codeWithCompilationErrors = "public class ClassName {";
25+
var result = CodeFormatter.Format(codeFormCompilationErrors);
26+
if (result.CompilationErrors.Any())
27+
{
28+
// result.Code will still be the unformatted code, it is not possible to format code that can't compile
29+
// result.CompilationErrors will contain all the errors from attempting to compile the code
30+
}
31+
2332
```

Src/Website/docs/CLI.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Options:
2626
--skip-write Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures.
2727
--write-stdout Write the results of formatting any files to stdout.
2828
--pipe-multiple-files Keep csharpier running so that multiples files can be piped to it via stdin
29+
--config-path Path to the CSharpier configuration file
2930
--version Show version information
3031
-?, -h, --help Show help and usage information
3132

@@ -124,3 +125,14 @@ public class ClassName
124125
public string Field;
125126
}
126127
```
128+
129+
### --config-path
130+
_First available in 0.23.0_
131+
If your configuration file lives in a location that CSharpier would not normally resolve it (such as in a config folder)
132+
you can pass the path for the configuration file to CSharpier.
133+
```bash
134+
dotnet csharpier . --config-path "./config/.csharpierrc"
135+
136+
# also supports any name for the config file
137+
dotnet csharpier . --config-path "./config/csharpier.yaml"
138+
```

Src/Website/docs/Ignore.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,18 @@ public class ClassName
8989
}
9090
}
9191
}
92+
```
93+
94+
As of 0.23.0 both types of ignores can include a description as part of the comment. The description must be seperated from the comment by at least one - character.
95+
96+
```c#
97+
// csharpier-ignore - class copied as-is from another project
98+
public class Unformatted {
99+
private string unformatted;
100+
}
101+
102+
// csharpier-ignore-start -- class copied as-is from another project
103+
public class Unformatted1 { }
104+
public class Unformatted2 { }
105+
// csharpier-ignore-end
92106
```

0 commit comments

Comments
 (0)