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
belav authored Nov 9, 2024
2 parents c363896 + 91bbafb commit 9415156
Show file tree
Hide file tree
Showing 41 changed files with 423 additions and 98 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/format_repositories.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Format Repositories
on:
workflow_dispatch:
push:
branches: [ main ]
paths:
Expand All @@ -9,13 +10,15 @@ jobs:
format_repositories:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
path: csharpier
- uses: actions/setup-dotnet@v3
- uses: actions/checkout@v2
- uses: actions/setup-dotnet@v4
with:
global-json-file: csharpier/global.json
- uses: actions/checkout@v4
with:
repository: belav/csharpier-repos
path: csharpier-repos
- run: dotnet build csharpier/Src/CSharpier.Cli/CSharpier.Cli.csproj -c release
- run: dotnet csharpier/Src/CSharpier.Cli/bin/release/net8.0/dotnet-csharpier.dll csharpier-repos --skip-write
- run: dotnet csharpier/Src/CSharpier.Cli/bin/release/net9.0/dotnet-csharpier.dll csharpier-repos --skip-write
2 changes: 1 addition & 1 deletion .run/Playground.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Playground" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/Src/CSharpier.Playground/CSharpier.Playground.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net7.0" />
<option name="LAUNCH_PROFILE_TFM" value="net9.0" />
<option name="LAUNCH_PROFILE_NAME" value="Watch" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net9.0</TargetFrameworks>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
36 changes: 18 additions & 18 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.13.11" />
<PackageVersion Include="BenchmarkDotNet.Annotations" Version="0.13.11" />
<PackageVersion Include="CliWrap" Version="3.6.4" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="BenchmarkDotNet.Annotations" Version="0.14.0" />
<PackageVersion Include="CliWrap" Version="3.6.6" />
<PackageVersion Include="DiffEngine" Version="6.5.7" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Ignore" Version="0.1.50" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Ignore" Version="0.2.1" />
<PackageVersion Include="ini-parser-netstandard" Version="2.5.2" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.8" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="NReco.Logging.File" Version="1.2.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NReco.Logging.File" Version="1.2.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Scriban" Version="5.9.0" />
<PackageVersion Include="Scriban" Version="5.10.0" />
<PackageVersion Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageVersion Include="System.IO.Abstractions" Version="20.0.4" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="20.0.4" />
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
<PackageVersion Include="System.IO.Abstractions.TestingHelpers" Version="21.0.29" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="YamlDotNet" Version="13.7.1" />
<PackageVersion Include="YamlDotNet" Version="16.1.2" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ public class ClassName
See [Development Readme](CONTRIBUTING.md)

