From 62c94e5b931bf73bfb193df84982c482a6268b61 Mon Sep 17 00:00:00 2001 From: "bela.vandervoort" Date: Mon, 6 Nov 2023 17:00:06 -0600 Subject: [PATCH] releasing 0.26.0 --- CHANGELOG.md | 213 +++++++++++++++++++++- Nuget/Build.props | 2 +- Src/Website/docs/Configuration.md | 47 ++++- Src/Website/docs/ContinuousIntegration.md | 4 +- 4 files changed, 254 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 578b48ec6..5adddc9d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,214 @@ -# 0.25.0 +# 0.26.0 +## What's Changed +#### Net8 Support +CSharpier now supports the .net8 sdk. It still supports net6 and net7. + +#### Sorting of using directives [#661](https://github.com/belav/csharpier/issues/661) +CSharpier now sorts using statements. It follows the following rules +```c# +global using System.Linq; // sort global first +using System; // sort anything in System +using NonSystem; // sort anything non-system +using static Static; // sort static +using Alias = Z; // sort alias +using SomeAlias = A; +#if DEBUG // finally any usings in #if's +using Z; // contents are not sorted as of now +using A; +#endif +``` +#### Remove line before the content of a bracketless if/else statement [#979](https://github.com/belav/csharpier/issues/979) +```c# +// input +if (true) + + CallMethod(); +else if (false) + + CallMethod(); +else + + CallMethod(); + +for (; ; ) + + CallMethod(); + +while (true) + + CallMethod(); + +// 0.26.0 +if (true) + CallMethod(); +else if (false) + CallMethod(); +else + CallMethod(); + +for (; ; ) + CallMethod(); + +while (true) + CallMethod(); +``` + +Thanks go to @Infinite-3D for reporting +#### Support C# 12 primary constructors on structs [#969](https://github.com/belav/csharpier/issues/969) +CSharpier now supports primary constructors on structs +```c# +public struct NamedItem2( + string name1, + string name2 +) +{ + public string Name1 => name1; + public string Name2 => name1; +} +``` +#### Support C# 12 collection expressions [#964](https://github.com/belav/csharpier/issues/964 +CSharpier now supports collection expressions +```c# +int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8 ]; + +Span b = [ 'a', 'b', 'c', 'd', 'e', 'f', 'h', 'i' ]; + +string[] c = +[ + "________________________", + "________________________", + "________________________", + "________________________" +]; + +int[][] d = +[ + [1, 2, 3], + [4, 5, 6], + [7, 8, 9] +]; +``` + +Thanks go to @meenzen for reporting +#### MSBuild - when a file fails to compile csharpier interferes with getting you clickable links to the compilation errors. [#957](https://github.com/belav/csharpier/issues/957) +Build errors will now display properly when using CSharpier.MSBuild +#### Format element access properly in long invocation chains [#956](https://github.com/belav/csharpier/issues/956) +```c# +// 0.25.0 +var x = someLongNameField.CallMethod____________________________________().AccessArray[ + 1 +].Property_______________; + +// 0.26.0 +var x = someLongNameField + .CallMethod____________________________________() + .AccessArray[1] + .Property_______________; +``` +#### Improvements to visible whitespace in console output. [#953](https://github.com/belav/csharpier/issues/953) +When using `cshapier --check` whitespace is now only visible in the following situations + +When an otherwise empty line contains whitespace +``` +----------------------------- Expected: Around Line 4 ----------------------------- + private string field1; + + private string field2; +----------------------------- Actual: Around Line 4 ----------------------------- + private string field1; +···· + private string field2; +``` + +When a line has extra trailing whitespace +``` +----------------------------- Expected: Around Line 3 ----------------------------- +{ + private string field1; +} +----------------------------- Actual: Around Line 3 ----------------------------- +{ + private string field1;···· +} +``` +#### MSBuild is not encoding using UTF8 [#947](https://github.com/belav/csharpier/issues/947) +When CSharpier.MSBuild ran into a failed csharpier check, it was not encoding the std-error output with UTF8. This resulted in messages such as +``` +----------------------------- Expected: Around Line 3 ----------------------------- +{ +┬╖┬╖┬╖┬╖private┬╖string┬╖field1; +} +----------------------------- Actual: Around Line 3 ----------------------------- +{ +┬╖┬╖┬╖┬╖private┬╖string┬╖field1;┬╖┬╖┬╖┬╖ +} +``` +Thanks go to @Tyrrrz for reporting +#### Comment inside raw string literal is lost when file is formatted. [#937](https://github.com/belav/csharpier/issues/937) +```c# +// input +var rawLiteralWithExpressionThatWeDontFormat = new StringContent( + // this comment shouldn't go away + $$""" + { + "params": "{{searchFilter switch +{ + SearchFilter.Video => "EgIQAQ%3D%3D", + _ => null +}}}" + } + """ +); + +// 0.25.0 +var rawLiteralWithExpressionThatWeDontFormat = new StringContent( + $$""" + { + "params": "{{searchFilter switch +{ + SearchFilter.Video => "EgIQAQ%3D%3D", + _ => null +}}}" + } + """ +); +``` + +Thanks go to @Tyrrrz for reporting +#### Allow line endings to be configurable [#935](https://github.com/belav/csharpier/issues/935) +CSharpier now supports the following options for line endings. The default is `auto` +- "auto" - Maintain existing line endings (mixed values within one file are normalised by looking at what's used after the first line) +- "lf" – Line Feed only (\n), common on Linux and macOS as well as inside git repos +- "crlf" - Carriage Return + Line Feed characters (\r\n), common on Windows + +Thanks go to @phuhl for the feature request +#### Avoid breaking only around binary expression but not binary expression itself [#924](https://github.com/belav/csharpier/issues/924) +```c# +// 0.25.0 +if ( + someLongStatement == true || someOtherStatement________________________________ == false +) + +// 0.26.0 +if (someLongStatement == true || someOtherStatement________________________________ == false) +``` + +Thanks go to @Nixxen for reporting +#### Nested loops without brackets should not be indented [#867](https://github.com/belav/csharpier/issues/867) +```c# +// 0.25.0 +foreach (var subsequence in sequence) + foreach (var item in subsequence) + item.DoSomething(); + +// 0.26.0 +foreach (var subsequence in sequence) +foreach (var item in subsequence) + item.DoSomething(); +``` +Thanks go to @Rudomitori for the contribution +**Full Changelog**: https://github.com/belav/csharpier/compare/0.25.0...0.26.0 +# 0.25.0 ## Breaking Changes #### Improve if directive formatting [#404](https://github.com/belav/csharpier/issues/404) The `preprocessorSymbolSets` configuration option is no longer supported. @@ -1225,3 +1435,4 @@ Thanks go to @pingzing **Full Changelog**: https://github.com/belav/csharpier/compare/0.9.0...0.9.1 + diff --git a/Nuget/Build.props b/Nuget/Build.props index 824aa2b93..73ac071e3 100644 --- a/Nuget/Build.props +++ b/Nuget/Build.props @@ -1,6 +1,6 @@ - 0.25.0 + 0.26.0 MIT https://github.com/belav/csharpier git diff --git a/Src/Website/docs/Configuration.md b/Src/Website/docs/Configuration.md index 5c52a2e29..5a4f3e055 100644 --- a/Src/Website/docs/Configuration.md +++ b/Src/Website/docs/Configuration.md @@ -5,6 +5,7 @@ hide_table_of_contents: true CSharpier has support for a configuration file. You can use any of the following files - A ```.csharpierrc``` file in JSON or YAML. - A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file. +- A ```.editorconfig``` file. See EditorConfig section below. The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found. @@ -15,7 +16,7 @@ JSON "printWidth": 100, "useTabs": false, "tabWidth": 4, - "preprocessorSymbolSets": ["", "DEBUG", "DEBUG,CODE_STYLE"] + "endOfLine": "auto" } ``` YAML @@ -23,30 +24,41 @@ YAML printWidth: 100 useTabs: false tabWidth: 4 -preprocessorSymbolSets: - - "" - - "DEBUG" - - "DEBUG,CODE_STYLE" +endOfLine: auto ``` #### Print Width Specify at what point the printer will wrap content. This is not a hard limit. Some lines will be shorter or longer. -Default 100 +Default `100` #### Use Tabs _First available in 0.17.0_ Indent lines with tabs instead of spaces. -Default false +Default `false` #### Tab Width _First available in 0.17.0_ Specify the number of spaces used per indentation level. -Default 4 +Default `4` + +#### End of Line +_First available in 0.26.0_ + +Valid options: + +- "auto" - Maintain existing line endings (mixed values within one file are normalised by looking at what's used after the first line) +- "lf" – Line Feed only (\n), common on Linux and macOS as well as inside git repos +- "crlf" - Carriage Return + Line Feed characters (\r\n), common on Windows + +Default `auto` + #### Preprocessor Symbol Sets +_Removed in 0.25.0_ + Currently CSharpier only has basic support for understanding how to format code inside of `#if` directives. It will attempt to determine which sets of preprocessor symbols are needed for roslyn to parse all the code in each file. @@ -65,3 +77,22 @@ For example in the following code block, the following symbol sets would be need When supplying symbol sets, they will be used for all files being formatted. This will slow down formatting, and determining all symbol sets needed across all files won't be straight forward. The long term plan is to improve Csharpier's ability to determine the symbol sets itself and to allow specifying them for individual files. + +### EditorConfig + +CSharpier supports configuration via an `.editorconfig` file. A `.csahrpierrc*` file in the same directory will take priority. + +```ini +[*] +# Non-configurable behaviors +charset = utf-8 +insert_final_newline = true +trim_trailing_whitespace = true + +# Configurable behaviors +# end_of_line = lf - there is no 'auto' with a .editorconfig +indent_style = space +indent_size = 4 +max_line_length = 100 + +``` \ No newline at end of file diff --git a/Src/Website/docs/ContinuousIntegration.md b/Src/Website/docs/ContinuousIntegration.md index 91f491632..c2a8613b2 100644 --- a/Src/Website/docs/ContinuousIntegration.md +++ b/Src/Website/docs/ContinuousIntegration.md @@ -37,8 +37,8 @@ Normally when using a code formatter like CSharpier, you'll want to ensure that steps: - uses: actions/checkout@v2 - run: | - dotnet tool restore - dotnet csharpier --check . + dotnet tool restore + dotnet csharpier --check . ```