Skip to content

Commit

Permalink
Merge branch 'main' into ref/subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
shocklateboy92 authored Nov 20, 2024
2 parents 0d6c739 + 84b775f commit f45440a
Show file tree
Hide file tree
Showing 26 changed files with 749 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.29.2",
"version": "0.30.1",
"commands": [
"dotnet-csharpier"
]
Expand Down
117 changes: 116 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,118 @@
# 0.29.2
# 0.30.1
## What's Changed
Revert tool command back to `dotnet-csharpier`, it was supposed to be changed to `csharpier` for 1.0.0

# 0.30.0
## Breaking Changes
The CSharpier dotnet tool no longer supports net6 & net7.
## What's Changed
### Support C# 13 & dotnet 9. [#1318](https://github.com/belav/csharpier/issues/1318)
CSharpier now supports dotnet 9 along with formatting all C# 13 language features.
### Inconsistent Formatting for new() Operator Compared to Explicit Object Constructors [#1364](https://github.com/belav/csharpier/issues/1364)
Implicit and explicit object initialization with constructors was not formatted consistently
```c#
// input & expected output
SomeObject someObject = new(
someLongParameter___________________,
someLongParameter___________________
)
{
Property = longValue_______________________________________________________________________,
};

SomeObject someObject = new SomeObject(
someLongParameter___________________,
someLongParameter___________________
)
{
Property = longValue_______________________________________________________________________,
};

// 0.29.2
SomeObject someObject =
new(someLongParameter___________________, someLongParameter___________________)
{
Property = longValue_______________________________________________________________________,
};

SomeObject someObject = new SomeObject(
someLongParameter___________________,
someLongParameter___________________
)
{
Property = longValue_______________________________________________________________________,
};

```
### Adds additional space before each member access in verbatim interpolated multiline string [#1358](https://github.com/belav/csharpier/issues/1358)
When an interpolated verbatim string contained line breaks, the code within the interpolations would contain extra spaces.
```c#
// input & expected output
var someStringWithLineBreakAndLongValue =
$@"
{someValue.GetValue().Name} someLongText________________________________________________________________";

// 0.29.2
var someStringWithLineBreakAndLongValue =
$@"
{someValue .GetValue() .Name} someLongText________________________________________________________________";
```

### Inserting trailing comma with trailing comment causes problems. [#1354](https://github.com/belav/csharpier/issues/1354)
CSharpier would insert a trailing comma after a trailing comment and format the end result poorly.
```c#
// input
var someObject = new SomeObject()
{
Property1 = 1,
Property2 = 2 // Trailing Comment
};

// 0.29.2
var someObject = new SomeObject()
{
Property1 = 1,
Property2 =
2 // Trailing Comment
,
};

// 0.30.0
var someObject = new SomeObject()
{
Property1 = 1,
Property2 = 2, // Trailing Comment
};
```

### Double line break before collection expression in field [#1351](https://github.com/belav/csharpier/issues/1351)
CSharpier was inserting an extra line break on a long field name followed by a collection expression to initialize it.
```c#
// input & expected output
class ClassName
{
public SomeType[] LongName____________________________________________________________________________ =
[
someLongValue___________________________________________________,
someLongValue___________________________________________________,
];
}

// 0.29.2
class ClassName
{
public SomeType[] LongName____________________________________________________________________________ =

[
someLongValue___________________________________________________,
someLongValue___________________________________________________,
];
}

```

**Full Changelog**: https://github.com/belav/csharpier/compare/0.29.2...0.30.0
# 0.29.2
## What's Changed
### Comments don't follow tabs indent style [#1343](https://github.com/belav/csharpier/issues/1343)
Prior to `0.29.2` CSharpier was converting any tabs within the block of a multiline comment to spaces.
Expand Down Expand Up @@ -2653,3 +2767,4 @@ Thanks go to @pingzing
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-bookworm-slim-amd64 AS base
FROM mcr.microsoft.com/dotnet/aspnet:9.0.0-bookworm-slim-amd64 AS base
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:8.0.100-bookworm-slim-amd64 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0.100-bookworm-slim-amd64 AS build

RUN set -uex \
&& apt-get update \
Expand Down
2 changes: 1 addition & 1 deletion Nuget/Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.29.2</Version>
<Version>0.30.1</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/belav/csharpier</RepositoryUrl>
<RepositoryType>git</RepositoryType>
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<AssemblyName>dotnet-csharpier</AssemblyName>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>csharpier</ToolCommandName>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<RollForward>Major</RollForward>
<SignAssembly>True</SignAssembly>
<PublicKey>002400000480000094000000060200000024000052534131000400000100010049d266ea1aeae09c0abfce28b8728314d4e4807126ee8bc56155a7ddc765997ed3522908b469ae133fc49ef0bfa957df36082c1c2e0ec8cdc05a4ca4dbd4e1bea6c17fc1008555e15af13a8fc871a04ffc38f5e60e6203bfaf01d16a2a283b90572ade79135801c1675bf38b7a5a60ec8353069796eb53a26ffdddc9ee1273be</PublicKey>
</PropertyGroup>
Expand Down
19 changes: 9 additions & 10 deletions Src/CSharpier.Cli/EditorConfig/ConfigFileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ internal static class ConfigFileParser
// "Comment: starts with a ; or a #."
private static readonly Regex CommentRegex = new("^[;#].*$");