Join Us [![Discord](https://img.shields.io/badge/Discord-chat?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/HfAKGEZQcX)

## Sponsors

Special thanks to the [.NET on AWS Open Source Software Fund](https://github.com/aws/dotnet-foss) for sponsoring the ongoing development CSharpier.

[<img src="./Src/Website/static/img/aws.png" style="padding: 10px 0; width: 200px" />](https://github.com/aws/dotnet-foss)
4 changes: 2 additions & 2 deletions Scripts/RunLinuxTests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# running this seems to screw up the nuget restore, but provides a way to figure out why a test is failing on linux while working on windows.
# you have to run this from the root, IE powershell ./Scripts/RunLinuxTests.ps1
# also a lot of these tests fail due to line endings in your local files being \r\n but the writeLine using \n
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:7.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx
docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app/tests mcr.microsoft.com/dotnet/sdk:9.0 dotnet test /app/Src/CSharpier.Tests/CSharpier.Tests.csproj --logger:trx

# gross way to run csharpier against the csharpier-repos
#docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app mcr.microsoft.com/dotnet/sdk:5.0 dotnet ./csharpier/Src/CSharpier/bin/Debug/net6.0/dotnet-csharpier.dll csharpier-repos --skip-write
#docker run --rm -v ${pwd}:/app -e "NormalizeLineEndings=1" -w /app mcr.microsoft.com/dotnet/sdk:9.0 dotnet ./csharpier/Src/CSharpier/bin/Debug/net9.0/dotnet-csharpier.dll csharpier-repos --skip-write
24 changes: 24 additions & 0 deletions Shell/PublishVS.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function CSH-PublishVS {
param (
[Parameter(Mandatory=$true)]
[string]$accessToken
)

$repositoryRoot = Join-Path $PSScriptRoot ".."
$vsRoot = Join-Path $repositoryRoot "/Src/CSharpier.VisualStudio"

$vsixPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional\VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe"

& $vsixPath publish `
-payload $vsRoot/CSharpier.VisualStudio/bin/Release/CSharpier.VisualStudio.vsix `
-publishManifest $vsRoot/manifest.json `
-personalAccessToken $accessToken

& $vsixPath publish `
-payload $vsRoot/CSharpier.VisualStudio2019/bin/Release/CSharpier.VisualStudio2019.vsix `
-publishManifest $vsRoot/manifest2019.json `
-personalAccessToken $accessToken

}

Export-ModuleMember -Function CSH-*
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<PackageId>CSharpier</PackageId>
<AssemblyName>dotnet-csharpier</AssemblyName>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>csharpier</ToolCommandName>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private CompareResult Compare(
sourceBuilder.AppendLine(
$"""
case {syntaxNodeType.Name} {lowerCaseName}:
if (this.IgnoreDisabledText)
if (this.ReorderedUsingsWithDisabledText)
return Equal;
return this.Compare{syntaxNodeType.Name}({lowerCaseName}, formattedNode as {syntaxNodeType.Name});
"""
Expand Down
4 changes: 2 additions & 2 deletions Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../Nuget/Build.props"/>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<PackageId>CSharpier.MsBuild</PackageId>
<DevelopmentDependency>true</DevelopmentDependency>
<CSharpierOutputDir>../CSharpier.Cli/bin/$(Configuration)/$(TargetFramework)</CSharpierOutputDir>
Expand All @@ -10,7 +10,7 @@
<!--
Note: There is no <ProjectReference /> here because that would cause msbuild to
make it a dependency in the output package, which causes all sorts of issues as
CSharpier is a net6.0 project with <PackAsTool> and this is neither.
CSharpier is a net9.0 project with <PackAsTool> and this is neither.
-->
<Target Name="BuildCSharpier" BeforeTargets="Restore">
<Exec command="dotnet build -c $(Configuration)" WorkingDirectory="../CSharpier.Cli" />
Expand Down
3 changes: 1 addition & 2 deletions Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project>
<PropertyGroup>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '9.0'))">net9.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '8.0'))">net8.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '7.0'))">net7.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == '' and $([MSBuild]::VersionGreaterThanOrEquals($(NETCoreSdkVersion), '6.0'))">net6.0</CSharpier_FrameworkVersion>
<CSharpier_FrameworkVersion Condition="'$(CSharpier_FrameworkVersion)' == ''" Label="Fallback">net8.0</CSharpier_FrameworkVersion>
<CSharpierDllPath>$(MSBuildThisFileDirectory)../tools/csharpier/$(CSharpier_FrameworkVersion)/dotnet-csharpier.dll</CSharpierDllPath>
<CSharpierArgs Condition="'$(CSharpier_Check)' == 'true'">$(CSharpierArgs) --check</CSharpierArgs>
Expand Down
2 changes: 2 additions & 0 deletions Src/CSharpier.Tests/CSharpier.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
<!-- DiffEngine references older packages and vulnerabilities on tests isn't a big deal -->
<NuGetAuditMode>direct</NuGetAuditMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DiffEngine" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class C<T>
where T : allows ref struct
{
// Use T as a ref struct:
public void M(scoped T p)
{
// The parameter p must follow ref safety rules
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ class ClassName { }

class CastExpressions
{
public SomeType[] ShortName =
[
someLongValue___________________________________________________,
someLongValue___________________________________________________,
];

public SomeType[] LongName____________________________________________________________________________ =
[
someLongValue___________________________________________________,
someLongValue___________________________________________________,
];

void MethodName()
{
var x = (string[])[someValue, someValue];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,39 @@ class ClassName
{ };
}

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

SomeObject someObject = new SomeObject
{
Property = longValue_______________________________________________________________________,
};

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

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

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

SomeObject someObject = new SomeObject(
someLongParameter___________________,
someLongParameter___________________
)
{
Property = longValue_______________________________________________________________________,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,9 @@ SomeVerbatimString
SomeVerbatimString
".CallMethod().CallMethod().CallMethod()
);

var someStringWithLineBreakAndLongValue =
$@"
{someValue.GetValue().Name} someLongText________________________________________________________________";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var someObject = new SomeObject()
{
Property1 = 1,
Property2 = 2, // Trailing Comment
};

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

var someObject = new SomeObject()
{
Property1 = 1,
Property2 =
[ /* this formatting isn't ideal, but this probably won't happen in the real world */
], // Trailing Comment
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var someObject = new SomeObject()
{
Property1 = 1,
Property2 = 2 // Trailing Comment
};

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

var someObject = new SomeObject()
{
Property1 = 1,
Property2 = [/* this formatting isn't ideal, but this probably won't happen in the real world */ ] // Trailing Comment
};
8 changes: 5 additions & 3 deletions Src/CSharpier.VisualStudio/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Publishing
- Update version in BOTH files at CSharpier.VisualStudio[2019]/source.extension.vsixmanifest
- Update ChangeLog.md
- build solution in release (can this happen via command line?)
- go to https://marketplace.visualstudio.com/manage/publishers/csharpier (with personal microsoft account)
- three dots - edit - add new vsix
- Automate this if we release a lot
- use cli
- CSH-PublishVS [AccessToken]
- old way
- go to https://marketplace.visualstudio.com/manage/publishers/csharpier (with personal microsoft account)
- three dots - edit - add new vsix
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.8.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
<License>LICENSE</License>
<Icon>logo.png</Icon>
<Tags>Format, Formatting, LineEnd, Tab, Space, CSharpier, Prettier</Tags>
<Tags>CSharpier;Formatting;Prettier;C#;Code;Format;Formatter;Formatting</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,)">
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,)">
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[17.0,18.0)">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.0,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.8.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
<License>LICENSE</License>
<Icon>logo.png</Icon>
<Tags>Format, Formatting, LineEnd, Tab, Space, CSharpier, Prettier</Tags>
<Tags>CSharpier;Formatting;Prettier;C#;Code;Format;Formatter;Formatting</Tags>
</Metadata>
<Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[16.0, 17.0)" />
Expand Down
Loading

0 comments on commit 9415156

Please sign in to comment.