Skip to content

Releases: belav/csharpier

0.27.3

18 Feb 16:34
7dc9d84
Compare
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

vscode-1.5.3-beta1

12 Feb 03:38
Compare
Choose a tag to compare
vscode-1.5.3-beta1 Pre-release
Pre-release

This adds better support for dotnet commands by

  1. Using the option for dotnet.dotnetPath if it exists
  2. Using the option for omnisharp.dotNetCliPaths if it exists
  3. Trying to find dotnet on the PATH by running dotnet --info
  4. Trying to find dotnet on the PATH by running sh -c "dotnet --info"

0.27.2

28 Jan 19:05
b456544
Compare
Choose a tag to compare

What's Changed

Orphan variable since 0.27.1 #1153

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

Better support for CSharp Script #1141

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: 0.27.1...0.27.2

0.27.1

24 Jan 02:15
2254d2d
Compare
Choose a tag to compare

What's Changed

Support for CSharp Script #1141

Previously CSharpier would only format files matching *.cs which prevented it from formatting C# script files. It now formats *.{cs,csx}

Thanks go to @Eptagone for the suggestion

Weird formatting of invocation chain #1130

Invocation chains that started with an identifier <= 4 characters were causing a strange break in the first method call. There were other edge cases cleaned up while working on the fix.

// 0.27.0
var something________________________________________ = x.SomeProperty.CallMethod(
    longParameter_____________,
    longParameter_____________
)
    .CallMethod();

// 0.27.1
var something________________________________________ = x
    .SomeProperty.CallMethod(longParameter_____________, longParameter_____________)
    .CallMethod();
// 0.27.0
var someLongValue_________________ = memberAccessExpression[
    elementAccessExpression
].theMember______________________________();

// 0.27.1
var someLongValue_________________ = memberAccessExpression[elementAccessExpression]
    .theMember______________________________();
// 0.27.0
someThing_______________________
    ?.Property
    .CallMethod__________________()
    .CallMethod__________________();

// 0.27.1
someThing_______________________
    ?.Property.CallMethod__________________()
    .CallMethod__________________();

Thanks go to @Rudomitori for reporting the issue

"Failed syntax tree validation" for raw string literals #1129

When an interpolated raw string changed indentation due to CSharpier formatting, CSharpier was incorrectly reporting it as failing syntax tree validation.

// input
CallMethod(CallMethod(
   $$"""
   SomeString
   """, someValue));

// output
CallMethod(
    CallMethod(
        $$"""
        SomeString
        """,
        someValue
    )
);

Thanks go to @Rudomitori for reporting the issue

Adding experimental support using HTTP for the extensions to communicate with CSharpier #1137

The GRPC support added in 0.27.0 increased the size of the nuget package significantly and has been removed.

CSharpier can now start a kestrel web server to support communication with the extensions once they are all updated.

Full Changelog: 0.27.0...0.27.1

0.27.0

15 Jan 18:15
7d09173
Compare
Choose a tag to compare

What's Changed

Improve formatting of lambda expressions #1066

Many thanks go to @Rudomitori for contributing a number of improvements to the formatting of lambda expressions.

Some examples of the improvements.

// input
var affectedRows = await _dbContext.SomeEntities
    .ExecuteUpdateAsync(
        x => 
            x.SetProperty(x => x.Name, x => command.NewName)
                .SetProperty(x => x.Title, x => command.NewTItle)
                .SetProperty(x => x.Count, x => x.Command.NewCount)
    );

// 0.27.0
var affectedRows = await _dbContext.SomeEntities
    .ExecuteUpdateAsync(x =>
        x.SetProperty(x => x.Name, x => command.NewName)
            .SetProperty(x => x.Title, x => command.NewTItle)
            .SetProperty(x => x.Count, x => x.Command.NewCount)
    );
// input
builder.Entity<IdentityUserToken<string>>(b =>
{
    b.HasKey(
        l =>
            new
            {
                l.UserId,
                l.LoginProvider,
                l.Name
            }
    );
    b.ToTable("AspNetUserTokens");
});

// 0.27.0
builder.Entity<IdentityUserToken<string>>(b =>
{
    b.HasKey(l => new
    {
        l.UserId,
        l.LoginProvider,
        l.Name
    });
    b.ToTable("AspNetUserTokens");
});
// input
table.PrimaryKey(
    "PK_AspNetUserTokens",
    x =>
        new
        {
            x.UserId,
            x.LoginProvider,
            x.Name
        }
);

// 0.27.0
table.PrimaryKey(
    "PK_AspNetUserTokens",
    x => new
    {
        x.UserId,
        x.LoginProvider,
        x.Name
    }
);

readonly ref is changed to ref readonly causing error CS9190 #1123

CSharpier was sorting modifiers in all places they occurred. Resulting the following change that led to code that would not compile.

// input
void Method(ref readonly int someParameter) { }

// 0.26.7
void Method(readonly ref int someParameter) { }

// 0.27.0
void Method(ref readonly int someParameter) { }

