Browse Source

Upgrade dotnet-format from version 5 to the version included with the .NET (6) SDK.

pull/2747/head
Daniel Grunwald 4 years ago
parent
commit
08ceffc3ad
  1. 5
      .github/workflows/build-ilspy.yml
  2. 10
      BuildTools/pre-commit
  3. 33
      BuildTools/tidy.py
  4. 3
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs
  5. 15
      ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs
  6. 6
      ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs
  7. 3
      ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs
  8. 3
      ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

5
.github/workflows/build-ilspy.yml

@ -30,9 +30,6 @@ jobs:
- name: Add msbuild to PATH - name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1 uses: microsoft/setup-msbuild@v1.1
- name: Install dotnet-format
run: dotnet tool install dotnet-format --global --version 5.1.225507
- name: Get Version - name: Get Version
id: version id: version
shell: pwsh shell: pwsh
@ -67,7 +64,7 @@ jobs:
paths: "test-results/${{ matrix.configuration }}.xml" paths: "test-results/${{ matrix.configuration }}.xml"
- name: Format check - name: Format check
run: python BuildTools\tidy.py run: dotnet format whitespace --verify-no-changes --verbosity detailed
- name: Verify package contents - name: Verify package contents
if: matrix.configuration == 'debug' if: matrix.configuration == 'debug'

10
BuildTools/pre-commit

@ -0,0 +1,10 @@
#!/bin/sh
#
# To enable this hook, copy/symlink this file to ".git/hooks/pre-commit".
#if git diff --quiet --ignore-submodules; then
# dotnet format whitespace --no-restore --verbosity detailed ILSpy.sln
# git add -u -- \*\*.cs
#else
exec dotnet format whitespace --verify-no-changes --no-restore --verbosity detailed ILSpy.sln
#fi

33
BuildTools/tidy.py

@ -1,33 +0,0 @@
#!/usr/bin/env python
import os, sys, subprocess
def check(filename):
ok = True
with open(filename, 'r') as f:
for i, line in enumerate(f):
if line.startswith(' '):
print('{}:{}: Line starting with spaces. Use tabs for indentation instead!'.format(filename, i+1))
ok = False
return ok
def main():
root_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
dirs_to_check = (
os.path.join(root_dir, subdir)
for subdir in ('ICSharpCode.Decompiler', 'ICSharpCode.Decompiler.Tests', 'ILSpy', 'ILSpy.BamlDecompiler'))
format_result = subprocess.call(['dotnet-format', '--check', '--verbosity', 'detailed', os.path.join(root_dir, 'ILSpy.sln')])
ok = format_result == 0
for dir in dirs_to_check:
for root, dirs, files in os.walk(dir):
if '\\obj\\' in root:
continue
for filename in files:
if filename.lower().endswith('.cs') and not filename.lower().endswith('resources.designer.cs'):
if not check(os.path.join(root, filename)):
ok = False
print('Tidy check: {}'.format('successful' if ok else 'failed'))
return 0 if ok else 1
if __name__ == '__main__':
sys.exit(main())

3
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -733,8 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
case ThisReferenceExpression _: case ThisReferenceExpression _:
case PrimitiveExpression _: case PrimitiveExpression _:
case IdentifierExpression _: case IdentifierExpression _:
case MemberReferenceExpression case MemberReferenceExpression {
{
Target: ThisReferenceExpression Target: ThisReferenceExpression
or IdentifierExpression or IdentifierExpression
or BaseReferenceExpression or BaseReferenceExpression

15
ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs

@ -476,8 +476,7 @@ namespace ICSharpCode.Decompiler.CSharp
return false; return false;
int pos = 0; int pos = 0;
//Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack() //Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack()
if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call {
{
Arguments: { Count: 0 }, Arguments: { Count: 0 },
Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } } Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } }
}) })
@ -924,12 +923,10 @@ namespace ICSharpCode.Decompiler.CSharp
bool Visit(ILInstruction inst) bool Visit(ILInstruction inst)
{ {
if (inst is BinaryNumericInstruction if (inst is BinaryNumericInstruction {
{
Operator: BinaryNumericOperator.Add, Operator: BinaryNumericOperator.Add,
CheckForOverflow: false, CheckForOverflow: false,
Left: BinaryNumericInstruction Left: BinaryNumericInstruction {
{
Operator: BinaryNumericOperator.Mul, Operator: BinaryNumericOperator.Mul,
CheckForOverflow: false, CheckForOverflow: false,
Left: var left, Left: var left,
@ -1039,10 +1036,8 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
target = null; target = null;
member = null; member = null;
if (inst is CallInstruction if (inst is CallInstruction {
{ Method: {
Method:
{
AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter, AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter,
AccessorOwner: IProperty property AccessorOwner: IProperty property
} }

6
ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs

@ -33,8 +33,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
int interpolationEnd; int interpolationEnd;
ILInstruction insertionPoint; ILInstruction insertionPoint;
// stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount)) // stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount))
if (block.Instructions[pos] is StLoc if (block.Instructions[pos] is StLoc {
{
Variable: ILVariable { Kind: VariableKind.Local } v, Variable: ILVariable { Kind: VariableKind.Local } v,
Value: NewObj { Arguments: { Count: 2 } } newObj Value: NewObj { Arguments: { Count: 2 } } newObj
} stloc } stloc
@ -122,8 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Debug.Assert(insertionPoint == result.LoadInst.Parent); Debug.Assert(insertionPoint == result.LoadInst.Parent);
} }
return insertionPoint is Call return insertionPoint is Call {
{
Arguments: { Count: 1 }, Arguments: { Count: 1 },
Method: { Name: "ToStringAndClear", IsStatic: false } Method: { Name: "ToStringAndClear", IsStatic: false }
}; };

3
ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs

@ -79,8 +79,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
branch = null; branch = null;
if (block.Instructions.Count != 2) if (block.Instructions.Count != 2)
return false; return false;
if (block.Instructions[0] is not StLoc if (block.Instructions[0] is not StLoc {
{
Variable: { Kind: VariableKind.StackSlot } s, Variable: { Kind: VariableKind.StackSlot } s,
Value: LdcI4 { Value: 0 or 1 } valueInst Value: LdcI4 { Value: 0 or 1 } valueInst
}) })

3
ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs

@ -389,8 +389,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
return false; return false;
return true; return true;
} }
if (condition is MatchInstruction if (condition is MatchInstruction {
{
CheckNotNull: true, CheckNotNull: true,
CheckType: true, CheckType: true,
TestedOperand: LdLoc { Variable: var v }, TestedOperand: LdLoc { Variable: var v },

Loading…
Cancel
Save