Skip to content

Releases: belav/csharpier

0.29.1

23 Aug 15:31
b87b4df

Choose a tag to compare

What's Changed

Sorting of usings with underscore differs from Visual Studio #1327

CSharpier now sorts _ to the bottom of usings.

using SomeCompany.MWord;
using SomeCompany.ZWord;
using SomeCompany._Word;

Process cannot access the file "....net8.0\any\server.log" while running multiple extensions. #1324

CSharpier Server now uses a log file name based on the port that it is starting on to avoid concurrency issues trying to access the same log file

Full Changelog: 0.29.0...0.29.1

0.29.0

17 Aug 18:17
5d73fe3

Choose a tag to compare

Breaking Changes

The formatting command will now exit with an error code of 1 if one of the target files cannot be compiled #1131

Prior to 0.29.0 if csharpier encountered a file that could not be compiled it would treat it as a warning and exit with a code of 0.
As of 0.29.0 a file that cannot be compiled is now treated as an error and csharpier will exit with code 1

What's Changed

Enforce trailing commas in object and collection initializer #668

CSharpier will now add trailing commas automatically where appropriate. It will collapse to a single line and remove the trailing comma in cases where everything fits on one line.

// input
public enum SomeEnum
{
    Value1,
    Value2
}

string[] someArray = new string[]
{
    someLongValue_____________________________________________,
    someLongValue_____________________________________________
};

string[] someArray = new string[]
{
    someValue,
    someValue,
};

// 0.29.0
public enum SomeEnum
{
    Value1,
    Value2,
}

string[] someArray = new string[]
{
    someLongValue_____________________________________________,
    someLongValue_____________________________________________,
}

string[] someArray = new string[] { someValue, someValue };

Many thanks go to @dawust for the contribution.

Support for formatting custom file extensions #1220

Prior to 0.29.0 csharpier would only format files with an extension of .cs or .csx. It is now possible to configure csharpier to format other files extensions, and to specify configuration options per file extension.
See https://csharpier.com/docs/Configuration#configuration-overrides for more details.

Invalid blank line being added with lambda returning collection expression #1306

// input & expected output
CallMethod(_ =>
    [
        LongValue________________________________________________,
        LongValue________________________________________________,
    ]
);

// 0.28.2
CallMethod(_ =>

    [
        LongValue________________________________________________,
        LongValue________________________________________________,
    ]
);

Switch expressions do not break consistently with other lambdas #1282

Prior to 0.29.0 csharpier would break before the => in switch expression arms. It now breaks after them to be consistent with other lambda expressions.

// 0.28.2
return someEnum switch
{
    Value1 => someOtherValue,
    Value2
    or Value3
        => someValue________________________________________________________________________,
    Value4
        => someValue_____________________________________________________________________________,
};

// 0.29.0
return someEnum switch
{
    Value1 => someOtherValue,
    Value2 or Value3 =>
        someValue________________________________________________________________________,
    Value4 =>
        someValue_____________________________________________________________________________,
};

Formatting of empty collection initializer for huge type #1268

Empty collection expression initializers formatting was including a break plus indentation resulting in poor formatting.

// 0.28.2
var someObject = new List<(
    int Field1__________________________________,
    int Field2__________________________________
)>
{
    };

// 0.29.0
var someObject = new List<(
    int Field1__________________________________,
    int Field2__________________________________
)>
{ };

Thanks go to @Rudomitori for the contribution

Switch expression single line broken when preceded by comment #1262

Improved formatting for short expression arms that have a leading comment.

// 0.28.2
return someValue switch
{
    // comment
    Some.One
        => 1,
    Some.Two => 2,
};

return someValue switch
{
    Some.One => 1,
    // comment
    Some.Two
        => 2,
};

// 0.29.0
return someValue switch
{
    // comment
    Some.One => 1,
    Some.Two => 2,
};

return someValue switch
{
    Some.One => 1,
    // comment
    Some.Two => 2,
};