Thanks go to @aurnoi1 for reporting the bug

#if at the end of collection expression gets eaten #1119

When a collection expression contained a directive immediately before the closing bracket, that directive was not included in the output.

// input
int[] someArray =
[
    1
#if DEBUG
    ,
    2
#endif
];

// 0.26.7
int[] someArray = [1];

// 0.27.0
int[] someArray =
[
    1
#if DEBUG
    ,
    2
#endif
];

Thanks go to @Meowtimer for reporting the bug

CSharpier.MsBuild - Set Fallback for dotnetcore3.1 or net5.0 applications #1111

CSharpier.MsBuild made an assumption that the project being built would be built using net6-net8 and failed when the project was built with earlier versions of dotnet.

It now falls back to trying to use net8

Thanks go to @samtrion for the contribution

Allow empty/blank lines in object initializers #1110

Large object initializers now retain single empty lines between initializers.

vvar someObject = new SomeObject
{
    NoLineAllowedAboveHere = 1,

    ThisLineIsOkay = 2,

    // comment
    AndThisLine = 3,
    DontAddLines = 4,
};

Thanks go to @Qtax for the suggestion

Add option to allow formatting auto generated files. [#1055](#1055

By default CSharpier will not format files that were generated by the SDK, or files that begin with <autogenerated /> comments.

Passing the option --include-generated to the CLI will cause those files to be formatted.

Format raw string literals indentation #975

CSharpier now adjusts the indentation of raw string literals if the end delimiter is indented.

// input
var someString = """
            Indent based on previous line
            """;

var doNotIndentIfEndDelimiterIsAtZero = """
Keep This
    Where It
Is
""";

// 0.26.7
var someString = """
            Indent based on previous line
            """;

var doNotIndentIfEndDelimiterIsAtZero = """
Keep This
    Where It
Is
""";

// 0.27.0
var someString = """
    Indent based on previous line
    """;

var doNotIndentIfEndDelimiterIsAtZero = """
Keep This
    Where It
Is
""";

Thanks go to @jods4 for reporting the issue

Incorrect indentation on a multi-line statement split by comments [#968](#968

CSharpier was not properly indenting an invocation chain when it was being split by comments.

// input
var someValue =
    // Some Comment
    CallSomeMethod()
        // Another Comment
        .CallSomeMethod();

// 0.26.7
var someValue =
// Some Comment
CallSomeMethod()
    // Another Comment
    .CallSomeMethod();

// 0.27.0
var someValue =
    // Some Comment
    CallSomeMethod()
        // Another Comment
        .CallSomeMethod();

Thanks go to @Tyrrrz for reporting the issue

Adding experimental support for GRPC for the extensions to communicate with CSharpier #944

Currently the extensions for CSharpier send data to a running instance of CSharpier by piping stdin/stdout back and forth. This approach has proved problematic and hard to extend.

As of 0.27.0, CSharpier can run a GRPC server to allow communication with the extensions once they are all updated.

Full Changelog: 0.26.7...0.27.0

0.26.7

16 Dec 21:27
c8aec14
Compare
Choose a tag to compare

What's Changed

Keep Field.Method() on the same line when breaking long method chain #1010

0.26.0 introduced changes that broke long invocation chains on fields/properties as well as methods. That change has been reverted after community feedback.

// 0.26.0
var loggerConfiguration = new LoggerConfiguration()
    .Enrich
    .FromLogContext()
    .Enrich
    .WithProperty("key", "value")
    .Enrich
    .WithProperty("key", "value")
    .Enrich
    .WithProperty("key", "value")
    .Enrich
    .WithProperty("key", "value")
    .WriteTo
    .Console(outputTemplate: "template");

// 0.26.7
var loggerConfiguration = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .Enrich.WithProperty("key", "value")
    .Enrich.WithProperty("key", "value")
    .Enrich.WithProperty("key", "value")
    .Enrich.WithProperty("key", "value")
    .WriteTo.Console(outputTemplate: "template");

Full Changelog: 0.26.6...0.26.7

0.26.6

14 Dec 03:04
3b738ad
Compare
Choose a tag to compare

What's Changed

CSharpier incorrectly reports problems with differing line endings as "The file did not end with a single newline"#1067

If CSharpier was validating that a file was formatted, and that file contained only \n but CSharpier was configured to use \r\n, then it would report the problem as The file did not end with a single newline

CSharpier added support for reading line ending configuration from an .editorconfig which could contain end_of_line = crlf so some users were unknowingly configuring CSharpier to use \r\n

CSharpier now correctly reports the problem as The file contained different line endings than formatting it would result in.

Full Changelog: 0.26.5...0.26.6

0.26.5

10 Dec 18:32
Compare
Choose a tag to compare

What's Changed

0.26.4 sorts NSubstitute before Newtonsoft.Json #1061

The using sorting in 0.26.4 was taking into account case.

// 0.26.4
using System;
using NSubstitute;
using Newtonsoft.Json;

// 0.26.5
using System;
using Newtonsoft.Json;
using NSubstitute;

Thanks go to @loraderon for contributing the fix.

Extra newline added when using a collection expression with { get; } #1063

A collection expression in a property initializer was including an extra new line.

// 0.26.4
public class ClassName
{
    public List<DayOfWeek> DaysOfWeek { get; } =

        [
            DayOfWeek.Sunday,
            // snip
            DayOfWeek.Saturday
        ];    
}

// 0.26.5
public class ClassName
{
    public List<DayOfWeek> DaysOfWeek { get; } =
        [
            DayOfWeek.Sunday,
            // snip
            DayOfWeek.Saturday
        ];    
}

Thanks go to @SapiensAnatis for contributing the fix.

Comments at the end of a collection expression should be indented #1059

When the close bracket on a collection expression had a leading comment, it had the same indentation as the bracket.

// 0.26.4
host.AddSection(
    name: "Kontakt Libraries (Third Party)",
    tags: Tags.SamplesUsed,
    tasks:
    [
    // TODO: Add any used third party instruments below as you discover them.
    ]
);

// 0.26.5
host.AddSection(
    name: "Kontakt Libraries (Third Party)",
    tags: Tags.SamplesUsed,
    tasks:
    [
        // TODO: Add any used third party instruments below as you discover them.
    ]
);

Thanks go to @fgimian for reporting the problem

Full Changelog: 0.26.4...0.26.5

0.26.4

02 Dec 17:10
133f698
Compare
Choose a tag to compare

What's Changed

Spacing bugs related to C#12 collection expressions #1049 #1047

There were a number of cases where CSharpier was including extra blank lines, an extra space, or not formatting contents of collection expressions.

// 0.26.3
var a = new A { B =  [1, 2, 3] };

List<string> items = [// My item
    "Hello",];

items.AddRange(

    [
        LongValue________________________________________________,
        LongValue________________________________________________
    ]
);

items =  [];
items ??=  [];

class SomeClass
{
    public SomeValue SomeProperty =>

        [
            LongValue________________________________________________,
            LongValue________________________________________________
        ];

    public SomeValue Method() =>

        [
            LongValue________________________________________________,
            LongValue________________________________________________
        ];
}

// 0.26.4
var a = new A { B = [1, 2, 3] };

List<string> items =
[
    // My item
    "Hello",
];

items.AddRange(
    [
        LongValue________________________________________________,
        LongValue________________________________________________
    ]
);

items = [];
items ??= [];

class SomeClass
{
    public SomeValue SomeProperty =>
        [
            LongValue________________________________________________,
            LongValue________________________________________________
        ];

    public SomeValue Method() =>
        [
            LongValue________________________________________________,
            LongValue________________________________________________
        ];
}

Thanks go to @fgimian and @JoshWoodArup for reporting the issues

Usings sorting differs based on system culture #1051

The sorting of Usings was done in a culture specific manner, resulting in unexpected behavior.
In Czech (cs-CZ) the ch is a "single letter" which is placed between h and i, which resulted in the following sorting behavior.

// 0.26.3
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Channel;

// 0.26.4
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;

Thanks go to @davidkudera for the contribution

0.26.3

23 Nov 20:25
6bcc339
Compare
Choose a tag to compare

What's Changed

C#12 Collection expressions are prefixed with two spaces #1009

// 0.26.0
List<int> ids =  [];

// 0.26.3
List<int> ids = [];

Thanks go to @Jackenmen for reporting the problem.

CSharpier inserts extra spaces around the contents of collection expressions #1002

// 0.26.0
List<int> ids = [ ];
List<int> ids = [ 1, 2, 3 ];

// 0.26.3
List<int> ids = [];
List<int> ids = [1, 2, 3];

Thanks go to @golavr for reporting the problem.

Configuration files not respected for stdin #1028

When piping a file to csharpier via stdin, CSharpier uses the working directory to locate any configuration files. This was broken with 0.26.0.

Thanks go to @kikniknik for reporting the problem.

Modify CSharpier.MSBuild to use NETCoreSdkVersion to detect which sdk to use for running CSharpier #1022 #1027

Previously CSharpier.MSBuild was using targetFramework to determine which version of CSharpier to run. This was problematic when there were multiple target frameworks, or the project was targeting a superset such as net8.0-windows

It now makes use of NETCoreSdkVersion to determine which version of CSharpier to run.

Thanks go to @Tyrrrz for the suggestion and to @Cjewett for the contribution to make it work

CSharpierIgnore not respected when recursively finding .editorconfig

When looking for .editorconfig files, CSharpier looks for them recursively in the current directory. This logic was not taking into account any files or directories ignored by a .csharpierignore.

Thanks go to @sebastieng84 for the contribution.

Optimize editorconfig lookups when piping files #1039

CSharpier now only looks for an .editorconfig for the file being piped to CSharpier. Under normal usage it recursively looks for all possible .editorconfig files for the given directory.

Full Changelog: 0.26.2...0.26.3