Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order modifiers #744

Merged
merged 10 commits into from
Jun 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Code review changes
belav committed Jun 10, 2023
commit 26f2b3e213d67927cb8dd44651145c4b4c3d3457
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -58,3 +58,4 @@ Src/CSharpier.VSCode/.idea/prettier.xml
/Src/CSharpier.Tests/Samples/Scratch.cst

.idea/.idea.CSharpier/.idea/riderMarkupCache.xml
/Src/CSharpier.Benchmarks/BenchmarkDotNet.Artifacts/
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BenchmarkDotNet" Version="0.12.1" />
<PackageVersion Include="BenchmarkDotNet.Annotations" Version="0.12.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.5" />
<PackageVersion Include="BenchmarkDotNet.Annotations" Version="0.13.5" />
<PackageVersion Include="CliWrap" Version="3.3.3" />
<PackageVersion Include="DiffEngine" Version="6.5.7" />
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
@@ -30,4 +30,4 @@
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="YamlDotNet" Version="11.1.1" />
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions Src/CSharpier.Benchmarks/CSharpier.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet"/>
<PackageReference Include="BenchmarkDotNet.Annotations"/>
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="BenchmarkDotNet.Annotations" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CSharpier\CSharpier.csproj"/>
<ProjectReference Include="..\CSharpier\CSharpier.csproj" />
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions Src/CSharpier/SyntaxPrinter/Modifiers.cs
Original file line number Diff line number Diff line change
@@ -28,14 +28,14 @@ private class DefaultOrder : IComparer<string>

public int Compare(string? x, string? y)
{
int GetIndex(string? value)
{
var result = Array.IndexOf(DefaultOrdered, value);
return result == -1 ? int.MaxValue : result;
}

return GetIndex(x) - GetIndex(y);
}

private static int GetIndex(string? value)
{
var result = Array.IndexOf(DefaultOrdered, value);
return result == -1 ? int.MaxValue : result;
}
}

private static readonly DefaultOrder Comparer = new();
@@ -58,9 +58,9 @@ FormattingContext context
modifiers,
sortedModifiers =>
Doc.Group(
Token.PrintWithoutLeadingTrivia(sortedModifiers.First(), context),
Token.PrintWithoutLeadingTrivia(sortedModifiers[0], context),
" ",
sortedModifiers.Count() > 1
sortedModifiers.Count > 1
? Doc.Concat(
sortedModifiers
.Skip(1)
@@ -74,7 +74,7 @@ FormattingContext context

private static Doc PrintWithSortedModifiers(
SyntaxTokenList modifiers,
Func<IEnumerable<SyntaxToken>, Doc> print
Func<IReadOnlyList<SyntaxToken>, Doc> print
)
{
if (modifiers.Count == 0)
@@ -88,6 +88,6 @@ Func<IEnumerable<SyntaxToken>, Doc> print
? modifiers.AsEnumerable()
: modifiers.OrderBy(o => o.Text, Comparer);

return print(sortedModifiers);
return print(sortedModifiers.ToArray());
}
}