Incorrect formatting of ternary expression with a comment after an interpolated string #1258

Fixed bug with comments on a ternary expression that resulted in invalid code.

// input & expected output
public string TrailingComment = someCondition
    ? $"empty" // trailing comment
    : someString;

// 0.28.2
public string TrailingComment = someCondition ? $"empty" // trailing comment : someString;

Formatting for indexer parameters should mostly be the same as for method parameters. #1255

Improved formatting of indexed properties that contained attributes.

// input & expected output
public class ClassName
{
    public string this[
        [SomeAttribute] int a________________________________,
        [SomeAttribute] int b________________________________
    ] => someValue;
}

// 0.28.2
public class ClassName
{
    public string this[[SomeAttribute] int a________________________________, [SomeAttribute]
        int b________________________________] => someValue;
}

Do not overwrite CSharpier_Check when already set. #1314

Fixed a bug with csharpier.msbuild where it would overwrite the CSharpier_Check value in some cases.

Thanks go to @PetSerAl for the contribution

The CLI has contradictory message about directoryOrFile being required #1296

The help text for the cli has been improved to better indicate when directoryOrFile is required.

Thanks go to @marcinjahn for the contribution

Fullwidth unicode characters should be accounted for in print width #260

CSharpier now considers full width unicode characters such as to be 2 spaces wide when determining how to format code.

Full Changelog: 0.28.2...0.29.0

0.28.2

26 Apr 16:39
3e4366c

Choose a tag to compare

What's Changed

Pipe to dotnet csharpier fails when subdirectory is inaccessible #1240

When 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: 0.28.1...0.28.2

Rider 1.7.1

19 Apr 14:59
4282d01

Choose a tag to compare

[1.7.1]

  • Fix unicode issue with csharpier 0.28.0+

0.28.1

16 Apr 23:12
5244417

Choose a tag to compare

What's Changed

Third party .editorconfig leading to: Error Failure parsing editorconfig files #1227

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: 0.28.0...0.28.1

0.28.0

07 Apr 22:22
d754703

Choose a tag to compare

What's Changed

Fix dedented method call if there is a long chain #1154

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();

Extra newline in switch case statement with curly braces [#1192](#1192

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.

Handle more editorconfig glob patterns. #1214

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

Ignore-start combined with regions throws exception #1197

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

Cannot format project containing editorconfig #1194

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.

Expose IncludeGenerated in CodeFormatterOptions #1215

CodeFormatterOptions.IncludeGenerated is now available for the SDK.

Returning errors + status from csharpier http server #1191

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: 0.27.3...0.28.0

Rider 1.6.2-beta

08 Mar 20:37

Choose a tag to compare

Rider 1.6.2-beta Pre-release
Pre-release
  • Fix issues with lookup of '.NET CLI executable path', csharpier will now wait until rider is ready with the information.
  • No more falling back to PATH

Rider 1.6.1-beta

01 Mar 18:12

Choose a tag to compare

Rider 1.6.1-beta Pre-release
Pre-release
  • Delay lookup of '.NET CLI executable path' until it is needed
  • Fall back to looking for dotnet on PATH if '.NET CLI executable path' is not available

Rider 1.6.0-beta

24 Feb 17:01

Choose a tag to compare

Rider 1.6.0-beta Pre-release
Pre-release

Better support for dotnet commands.

  • Uses the Rider setting for '.NET CLI executable path' for running dotnet commands
  • If unable to run dotnet commands, show an error message

0.27.3

18 Feb 16:34
7dc9d84

Choose a tag to compare

What's Changed

Add more options to CodeFormatterOptions #1172

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

Extra indent when call method on RawStringLiteral #1169

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 sorting is not always the same depending on the input order #1168

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.

Spread (in collection expression) are not formatted #1167

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.

Fix empty line before collection expression in attribute #1164

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.

using static System.* usings not ordered before other static usings like using System.* ones #1162

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;

Remove hash from version #1144

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