private static readonly IniParserConfiguration Configuration =
new()
{
CommentRegex = CommentRegex,
AllowDuplicateKeys = true,
AllowDuplicateSections = true,
OverrideDuplicateKeys = true,
SkipInvalidLines = true,
ThrowExceptionsOnError = false,
};
private static readonly IniParserConfiguration Configuration = new()
{
CommentRegex = CommentRegex,
AllowDuplicateKeys = true,
AllowDuplicateSections = true,
OverrideDuplicateKeys = true,
SkipInvalidLines = true,
ThrowExceptionsOnError = false,
};

public static ConfigFile Parse(string filePath, IFileSystem fileSystem)
{
Expand Down
15 changes: 7 additions & 8 deletions Src/CSharpier.Cli/EditorConfig/Globber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ namespace CSharpier.Cli.EditorConfig;

internal static class Globber
{
private static readonly GlobMatcherOptions globOptions =
new()
{
MatchBase = true,
Dot = true,
AllowWindowsPaths = true,
AllowSingleBraceSets = true,
};
private static readonly GlobMatcherOptions globOptions = new()
{
MatchBase = true,
Dot = true,
AllowWindowsPaths = true,
AllowSingleBraceSets = true,
};

public static GlobMatcher Create(string files, string directory)
{
Expand Down
36 changes: 17 additions & 19 deletions Src/CSharpier.FakeGenerators/Ignored.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,22 @@ public static class Ignored

public static readonly Type[] Types = { typeof(TextSpan), typeof(SyntaxTree) };

public static readonly Dictionary<Type, string[]> PropertiesByType =
new()
{
{ typeof(PropertyDeclarationSyntax), new[] { "semicolon" } },
{ typeof(IndexerDeclarationSyntax), new[] { "semicolon" } },
{ typeof(SyntaxTrivia), new[] { "token" } },
{ typeof(SyntaxToken), new[] { "value", "valueText" } },
{ typeof(ParameterSyntax), new[] { "exclamationExclamationToken" } },
};
public static readonly Dictionary<Type, string[]> PropertiesByType = new()
{
{ typeof(PropertyDeclarationSyntax), new[] { "semicolon" } },
{ typeof(IndexerDeclarationSyntax), new[] { "semicolon" } },
{ typeof(SyntaxTrivia), new[] { "token" } },
{ typeof(SyntaxToken), new[] { "value", "valueText" } },
{ typeof(ParameterSyntax), new[] { "exclamationExclamationToken" } },
};

public static readonly HashSet<string> UnsupportedNodes =
new()
{
// if new versions of c# add node types, we need to ignore them in the generators
// until codeAnalysis + sdks are updated
// global.json doesn't seem to always be respected for builds (namely VS but rider started having the same problem)
// which causes the generators to generate code for the new node types
// but then the build fails because those types don't exist in the packages the actual project references
// "ListPatternSyntax", "SlicePatternSyntax"
};
public static readonly HashSet<string> UnsupportedNodes = new()
{
// if new versions of c# add node types, we need to ignore them in the generators
// until codeAnalysis + sdks are updated
// global.json doesn't seem to always be respected for builds (namely VS but rider started having the same problem)
// which causes the generators to generate code for the new node types
// but then the build fails because those types don't exist in the packages the actual project references
// "ListPatternSyntax", "SlicePatternSyntax"
};
}
4 changes: 3 additions & 1 deletion Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '8.0'))">net8.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == ''" Label="Fallback">net8.0</CSharpier_FrameworkVersion>
<CSharpierDllPath>$(MSBuildThisFileDirectory)../tools/csharpier/$(CSharpier_FrameworkVersion)/dotnet-csharpier.dll</CSharpierDllPath>
<CSharpier_dotnet_Path Condition="'$(CSharpier_dotnet_Path)' == ''">$(DOTNET_HOST_PATH)</CSharpier_dotnet_Path>
<CSharpier_dotnet_Path Condition="'$(CSharpier_dotnet_Path)' == ''">dotnet</CSharpier_dotnet_Path>
<CSharpierArgs Condition="'$(CSharpier_Check)' == 'true'">$(CSharpierArgs) --check</CSharpierArgs>
<CSharpierArgs Condition="'$(CSharpier_LogLevel)' != ''">$(CSharpierArgs) --loglevel $(CSharpier_LogLevel)</CSharpierArgs>
<FirstTargetFramework Condition=" '$(TargetFrameworks)' == '' ">$(TargetFramework)</FirstTargetFramework>
Expand All @@ -23,7 +25,7 @@
StdOutEncoding="utf-8"
StdErrEncoding="utf-8"
IgnoreExitCode="true"
Command="dotnet &quot;$(CSharpierDllPath)&quot; $(CSharpierArgs) --no-msbuild-check --compilation-errors-as-warnings &quot;$(MSBuildProjectDirectory)&quot; &gt; $(NullOutput) " />
Command="&quot;$(CSharpier_dotnet_Path)&quot; exec &quot;$(CSharpierDllPath)&quot; $(CSharpierArgs) --no-msbuild-check --compilation-errors-as-warnings &quot;$(MSBuildProjectDirectory)&quot; &gt; $(NullOutput) " />
</Target>

