From 08ceffc3adbf82cbc843119f4bb5ce17cfef07bb Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 15 Jul 2022 12:09:13 +0200 Subject: [PATCH] Upgrade dotnet-format from version 5 to the version included with the .NET (6) SDK. --- .github/workflows/build-ilspy.yml | 5 +-- BuildTools/pre-commit | 10 +++++ BuildTools/tidy.py | 33 -------------- .../OutputVisitor/CSharpOutputVisitor.cs | 3 +- .../CSharp/RecordDecompiler.cs | 45 +++++++++---------- .../Transforms/InterpolatedStringTransform.cs | 12 +++-- .../RemoveInfeasiblePathTransform.cs | 9 ++-- .../IL/Transforms/UsingTransform.cs | 13 +++--- TestPlugin/Properties/AssemblyInfo.cs | 2 +- 9 files changed, 48 insertions(+), 84 deletions(-) create mode 100644 BuildTools/pre-commit delete mode 100644 BuildTools/tidy.py diff --git a/.github/workflows/build-ilspy.yml b/.github/workflows/build-ilspy.yml index e99bf6b0d..f4e1d446a 100644 --- a/.github/workflows/build-ilspy.yml +++ b/.github/workflows/build-ilspy.yml @@ -30,9 +30,6 @@ jobs: - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.1 - - name: Install dotnet-format - run: dotnet tool install dotnet-format --global --version 5.1.225507 - - name: Get Version id: version shell: pwsh @@ -67,7 +64,7 @@ jobs: paths: "test-results/${{ matrix.configuration }}.xml" - name: Format check - run: python BuildTools\tidy.py + run: dotnet format whitespace --verify-no-changes --verbosity detailed - name: Verify package contents if: matrix.configuration == 'debug' diff --git a/BuildTools/pre-commit b/BuildTools/pre-commit new file mode 100644 index 000000000..58a5eadbc --- /dev/null +++ b/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 diff --git a/BuildTools/tidy.py b/BuildTools/tidy.py deleted file mode 100644 index f170adfec..000000000 --- a/BuildTools/tidy.py +++ /dev/null @@ -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()) \ No newline at end of file diff --git a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs index 789253ad4..a38e56842 100644 --- a/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs +++ b/ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpOutputVisitor.cs @@ -733,8 +733,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor case ThisReferenceExpression _: case PrimitiveExpression _: case IdentifierExpression _: - case MemberReferenceExpression - { + case MemberReferenceExpression { Target: ThisReferenceExpression or IdentifierExpression or BaseReferenceExpression diff --git a/ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs b/ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs index 7bf416ab0..f76cb2fe1 100644 --- a/ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/RecordDecompiler.cs @@ -476,11 +476,10 @@ namespace ICSharpCode.Decompiler.CSharp return false; int pos = 0; //Roslyn 4.0.0-3.final start to insert an call to RuntimeHelpers.EnsureSufficientExecutionStack() - if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call - { - Arguments: { Count: 0 }, - Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } } - }) + if (!isStruct && !isInheritedRecord && body.Instructions[pos] is Call { + Arguments: { Count: 0 }, + Method: { Name: "EnsureSufficientExecutionStack", DeclaringType: { Namespace: "System.Runtime.CompilerServices", Name: "RuntimeHelpers" } } + }) { pos++; } @@ -924,19 +923,17 @@ namespace ICSharpCode.Decompiler.CSharp bool Visit(ILInstruction inst) { - if (inst is BinaryNumericInstruction - { - Operator: BinaryNumericOperator.Add, + if (inst is BinaryNumericInstruction { + Operator: BinaryNumericOperator.Add, + CheckForOverflow: false, + Left: BinaryNumericInstruction { + Operator: BinaryNumericOperator.Mul, CheckForOverflow: false, - Left: BinaryNumericInstruction - { - Operator: BinaryNumericOperator.Mul, - CheckForOverflow: false, - Left: var left, - Right: LdcI4 { Value: -1521134295 } - }, - Right: var right - }) + Left: var left, + Right: LdcI4 { Value: -1521134295 } + }, + Right: var right + }) { if (!Visit(left)) return false; @@ -1039,14 +1036,12 @@ namespace ICSharpCode.Decompiler.CSharp { target = null; member = null; - if (inst is CallInstruction - { - Method: - { - AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter, - AccessorOwner: IProperty property - } - } call && (call is CallVirt || (isSealed && call is Call))) + if (inst is CallInstruction { + Method: { + AccessorKind: System.Reflection.MethodSemanticsAttributes.Getter, + AccessorOwner: IProperty property + } + } call && (call is CallVirt || (isSealed && call is Call))) { if (call.Arguments.Count != 1) return false; diff --git a/ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs index 6efe01f26..ed26c0402 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/InterpolatedStringTransform.cs @@ -33,11 +33,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms int interpolationEnd; ILInstruction insertionPoint; // stloc v(newobj DefaultInterpolatedStringHandler..ctor(ldc.i4 literalLength, ldc.i4 formattedCount)) - if (block.Instructions[pos] is StLoc - { - Variable: ILVariable { Kind: VariableKind.Local } v, - Value: NewObj { Arguments: { Count: 2 } } newObj - } stloc + if (block.Instructions[pos] is StLoc { + Variable: ILVariable { Kind: VariableKind.Local } v, + Value: NewObj { Arguments: { Count: 2 } } newObj + } stloc && v.Type.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler) && newObj.Method.DeclaringType.IsKnownType(KnownTypeCode.DefaultInterpolatedStringHandler) && newObj.Arguments[0].MatchLdcI4(out _) @@ -122,8 +121,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms Debug.Assert(insertionPoint == result.LoadInst.Parent); } - return insertionPoint is Call - { + return insertionPoint is Call { Arguments: { Count: 1 }, Method: { Name: "ToStringAndClear", IsStatic: false } }; diff --git a/ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs index 3f4cbbefb..a337ea1ac 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/RemoveInfeasiblePathTransform.cs @@ -79,11 +79,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms branch = null; if (block.Instructions.Count != 2) return false; - if (block.Instructions[0] is not StLoc - { - Variable: { Kind: VariableKind.StackSlot } s, - Value: LdcI4 { Value: 0 or 1 } valueInst - }) + if (block.Instructions[0] is not StLoc { + Variable: { Kind: VariableKind.StackSlot } s, + Value: LdcI4 { Value: 0 or 1 } valueInst + }) { return false; } diff --git a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs index e59257f78..140bd11ad 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/UsingTransform.cs @@ -389,13 +389,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms return false; return true; } - if (condition is MatchInstruction - { - CheckNotNull: true, - CheckType: true, - TestedOperand: LdLoc { Variable: var v }, - Variable: var newObjVar - }) + if (condition is MatchInstruction { + CheckNotNull: true, + CheckType: true, + TestedOperand: LdLoc { Variable: var v }, + Variable: var newObjVar + }) { if (v != objVar) return false; diff --git a/TestPlugin/Properties/AssemblyInfo.cs b/TestPlugin/Properties/AssemblyInfo.cs index 5d7964ff4..060b5a4e4 100644 --- a/TestPlugin/Properties/AssemblyInfo.cs +++ b/TestPlugin/Properties/AssemblyInfo.cs @@ -15,4 +15,4 @@ using System.Runtime.InteropServices; // This sets the default COM visibility of types in the assembly to invisible. // If you need to expose a type to COM, use [ComVisible(true)] on that type. -[assembly: ComVisible(false)] \ No newline at end of file +[assembly: ComVisible(false)]