Skip to content

Commit d7d791e

Browse files
authored
Releasing 1.0.0 (#1576)
1 parent dec984c commit d7d791e

21 files changed

+500
-190
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"csharpier": {
6-
"version": "1.0.0-alpha45",
6+
"version": "1.0.0-alpha99",
77
"commands": [
88
"csharpier"
99
]

CHANGELOG.md

Lines changed: 273 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,275 @@
1-
# 0.30.6
1+
# 1.0.0
2+
## Major Changes
3+
### Support for formatting XML [#819](https://github.com/belav/csharpier/issues/819)
4+
CSharpier now formats xml files by default. It will try to format ".csproj", ".props", ".targets", ".xml", ".config" as if they were xml. \
5+
If a file is not valid xml it will be treated as a warning. \
6+
The default indent size is `2` instead of `4`
7+
8+
### Performance Improvements
9+
@TimothyMakkison put a lot of effort into improving the performance of CSharpier. These benchmark numbers show drastic improvement for both speed and memory usage.
10+
11+
Baseline
12+
```
13+
| Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Gen2 | Allocated |
14+
|------------------------------ |---------:|--------:|--------:|---------:|-----------:|----------:|----------:|----------:|
15+
| Default_CodeFormatter_Tests | 233.3 ms | 4.63 ms | 8.23 ms | 229.7 ms | 11000.0000 | 4000.0000 | 1000.0000 | 101.41 MB |
16+
| Default_CodeFormatter_Complex | 433.7 ms | 8.53 ms | 7.56 ms | 433.4 ms | 20000.0000 | 5000.0000 | 1000.0000 | 182.44 MB |
17+
```
18+
19+
After Improvements
20+
```
21+
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
22+
|------------------------------ |----------:|---------:|---------:|----------:|----------:|----------:|
23+
| Default_CodeFormatter_Tests | 64.72 ms | 0.548 ms | 0.512 ms | 1666.6667 | 1000.0000 | 18.33 MB |
24+
| Default_CodeFormatter_Complex | 137.83 ms | 2.730 ms | 4.708 ms | 3000.0000 | 1000.0000 | 30.78 MB |
25+
26+
```
27+
## Breaking Changes
28+
### ConfigurationFile - rename TabWidth to IndentSize [#1377](https://github.com/belav/csharpier/issues/1377)
29+
In order to get consistency between an `.editorconfig` and `.csharpierconfig` the option `TabWidth` has been renamed to `IndentSize`. This is also a more accurate name considering by default indentation is done with spaces and not tabs.
30+
### Rework the CLI to use commands and arguments. [#1321](https://github.com/belav/csharpier/issues/1321)
31+
The CLI has been reworked to use commands. This helps make it clear which arguments apply to which commands. The two common commands are below, see https://csharpier.com/docs/CLI for more details.
32+
```
33+
dotnet csharpier format .
34+
dotnet csharpier check .
35+
```
36+
### Changing the tool command to csharpier. Changing the assembly/exe to CSharpier [#1418](https://github.com/belav/csharpier/pull/1418)
37+
Prior to `1.0.0` the tool command was `dotnet-csharpier` and assembly/exe were named `dotnet_csharpier`.
38+
The tool command name was changed to just `csharpier`
39+
- Running a local tool remains the same `dotnet csharpier --version`
40+
- Running a global tool is changed to `csharpier --version`
41+
42+
The assembly/exe names have changed to just `CSharpier`
43+
44+
### Support for ignoring files via a .gitignore [#631](https://github.com/belav/csharpier/issues/631)
45+
CSharpier now works as follows when determining if a file should be ignored.
46+
47+
- .gitignore files are considered when determining if a file will be ignored. A .gitignore file at the same level as a given file will take priority over a .gitignore file above it in the directory tree.
48+
- If a .csharpierignore file is present at the same level or anywhere above the given file in the tree and it contains a pattern for a given file, that will take priority.
49+
- The patterns within .csharpierignore work the same as a .gitignore, with patterns lower in the file taking priority over patterns above
50+
- CSharpier does not currently look further up the directory tree for additional .csharpierignore files if it finds one. But it does look for .gitignore files. If there is demand this could be added later.
51+
## What's Changed
52+
### Add logging format argument and support for msbuild logs [#1517](https://github.com/belav/csharpier/pull/1517)
53+
CSharpier now supports a `--log-format` argument. By default it will log with a console format. \
54+
With `--log-format MsBuild` CSharpier will produce logs in a format that allow jumping to files in the VisualStudio error list.
55+
56+
Thanks go to @moormaster for the contribution
57+
### Allow passing an `.editorconfig` file path into `--config-path` [#1456](https://github.com/belav/csharpier/issues/1456)
58+
CSharpier now supports passing a path to an `.editorconfig` file when using the `--config-path` argument.
59+
### Always ignore any files in .git folder [#1438](https://github.com/belav/csharpier/pull/1438)
60+
CSharpier will now ignore any files that are in a `.git` folder. Previously if the `.git` folder happened to contain an invalid c# file CSharpier would attempt to format it and report an error.
61+
### Avoid excessive file system watches for --server [#1465](https://github.com/belav/csharpier/pull/1465)
62+
When CSharpier server was started, it would create file watches for all of the files within the directory the tool existed in. This can lead to some systems running out of the ability to monitor more files.
63+
64+
CSharpier server now uses a temporary empty content root to avoid creating all file watches.
65+
66+
Thanks go to @chklauser for the contribution
67+
### Smarter EditorConfig parsing [#1228](https://github.com/belav/csharpier/issues/1228)
68+
Previously CSharpier was eagerly loading all `.editorconfig` files within a directory that it was asked to format. It now lazy loads them in a way that is performant and avoids loading and parsing editorconfigs that aren't needed.
69+
### Extra blank line before local scope block in global statement [#1566](https://github.com/belav/csharpier/issues/1566)
70+
```c#
71+
// input & expected output
72+
int x = 1;
73+
74+
{
75+
int x = 2;
76+
}
77+
78+
// 0.30.6
79+
int x = 1;
80+
81+
82+
{
83+
int x = 2;
84+
}
85+
```
86+
### Inconsistent indentation for parenthesis expression [#1562](https://github.com/belav/csharpier/issues/1562)
87+
A statement being surrounded by parentheses affected the indentation in an inconsistent way.
88+
```c#
89+
// input & expected output
90+
var b2 =
91+
System.Environment.SpecialFolder.AdminTools
92+
is System.Environment.SpecialFolder.AdminTools
93+
or System.Environment.SpecialFolder.AdminTools
94+
or System.Environment.SpecialFolder.AdminTools;
95+
96+
var b2 = (
97+
System.Environment.SpecialFolder.AdminTools
98+
is System.Environment.SpecialFolder.AdminTools
99+
or System.Environment.SpecialFolder.AdminTools
100+
or System.Environment.SpecialFolder.AdminTools
101+
);
102+
103+
// 0.30.6
104+
var b2 =
105+
System.Environment.SpecialFolder.AdminTools
106+
is System.Environment.SpecialFolder.AdminTools
107+
or System.Environment.SpecialFolder.AdminTools
108+
or System.Environment.SpecialFolder.AdminTools;
109+
110+
var b2 = (
111+
System.Environment.SpecialFolder.AdminTools
112+
is System.Environment.SpecialFolder.AdminTools
113+
or System.Environment.SpecialFolder.AdminTools
114+
or System.Environment.SpecialFolder.AdminTools
115+
);
116+
117+
```
118+
### Attribute on property accessor causes unnecessary newlines in formatting [#1558](https://github.com/belav/csharpier/issues/1558)
119+
The logic around when to break properties with attributes has been adjusted. See the example for more details
120+
```c#
121+
public class ClassName
122+
{
123+
[Obsolete]
124+
public string Property { [Obsolete] get; [Obsolete] set; }
125+
126+
public int ShortProperty { get; [SomeAttribute] init; } = 20;
127+
128+
public int CommandTimeout
129+
{
130+
get;
131+
[SomeAttribute]
132+
[SomeOtherAttribute]
133+
set;
134+
}
135+
136+
public int CommandTimeout
137+
{
138+
[SomeAttribute(someValue)]
139+
get;
140+
}
141+
}
142+
```
143+
### Fluent multiline with comment re-formats incorrectly. [#1556](https://github.com/belav/csharpier/issues/1556)
144+
When a single method in a fluent chain was commented out, csharpier would try to collapse the chain to a single line.
145+
```c#
146+
// input & expected output
147+
builder
148+
.CallMethod()
149+
.CallMethod()
150+
.CallMethod()
151+
//.CallMethod()
152+
;
153+
154+
// 0.30.6
155+
builder.CallMethod().CallMethod().CallMethod()
156+
//.CallMethod()
157+
;
158+
159+
```
160+
### Comments on an invocation chain that began with a generic where breaking when they should not [#1555](https://github.com/belav/csharpier/issues/1555)
161+
In some cases CSharpier was breaking an invocation chain when it should not.
162+
```c#
163+
// input & expected output
164+
165+
// CommentOnGenericDoesNotBreakChain
166+
SomeObject<SomeThing>.SomeProperty.SomeOtherProperty = 1;
167+
168+
// CommentOnGenericDoesNotBreakChain
169+
SomeObject<SomeThing>.SomeProperty.CallMethod();
170+
171+
// 0.30.6
172+
173+
// CommentOnGenericDoesNotBreakChain
174+
SomeObject<SomeThing>
175+
.SomeProperty
176+
.SomeOtherProperty = 1;
177+
178+
// CommentOnGenericDoesNotBreakChain
179+
SomeObject<SomeThing>.SomeProperty.CallMethod();
180+
181+
```
182+
### Comment in line before attribute causes unexpected line break after attribute [#1553](https://github.com/belav/csharpier/issues/1553)
183+
CSharpier was breaking and indenting a parameter when it had a comment
184+
```c#
185+
// input & expected output
186+
public void SomeMethod(
187+
// Some Comment does not indent parameter
188+
[SomeAttribute] string someParameter
189+
) { }
190+
191+
// 0.30.6
192+
public void SomeMethod(
193+
// Some Comment does not indent parameter
194+
[SomeAttribute]
195+
string someParameter
196+
) { }
197+
```
198+
### Huge oneliner with switch expression followed my method invocations [#1546](https://github.com/belav/csharpier/issues/1546)
199+
CSharpier was keeping a method chain on a single line if it was invoked on a switch expression within parentheses.
200+
```c#
201+
// input & expected output
202+
(
203+
someValue switch
204+
{
205+
someValue => 1,
206+
_ => 2,
207+
}
208+
)
209+
.SomeLongMethodCall______________________________()
210+
.SomeLongMethodCall______________________________()
211+
.SomeLongMethodCall______________________________();
212+
213+
// 0.30.6
214+
(
215+
someValue switch
216+
{
217+
someValue => 1,
218+
_ => 2,
219+
}
220+
).SomeLongMethodCall______________________________().SomeLongMethodCall______________________________().SomeLongMethodCall______________________________();
221+
222+
```
223+
### Inconsistent Formatting of Single Parameter Lambda Expressions [#1522](https://github.com/belav/csharpier/issues/1522)
224+
CSharpier was not formatting all lambda expressions consistently when they were the single argument to a method call.
225+
```c#
226+
// input & expected output
227+
CallMethod(() =>
228+
CallOtherMethod___________________________________________________________()
229+
);
230+
231+
CallMethod(() =>
232+
CallLongMethod_________________________________()
233+
.ThenAnotherMethod_____________________________________()
234+
);
235+
236+
// 0.30.6
237+
CallMethod(() =>
238+
CallOtherMethod___________________________________________________________()
239+
);
240+
241+
CallMethod(
242+
() =>
243+
CallLongMethod_________________________________()
244+
.ThenAnotherMethod_____________________________________()
245+
);
246+
```
247+
248+
### Empty lines after XmlComments should be removed [#1521](https://github.com/belav/csharpier/issues/1521)
249+
When a member has documentation comments, any empty lines after those comments and before the member are now removed.
250+
```c#
251+
// input
252+
/// <summary>Remove the lines after the summary</summary>
253+
254+
public bool SomeField1;
255+
256+
// output
257+
/// <summary>Remove the lines after the summary</summary>
258+
public bool SomeField1;
259+
```
260+
### CSharpier always includes indentation whitespace on non-content lines [#1455](https://github.com/belav/csharpier/issues/1455)
261+
CSharpier was indenting the final non-content line within a raw string. It now leaves them dedented to keep it consistent with other non-content lines.
262+
```c#
263+
MakeSureBothNonContentLinesHereStayTrimmed(
264+
$"""
265+
266+
267+
"""
268+
);
269+
```
270+
271+
**Full Changelog**: https://github.com/belav/csharpier/compare/1.0.0...1.0.0
272+
# 0.30.6
2273
## What's Changed
3274
### Trailing comma is placed on new line if last enum value is followed by a comment [#1429](https://github.com/belav/csharpier/issues/1429)
4275
```c#
@@ -2920,5 +3191,6 @@ Thanks go to @pingzing
29203191
29213192
29223193
3194+
29233195
29243196

Nuget/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.30.6</Version>
3+
<Version>1.0.0</Version>
44
<PackageLicenseExpression>MIT</PackageLicenseExpression>
55
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
66
<RepositoryType>git</RepositoryType>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![CSharpier](./banner.svg)
22

3-
CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.
3+
CSharpier is an opinionated code formatter for c# and XML. It parses your code and re-prints it using its own rules.
44
The printing process was ported from [prettier](https://github.com/prettier/prettier) but has evolved over time.
55

66
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.

Shell/Release.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function CSH-Release {
2929
{
3030
Copy-Item $file.FullName ($PSScriptRoot + "/../Src/Website/docs/" + $file.Name)
3131
}
32+
33+
& dotnet csharpier format .
3234
}
3335

3436
Export-ModuleMember -Function CSH-*

Src/CSharpier.Rider/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fun properties(key: String) = project.findProperty(key).toString()
66
plugins {
77
id("java")
88
id("org.jetbrains.kotlin.jvm") version "1.9.21"
9-
id("org.jetbrains.intellij.platform") version "2.2.0"
9+
id("org.jetbrains.intellij.platform") version "2.2.1"
1010
id("org.jetbrains.changelog") version "2.2.0"
1111
id("org.jetbrains.qodana") version "0.1.13"
1212
id("com.jetbrains.rdgen") version "2024.3.1"

Src/CSharpier.Rider/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginVersion = 2.1.2
44
pluginSinceBuild = 222
55
pluginUntilBuild = 253.*
66

7-
platformVersion = 2024.3
7+
platformVersion = 2024.3.4
88

99
gradleVersion = 8.5
1010

Src/CSharpier.Tests/CSharp/SyntaxNodeComparerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using CSharpier.Core;
21
using CSharpier.Core.CSharp;
32
using FluentAssertions;
43
using Microsoft.CodeAnalysis;
@@ -18,6 +17,7 @@ public void Class_Not_Equal_Namespace()
1817

1918
var result = CompareSource(left, right);
2019

20+
// wtf
2121
ResultShouldBe(
2222
result,
2323
"""
@@ -586,7 +586,7 @@ public void Usings_With_Directives_Pass_Validation(string content)
586586
using System.IO;
587587
588588
{content}
589-
589+
590590
""";
591591

592592
var right = $"""
@@ -596,7 +596,7 @@ public void Usings_With_Directives_Pass_Validation(string content)
596596
#endif
597597
598598
{content}
599-
599+
600600
""";
601601

602602
var result = CompareSource(left, right, reorderedUsingsWithDisabledText: true);

0 commit comments

Comments
 (0)