Fix for CSharpier.MsBuild so it selects a compatible framework if the project does not target net6 or net7 #797
This fix auto selects net7.0
for projects that do not target net6.0
or net7.0
. This means the CSharpier_FrameworkVersion
property is only required if a project is targeting < net6.0
and net7.0
is not installed.
Thanks go to @samtrion for submitting the fix.
Support only UTF8 and UTF8-BOM files #787
Previously UTF.Unknown was used to try to determine file encodings. This was problematic because if a file was too small it would not properly detect the encoding.
public enum MeetingLocation
{
Café,
Restaurant
}
This file saved as UTF8 would be detected as SBCSCodePageEncoding and result in CSharpier trying to parse the following file
public enum MeetingLocation
{
Café,
Restaurant
}
CSharpier now only supports UTF8 & UTF8-BOM files. This is consistent with the IDE plugins, which stream files to CSharpier as UTF8.
Thanks go to @Meligy for reporting the problem.
CSharpier.MSBuild support for .NET 7 #773
CSharpier.MSBuild now multi-targets net6.0 and net7.0. As a side effect of multi-targeting, the CSharpier_FrameworkVersion
property is now required for projects that do not target net6.0
or net7.0
. See https://csharpier.com/docs/MsBuild#target-frameworks
Thanks go to @OneCyrus for reporting it
Fix for CSharpier.MsBuild "Specified condition "$(CSharpier_Check)" evaluates to "" instead of a boolean" #788
When projects referencing CSharpier.MsBuild were reloaded, they would get the error "Specified condition "$(CSharpier_Check)" evaluates to "" instead of a boolean" and fail to load.
Thanks go to @samtrion for submitting the fix.
List Pattern support for subpattern within a slice #779
CSharpier did not have proper support for the new c# 11 slice pattern. When a slice contained a pattern, that pattern would be lost.
// input
var someValue = someString is [var firstCharacter, .. var rest];
// 0.21.0
var someValue = someString is [var firstCharacter, ..];
// 0.22.0
var someValue = someString is [var firstCharacter, .. var rest];
Thanks go to @domn1995 for reporting it
Fix for comments within expressions in interpolated strings #774
When an interpolated string contained a comment within an expression, CSharpier was inserting a line break that resulted in invalid code.
// input
var trailingComment = $"{someValue /* Comment shouldn't cause new line */}";
// 0.21.0
var trailingComment = $"{someValue /* Comment shouldn't cause new line */
}";
// 0.22.0
var trailingComment = $"{someValue /* Comment shouldn't cause new line */}";
Thanks go to @IT-CASADO for reporting it
Always put generic type constraints onto a new line #527
// 0.21.0
public class SimpleGeneric<T> where T : new() { }
// 0.22.0
public class SimpleGeneric<T>
where T : new() { }
Always put constructor initializers on their own line #526
// 0.21.0
public Initializers() : this(true) { }
public Initializers(string value) : base(value) { }
// 0.22.0
public Initializers()
: this(true) { }
public Initializers(string value)
: base(value) { }
Full Changelog: https://github.com/belav/csharpier/compare/0.21.0...0.22.0
Support file scoped types #748
CSharpier now supports a file scoped type
file class FileScopedClass
{
// implementation
}
Csharpier removes empty lines in ignored blocks of code #742
In some instances csharpier was removing empty lines in csharpier-ignore
blocks of code
// input
public class KeepLines1
{
// csharpier-ignore-start
private string first;
private string second;
// csharpier-ignore-end
}
// 0.20.0
public class KeepLines1
{
// csharpier-ignore-start
private string first;private string second;
// csharpier-ignore-end
}
Thanks go to @MonstraG for reporting it
Await + LINQ query syntax indents incorrectly #740
// 0.20.0
var result = await from thing in Things
from otherThing in OtherThings
from finalThing in SomethingAsync(thing, otherThing)
select finalThing;
// 0.21.0
var result = await
from thing in Things
from otherThing in OtherThings
from finalThing in SomethingAsync(thing, otherThing)
select finalThing;
Thanks go to @domn1995 for reporting it.
Break anonymous object creation when there are more than two properties #753
Object initializers break when they have more than two properties. For example
var x = new Thing
{
Post = post,
Blog = blog,
SamePostNameCount = count
};
Anonymous object initializers were not included in this logic prior to 0.21.0
// 0.20.0
var result =
from post in Posts
select new { Post = post, Blog = blog, SamePostNameCount = count };
// 0.21.0
var result =
from post in Posts
select new
{
Post = post,
Blog = blog,
SamePostNameCount = count
};
Thanks go to @TwentyFourMinutes for reporting it.
Support net7 #756
The CSharpier dotnet tool now works with net6 or net7.
Fix for ignoring subfolders in node_modules #762
CSharpier was not properly ignoring .cs files when they were in a subfolder of node_modules
Thanks go to @snebjorn for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.20.0...0.21.0
Improve Tuple formatting #735
Tuples would break poorly in some cases
// 0.19.2
public async Task<(ILookup<string, int> someLookup, ILookup<int, string> reverseLookup, ILookup<
string,
ClassName
> thirdLookup)> CreateLookups()
{
return (null, null);
}
public void TuplesAsInput(
(int myInt, string myString, ClassName myClassNameInstance, Dictionary<
int,
string
> wordList) inputArgs
)
{
// do something
}
// 0.20.0
public async Task<(
ILookup<string, int> someLookup,
ILookup<int, string> reverseLookup,
ILookup<string, ClassName> thirdLookup
)> CreateLookups()
{
return (null, null);
}
public void TuplesAsInput(
(
int myInt,
string myString,
ClassName myClassNameInstance,
Dictionary<int, string> wordList
) inputArgs
)
{
// do something
}
Thanks go to @BenjaBobs for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.19.2...0.20.0
.NET Tool Crashes When Run Concurrently #728
Fixed another edge case with running csharpier concurrently.
Thanks go to @Kurt-von-Laven for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.19.1...0.19.2
CSharpier crashes when run multiple times simultaneously #728
The new caching for CSharpier didn't properly handle multiple CSharpier processes formatting at the same time. This is most common when using CSharpier.MsBuild in a solution with multiple projects.
Thanks go to @pingzing for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.19.0...0.19.1
Adding a cache to speed up formatting. #692
CSharpier now caches information about files that it has formatted to speed up subsequent runs.
By default the following are used as cache keys and a file is only formatted if one of them has changed.
- CSharpier Version
- CSharpier Options
- Content of the file
The cache is stored at [LocalApplicationData]/CSharpier/.formattingCache.
Ignore node_modules #699
CSharpier now ignores any files within a node_modules folder.
Thanks go to @RichiCoder1 for the suggestion and @SubjectAlpha for the implementation.
Extra space before curly brace in array initializer #693
// 0.18.0
public class ClassName
{
public int[] SomeArray { get; set; } = { 1, 2, 3 };
}
// 0.19.0
public class MyClass
{
public int[] SomeArray { get; set; } = { 1, 2, 3 };
}
Thanks go to @TiraelSedai for reporting the bug.
Full Changelog: https://github.com/belav/csharpier/compare/0.18.0...0.19.0
Initial C# 11 support #686
CSharpier can format the following c# 11 features
- Raw string literals
- Generic attributes
- Static abstract members in interfaces
- Newlines in string interpolation expressions CSharpier will leave existing new lines within expressions and not add new ones
- List Patterns
- UTF8 string literals
- Unsigned right shift operator
- Checked operator
- Generic math
use relative file path in CommandLineFormatter #680
CSharpier now outputs relative or absolute file paths so that they are clickable in terminals.
dotnet csharpier .
# csharpier 0.17.0
Error Invalid.cs - Failed to compile so was not formatted.
# csharpier 0.18.0
Error ./Invalid.cs - Failed to compile so was not formatted.
dotnet csharpier c:/src
# csharpier 0.17.0
Error Invalid.cs - Failed to compile so was not formatted.
# csharpier 0.18.0
Error c:/src/Invalid.cs - Failed to compile so was not formatted.
Thanks go to @dlech
Invalid code for comments inside expressions in verbatim interpolated strings #679
// input
var someValue =
$@"
{
// comment
"hi"
}
";
// 0.17.0
var someValue =
$@"
{
// comment "hi"}
";
// 0.18.0
var someValue =
$@"
{
// comment
"hi"
}
";
Thanks go to @ivan-razorenov
CSharpier ranged ignore #678
CSharpier now has the ability to ignore a range of statements or members. See Ignore for more details
// csharpier-ignore-start
var unformatted = true;
var unformatted = true;
// csharpier-ignore-end
Thanks go to @pingzing
Full Changelog: https://github.com/belav/csharpier/compare/0.17.0...0.18.0
- MSBuild Task target too late? Breakpoints are not hit #674
- Excessive indent level with lambda as the only method call argument #669
- Empty (or malformed) .csproj file will cause csharpier to fail. #665
- #endif retains extra blank lines #660
- Option for indentation #645
- Small bug with formatting LINQ queries with multiple orderby fields #643
- Consistently Indent By 4 Spaces #617
- Conditional access edge cases #603
- Improve formatting for casting #407
Full Changelog: https://github.com/belav/csharpier/compare/0.16.0...0.17.0
- fix: ignore file detection when directory contains period #634
- Format switch statement consistently with other code. #624
- CodeFormatter should accept SyntaxTree #621
- Add support for netstandard 2.0 to CSharpier.Core #619
- Indent c style multiline comments correctly when they switch indentation. #606
- Member access should break #600
- SuppressNullableWarningExpression ( !. ) does not break consistenly #596
- Turn CSharpier.com into a proper website. #505
Full Changelog: https://github.com/belav/csharpier/compare/0.15.1...0.16.0
- Set CSharpier.MsBuild as DevelopmentDependency. #607
Full Changelog: https://github.com/belav/csharpier/compare/0.15.0...0.15.1
CSharpier.MsBuild
now requires .NET6 #565
- .csharpierignore causes csharpier to be significantly slower #594
- Support for // csharpier-ignore #581
- Multiline comments are not properly indented. #580
- Generics + ObjectCreationExpression should break consistently #578
- Extra blank lines should be removed at the end of a method #575
- Null conditional operator does not break consistently #561
- Enum members should follow the rules for new lines #553
Full Changelog: https://github.com/belav/csharpier/compare/0.14.0...0.15.0
- File with no preprocessor symbols formats twice. #555
- A namespace with
assembly
attribute andusing
causes two newlines #551 - Wrapping arithmetic expressions not stacked/chopped down #547
- Use UTF8 for piping in/out to CLI to support unicode characters #545
Full Changelog: https://github.com/belav/csharpier/compare/0.13.0...0.14.0
- Incorrect indentation in Method chain inside Initializer #529
- Allow empty lines before comments in enums #524
- For with empty statement should have space. #523
- Empty lines are not respected with break and continue #520
- Extra Whitespace in empty anonymous initializer #519
- Class that ends with comment does not retain extra line before comment #513
- Join Clause with Type losing Type #508
- Give cli bad path, you get an exception #506
- Double blank lines appearing in top level statements #501
- VisualStudio Extension #499
- Rider Plugin #498
- CSharpier.MSBuild may have mismatched version with CLI #490
- Break object initializers if there are 3 or more properties #446
- Force lines before and after some members. #285
- Formatting may conflict with StyleCopAnalayzers #13
Full Changelog: https://github.com/belav/csharpier/compare/0.12.0...0.13.0
- If a file that fails to compile is piped to csharpier, csharpier now writes an error message on std error and return a 1 exit code.
- Nested Initializers should break #487
- Adding --pipe-multiple-files and other changes to support vscode extension #283
Full Changelog: https://github.com/belav/csharpier/compare/0.11.1...0.12.0
- CSharpier.MSBuild 0.11.1 is not published correctly #481
- base should merge in an invocation chain #473
- File with multiple newlines at the end keeps them #464
- Extra space in generic with omitted types #463
- Object creation still uses SpaceBrace #462
- Empty Initializer gets double whitespace #461
- Support C# 10 and .Net 6 #448
- Always break nested Conditionals #434
Full Changelog: https://github.com/belav/csharpier/compare/0.10.0...0.11.1
- try-finally without catch clause is formatted strangely. #454
- Nested FixedStatements should break #438
- Disabled text validation fails with trailing whitespace #428
- Vertically Align Curly Braces #423
- Crash On Empty Config File #421
- Conditional in Arguments should indent. #419
- Chained assignments formatting can be improved #417
- Improve ConditionalExpression in ReturnStatement formatting #416
- Pattern Matching edge cases #413
- Implement proper logging. #406
- (finally) Improve formatting of InvocationExpressions #7
Full Changelog: https://github.com/belav/csharpier/compare/0.9.9...0.10.0
- Require the directoryOrFile argument when not piping into to stdin #381
- SwitchExpression + Pattern edge cause causes extra line and poor formatting #408
- NewLines not retained before lock statement #401
- Better error handling when given a csproj or sln file #398
- CSharpierignore not taken into account when supplying . as the directory #392
- SwitchStatement with When breaks even with body of switch #387
- Respect new lines between case statements #383
- Line breaks in "when" clause in SwitchExpression #382
- Block loses extra lines #378
- RecordDeclaration should format consistently with ConstructorDeclaration #371
- Conditional breaking without indentation #345
- Improve formatting of pattern matching (IsPatternExpression, BinaryPattern, etc) #154
- Code in IfDirective can't currently be formatted #15
Full Changelog: https://github.com/belav/csharpier/compare/0.9.8...0.9.9
- Remove all configuration options except for print width. #358
- Array Rank not breaking #353
- SwitchStatement should SpaceBrace #352
- ObjectInitializer keeping brace on same line #336
- ObjectInitializer in CollectionInitializer breaking #335
- Better format do-while #317
- Blocks inside of other blocks are getting an extra new line. #316
- Implicit Object Creation breaking #302
- ForEachVariableStatement not breaking/indenting consistently with regular ForEachStatement #300
- MethodDeclaration with Constraints not breaking before brace #299
- Constructor with Base edge cases #298
- Nested Generics in Variable Declaration #295
- #pragma or trailing comment causes breaking in Object Initializer #252
- Verbatim string with mismatched line endings triggers "failed syntax tree validation" #244
- SwitchExpression formatting. #237
- Empty Method should keep braces on same line #133
- Improving formatting for edge cases of ForStatement #112
- ConditionalExpression indentation #83
- BinaryExpression Grouping #37
Full Changelog: https://github.com/belav/csharpier/compare/0.9.7...0.9.8
- New overload for
Doc.GroupWithId()
#334 - Improve formatting by grouping parenthesized expressions and indenting them if they break. #328
- Improve formatting of IsPattern in IfStatement #327
- Improve formatting of the condition in a do-while #326
- Always break statements without braces. #303
- Empty Line being added with Array Type #301
- Implicit Array Initializer does not format braces consistently with other statements. #297
- Format checked like a invocation expression with an argument list #270
- Attribute should newline before close paren #257
- Tuple with VariableDeclaration #251
- Record - does not format consistently with a class. #233
- CSharpier.Playground should only publish with new released version #224
- Attributes on parameters #204
- Improve Lambda Formatting - indent expression body and break in a way to minimize new lines. #176
- Format ObjectCreationExpression with Initializer consistently #113
- Improve formatting of long Catch Clauses #86
Full Changelog: https://github.com/belav/csharpier/compare/0.9.6...0.9.7
- Add options to write the formatted file to stdout and accept a file from stdin #282
- Implement ConditionalGroup doc type #278
- Optimize some hot paths to speed up formatting. #277
- Implement Align Doc Type #276
- Improve formatting of ClassDeclaration with BaseList + Constraints #275
- Switch tests to width 100 so they line up with default option #256
- Improving formatting of generics + variable declarations. #240
- Improve Forrmatting of Field with lambda and generics #236
- Improve Formatting of object initialiser syntax #234
- Improve formatting of generic methods and constructors #94
- Improve formatting of field with generics #47
Full Changelog: https://github.com/belav/csharpier/compare/0.9.5...0.9.6
- CSharpier.MSBuild does not work with dotnet watch run #228
- Leading comments interfering with breaking InitializerExpression #217
- #endregion is getting indented more on each format #216
- Some files getting extra new lines on each format #215
- File that fails check should give some indication of the formatting that was missing. #182
- Missing nodes in SyntaxNodeComparer need better reporting. #160
Full Changelog: https://github.com/belav/csharpier/compare/0.9.4...0.9.5
- Interpolated verbatim string is not handling line endings #221
- CLI Support for multiple targets #220
- Add support for nuget package that inject msbuild step to run csharpier #218
- Loops without braces #202
Full Changelog: https://github.com/belav/csharpier/compare/0.9.3...0.9.4
- RecordDeclaration with Generics produces invalid code #201
- Formatting of auto implemented properties with access modifiers #188
- Verbatim string literals take into account EndOfLine configuration #183
- CSharpierIgnore & CSharpierRC from parent directories should be respected. #181
- Break apart readme #172
- PatternMatching includes extra spaces #167
- Re-add async file reads #127
- Dictionary Initializer inserts extra new line #103
Full Changelog: https://github.com/belav/csharpier/compare/0.9.2...0.9.3
#0.9.2
- Support "auto" for endOfLine #147
- Long Parameter Attribute should break after ending brace #174
- Attribute on parameter should have space #104
Full Changelog: https://github.com/belav/csharpier/compare/0.9.1...0.9.2
- Add support for .csharpierignore #159
- Break before BinaryOperator #152
- LeadingComments affect breaking #149
- Ignore generated files by default #140
- Return with BinaryExpression #137
- IsPattern breaking inside of IfStatement #130
- SpaceBrace causing breaking when it shouldn't #100
- Implement Formatting Options with Configuration File #10
Full Changelog: https://github.com/belav/csharpier/compare/0.9.0...0.9.1