CSharpier is an opinionated code formatter for c#.
dotnet csharpier
fails when subdirectory is inaccessible #1240When running the following CSharpier would look for config files in subdirectories of the pwd
. This could lead to exceptions if some of those directories were inaccessible.
echo "namespace Foo { public class Bar { public string Baz {get;set;}}}" | dotnet csharpier
Thanks go to @jamesfoster for reporting the issue.
Full Changelog: https://github.com/belav/csharpier/compare/0.28.1...0.28.2
When CSharpier encountered an invalid .editorconfig
file, it would throw an exception and not format files. These files could appear in 3rd party code (for example within node_modules). CSharpier now ignores invalid lines in .editorconfigs
Thanks go to @K0Te for reporting the issue
Full Changelog: https://github.com/belav/csharpier/compare/0.28.0...0.28.1
In some cases of method chains, the first invocation would end up dedented.
// 0.27.3
o.Property.CallMethod(
someParameter_____________________________,
someParameter_____________________________
)
.CallMethod()
.CallMethod();
// 0.28.0
o.Property.CallMethod(
someParameter_____________________________,
someParameter_____________________________
)
.CallMethod()
.CallMethod();
If a case statement started with a block it would get an extra new line
// 0.27.3
switch (someValue)
{
case 0:
{
// dedented because the only statement is a block
break;
}
case 1:
{
// indented because there are two statements, a block then a break
}
break;
}
// 0.28.0
// 0.27.3
switch (someValue)
{
case 0:
{
// dedented because the only statement is a block
break;
}
case 1:
{
// indented because there are two statements, a block then a break
}
break;
}
Thanks go to @emberTrev for reporting the bug.
The editorconfig parsing was not handling glob patterns that contained braces.
# worked in 0.27.3
[*.cs]
indent_size = 4
tab_width = 4
# did not work in 0.27.3
[*.{cs,csx}]
indent_size = 4
tab_width = 4
# did not work in 0.27.3
[*.{cs}]
indent_size = 4
tab_width = 4
Thanks go to @kada-v for reporting the bug
The following code would throw an exception, it is now working as expected.
class ClassName
{
#region Region
// csharpier-ignore-start
public string Field;
// csharpier-ignore-end
#endregion
}
Thanks go to @davidescapolan01 for reporting the bug
On some OSs the following would cause an exception.
dotnet new console -n foo
cd foo
dotnet new editorconfig
dotnet csharpier ./
Thanks go to @hashitaku for contributing the fix.
CodeFormatterOptions.IncludeGenerated
is now available for the SDK.
Improved the http server that CSharpier will soon use to facilitate formatting by plugins. The formatting request now returns errors and a status for each file formatted. This allows the plugin to provide more information to the user when they attempt to format a file. The plugins will be updated to use the http server option for CSharpier 0.28.0+
Full Changelog: https://github.com/belav/csharpier/compare/0.27.3...0.28.0
PATH
Better support for dotnet commands.
The API for CSharpier was only exposing CodeFormatterOptions.PrintWidth
. It is now in sync with the CLI and exposes all of the available options
public class CodeFormatterOptions
{
public int Width { get; init; } = 100;
public IndentStyle IndentStyle { get; init; } = IndentStyle.Spaces;
public int IndentSize { get; init; } = 4;
public EndOfLine EndOfLine { get; init; } = EndOfLine.Auto;
}
Thanks go to @Phault for the contribution
When a raw string literal was the first argument to a method call, it was getting an extra indent.
// input & expected output
CallMethod(
"""
SomeRawString
""".CallMethod()
);
// 0.27.2
CallMethod(
"""
SomeRawString
""".CallMethod()
);
Thanks go to @Rudomitori for reporting the bug.
Using aliases were not sorting properly, resulting differing outputs and unstable formatting.
Inputs of
using A = string;
using B = string;
using C = string;
using D = string;
And
using D = string;
using C = string;
using B = string;
using A = string;
Now always result in properly sorted output of
using A = string;
using B = string;
using C = string;
using D = string;
Thanks go to @Araxor for reporting the bug.
The spread element was unformatted, and left as is. It is now formatted as follows.
int[] someArray = [.. someOtherArray];
int[] someOtherArray = [.. value1, .. value2, .. value3];
int[] someOtherArray =
[
.. value1________________________________,
.. value2________________________________,
.. value3________________________________
];
Thanks go to @jods4 for reporting the bug.
A collection expression in an attribute resulted in an extra line before the collection expression.
// input & expected output
[SomeAttribute(
[
someValue_______________________________________________,
someValue_______________________________________________,
]
)]
class ClassName { }
// 0.27.2
[SomeAttribute(
[
someValue_______________________________________________,
someValue_______________________________________________,
]
)]
class ClassName { }
Thanks go to @Rudomitori for reporting the bug.
Static usings were not following the rule that System.*
should be sorted to the top.
// input & expected output
using static System;
using static System.Web;
using static AWord;
using static ZWord;
// 0.27.2
using static AWord;
using static System;
using static System.Web;
using static ZWord;
When .net8
support was added, CSharpier started including a commit hash in the version number output. This was due to a breaking change in the sdk.
> dotnet csharpier --version
0.27.2+b456544aad8957d0e2026afe1a37544bb74552ba
CSharpier no longer includes the commit hash
> dotnet csharpier --version
0.27.3
This adds better support for dotnet commands by
dotnet.dotnetPath
if it existsomnisharp.dotNetCliPaths
if it existsdotnet
on the PATH by running dotnet --info
dotnet
on the PATH by running sh -c "dotnet --info"
0.27.1 introduced the following formatting regression, resulting in short variables being orphaned on a line
// 0.27.1
o
.Property.CallMethod(
someParameter_____________________________,
someParameter_____________________________
)
.CallMethod()
.CallMethod();
// 0.27.2
o.Property.CallMethod(
someParameter_____________________________,
someParameter_____________________________
)
.CallMethod()
.CallMethod();
Thanks go to @aurnoi1 for reporting the bug
Version 0.27.1 parsed .csx
files as if they were C#, so it could only format simple ones. It now parses them as CSharpScript files so it can format them properly.
Thanks go to @Eptagone for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.27.1...0.27.2