<!-- getting this to run a single time for projects that target multiple frameworks requires all of this
Expand Down
89 changes: 44 additions & 45 deletions Src/CSharpier.Tests/MissingTypeChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,49 +70,48 @@ public void Ensure_There_Are_No_Missing_Types()
missingTypes.Should().BeEmpty();
}

private readonly HashSet<string> ignored =
new()
{
"AccessorDeclarationSyntax",
"AccessorListSyntax",
"AttributeArgumentListSyntax",
"AttributeArgumentSyntax",
"AttributeSyntax",
"AttributeTargetSpecifierSyntax",
"BaseListSyntax",
"CatchDeclarationSyntax",
"CatchFilterClauseSyntax",
"ConstructorInitializerSyntax",
"ConversionOperatorMemberCrefSyntax",
"CrefBracketedParameterListSyntax",
"CrefParameterListSyntax",
"CrefParameterSyntax",
"ExplicitInterfaceSpecifierSyntax",
"FunctionPointerCallingConventionSyntax",
"FunctionPointerParameterListSyntax",
"FunctionPointerParameterSyntax",
"FunctionPointerUnmanagedCallingConventionListSyntax",
"FunctionPointerUnmanagedCallingConventionSyntax",
"IndexerMemberCrefSyntax",
"InterpolationAlignmentClauseSyntax",
"InterpolationFormatClauseSyntax",
"JoinIntoClauseSyntax",
"LineDirectivePositionSyntax",
"NameMemberCrefSyntax",
"OperatorMemberCrefSyntax",
"OrderingSyntax",
"PositionalPatternClauseSyntax",
"PropertyPatternClauseSyntax",
"QualifiedCrefSyntax",
"SubpatternSyntax",
"SwitchExpressionArmSyntax",
"TypeCrefSyntax",
"XmlCrefAttributeSyntax",
"XmlElementEndTagSyntax",
"XmlElementStartTagSyntax",
"XmlNameAttributeSyntax",
"XmlNameSyntax",
"XmlPrefixSyntax",
"XmlTextAttributeSyntax",
};
private readonly HashSet<string> ignored = new()
{
"AccessorDeclarationSyntax",
"AccessorListSyntax",
"AttributeArgumentListSyntax",
"AttributeArgumentSyntax",
"AttributeSyntax",
"AttributeTargetSpecifierSyntax",
"BaseListSyntax",
"CatchDeclarationSyntax",
"CatchFilterClauseSyntax",
"ConstructorInitializerSyntax",
"ConversionOperatorMemberCrefSyntax",
"CrefBracketedParameterListSyntax",
"CrefParameterListSyntax",
"CrefParameterSyntax",
"ExplicitInterfaceSpecifierSyntax",
"FunctionPointerCallingConventionSyntax",
"FunctionPointerParameterListSyntax",
"FunctionPointerParameterSyntax",
"FunctionPointerUnmanagedCallingConventionListSyntax",
"FunctionPointerUnmanagedCallingConventionSyntax",
"IndexerMemberCrefSyntax",
"InterpolationAlignmentClauseSyntax",
"InterpolationFormatClauseSyntax",
"JoinIntoClauseSyntax",
"LineDirectivePositionSyntax",
"NameMemberCrefSyntax",
"OperatorMemberCrefSyntax",
"OrderingSyntax",
"PositionalPatternClauseSyntax",
"PropertyPatternClauseSyntax",
"QualifiedCrefSyntax",
"SubpatternSyntax",
"SwitchExpressionArmSyntax",
"TypeCrefSyntax",
"XmlCrefAttributeSyntax",
"XmlElementEndTagSyntax",
"XmlElementStartTagSyntax",
"XmlNameAttributeSyntax",
"XmlNameSyntax",
"XmlPrefixSyntax",
"XmlTextAttributeSyntax",
};
}
13 changes: 0 additions & 13 deletions Src/CSharpier.VSCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,3 @@ dotnet tool install csharpier

# rebuild container image
```

## Limitations

Format Selection is not supported.

Only `"editor.formatOnSaveMode" : "file"` is supported. If using other modes, you can set `file` by scoping the setting:
```json
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications"
"[csharp]": {
"editor.formatOnSaveMode": "file"
}
```
Loading

0 comments on commit f45440a

Please sign in to comment.