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

Add CSharpier as a Code Formatter #239

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.27.3",
"commands": [
"dotnet-csharpier"
]
}
}
}
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
60e7aa44819edda932026dc2254db2876e70ead3
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[blame]
ignoreRevsFile = .git-blame-ignore-revs
14 changes: 14 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ on:
types: [opened, reopened, synchronize]

jobs:
formatting:
name: Check formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup .NET
uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4.0.0
with:
dotnet-version: 6.0.402
- name: Install tools
run: dotnet tool restore
- name: Check formatting
run: dotnet csharpier --check .
run-tests:
name: Run tests
strategy:
Expand Down
4 changes: 2 additions & 2 deletions ArchUnitNET.MSTestV2/ArchRuleAssert.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand All @@ -26,4 +26,4 @@ public static void FulfilsRule(Architecture architecture, IArchRule archRule)
}
}
}
}
}
4 changes: 2 additions & 2 deletions ArchUnitNET.MSTestV2/ArchRuleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand Down Expand Up @@ -31,4 +31,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule)
ArchRuleAssert.FulfilsRule(architecture, archRule);
}
}
}
}
57 changes: 44 additions & 13 deletions ArchUnitNET.MSTestV2Tests/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand All @@ -25,7 +25,9 @@ public class RuleEvaluationTests
[ClassInitialize]
public static void Setup(TestContext context)
{
_architecture = new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV2Tests")).Build();
_architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.MSTestV2Tests"))
.Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
Expand All @@ -35,26 +37,55 @@ public static void Setup(TestContext context)
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.ThrowsException<AssertFailedException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule));
Assert.AreEqual(_expectedErrorMessage,
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message));
Assert.ThrowsException<AssertFailedException>(
() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsException<AssertFailedException>(
() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
)
);
}

[TestMethod]
public void ArchRuleExtensionsTest()
{
_architecture.CheckRule(_trueRule);
_trueRule.Check(_architecture);
Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule));
Assert.ThrowsException<AssertFailedException>(
() => _architecture.CheckRule(_falseRule)
);
Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(_expectedErrorMessage,
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => _architecture.CheckRule(_falseRule)).Message));
Assert.AreEqual(_expectedErrorMessage,
RemoveAssertionText(Assert.ThrowsException<AssertFailedException>(() => _falseRule.Check(_architecture)).Message));
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsException<AssertFailedException>(
() => _architecture.CheckRule(_falseRule)
)
.Message
)
);
Assert.AreEqual(
_expectedErrorMessage,
RemoveAssertionText(
Assert
.ThrowsException<AssertFailedException>(
() => _falseRule.Check(_architecture)
)
.Message
)
);
}

private static string RemoveAssertionText(string exceptionMessage) {
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
private static string RemoveAssertionText(string exceptionMessage)
{
return exceptionMessage.Replace("Assert.Fail failed. ", string.Empty);
}
}
}
}
4 changes: 2 additions & 2 deletions ArchUnitNET.NUnit/ArchRuleAssert.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand All @@ -26,4 +26,4 @@ public static void FulfilsRule(Architecture architecture, IArchRule archRule)
}
}
}
}
}
4 changes: 2 additions & 2 deletions ArchUnitNET.NUnit/ArchRuleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand Down Expand Up @@ -31,4 +31,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule)
ArchRuleAssert.FulfilsRule(architecture, archRule);
}
}
}
}
34 changes: 24 additions & 10 deletions ArchUnitNET.NUnitTests/RuleEvaluationTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand All @@ -24,7 +24,9 @@ public class RuleEvaluationTests
[SetUp]
public void Setup()
{
_architecture = new ArchLoader().LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.NUnitTests")).Build();
_architecture = new ArchLoader()
.LoadAssemblies(System.Reflection.Assembly.Load("ArchUnitNET.NUnitTests"))
.Build();
_trueRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().Exist();
_falseRule = Classes().That().Are(typeof(RuleEvaluationTests)).Should().NotExist();
_expectedErrorMessage = _falseRule.Evaluate(_architecture).ToErrorMessage();
Expand All @@ -34,9 +36,17 @@ public void Setup()
public void ArchRuleAssertTest()
{
ArchRuleAssert.FulfilsRule(_architecture, _trueRule);
Assert.Throws<AssertionException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule));
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)).Message);
Assert.Throws<AssertionException>(
() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
);
Assert.AreEqual(
_expectedErrorMessage,
Assert
.Catch<AssertionException>(
() => ArchRuleAssert.FulfilsRule(_architecture, _falseRule)
)
.Message
);
}

[Test]
Expand All @@ -46,10 +56,14 @@ public void ArchRuleExtensionsTest()
_trueRule.Check(_architecture);
Assert.Throws<AssertionException>(() => _architecture.CheckRule(_falseRule));
Assert.Throws<AssertionException>(() => _falseRule.Check(_architecture));
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _architecture.CheckRule(_falseRule)).Message);
Assert.AreEqual(_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _falseRule.Check(_architecture)).Message);
Assert.AreEqual(
_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _architecture.CheckRule(_falseRule)).Message
);
Assert.AreEqual(
_expectedErrorMessage,
Assert.Catch<AssertionException>(() => _falseRule.Check(_architecture)).Message
);
}
}
}
}
4 changes: 2 additions & 2 deletions ArchUnitNET.xUnit/ArchRuleAssert.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand All @@ -26,4 +26,4 @@ public static void CheckRule(Architecture architecture, IArchRule archRule)
}
}
}
}
}
4 changes: 2 additions & 2 deletions ArchUnitNET.xUnit/ArchRuleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using ArchUnitNET.Domain;
Expand Down Expand Up @@ -32,4 +32,4 @@ public static void CheckRule(this Architecture architecture, IArchRule archRule)
ArchRuleAssert.CheckRule(architecture, archRule);
}
}
}
}
12 changes: 4 additions & 8 deletions ArchUnitNET.xUnit/FailedArchRuleException.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Generic;
Expand All @@ -21,17 +21,13 @@ public class FailedArchRuleException : XunitException
/// <param name="architecture">The architecture which was tested</param>
/// <param name="archRule">The archrule that failed</param>
public FailedArchRuleException(Architecture architecture, IArchRule archRule)
: this(archRule.Evaluate(architecture))
{
}
: this(archRule.Evaluate(architecture)) { }

/// <summary>
/// Creates a new instance of the <see href="FailedArchRuleException" /> class.
/// </summary>
/// <param name="evaluationResults">The results of the evaluation of the archrule</param>
public FailedArchRuleException(IEnumerable<EvaluationResult> evaluationResults)
: base(evaluationResults.ToErrorMessage())
{
}
: base(evaluationResults.ToErrorMessage()) { }
}
}
}
29 changes: 19 additions & 10 deletions ArchUnitNET/Domain/Architecture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Paula Ruiz <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
//
//
// SPDX-License-Identifier: Apache-2.0

using System;
Expand All @@ -15,9 +15,13 @@ public class Architecture
private readonly IEnumerable<Assembly> _allAssemblies;
private readonly ObjectProviderCache _objectProviderCache;

public Architecture(IEnumerable<Assembly> allAssemblies, IEnumerable<Namespace> namespaces,
IEnumerable<IType> types, IEnumerable<GenericParameter> genericParameters,
IEnumerable<IType> referencedTypes)
public Architecture(
IEnumerable<Assembly> allAssemblies,
IEnumerable<Namespace> namespaces,
IEnumerable<IType> types,
IEnumerable<GenericParameter> genericParameters,
IEnumerable<IType> referencedTypes
)
{
_allAssemblies = allAssemblies;
Namespaces = namespaces;
Expand All @@ -27,7 +31,8 @@ public Architecture(IEnumerable<Assembly> allAssemblies, IEnumerable<Namespace>
_objectProviderCache = new ObjectProviderCache(this);
}

public IEnumerable<Assembly> Assemblies => _allAssemblies.Where(assembly => !assembly.IsOnlyReferenced);
public IEnumerable<Assembly> Assemblies =>
_allAssemblies.Where(assembly => !assembly.IsOnlyReferenced);
public IEnumerable<Namespace> Namespaces { get; }
public IEnumerable<IType> Types { get; }
public IEnumerable<GenericParameter> GenericParameters { get; }
Expand All @@ -45,8 +50,11 @@ public Architecture(IEnumerable<Assembly> allAssemblies, IEnumerable<Namespace>
public IEnumerable<MethodMember> MethodMembers => Members.OfType<MethodMember>();
public IEnumerable<IMember> Members => Types.SelectMany(type => type.Members);

public IEnumerable<T> GetOrCreateObjects<T>(IObjectProvider<T> objectProvider,
Func<Architecture, IEnumerable<T>> providingFunction) where T : ICanBeAnalyzed
public IEnumerable<T> GetOrCreateObjects<T>(
IObjectProvider<T> objectProvider,
Func<Architecture, IEnumerable<T>> providingFunction
)
where T : ICanBeAnalyzed
{
return _objectProviderCache.GetOrCreateObjects(objectProvider, providingFunction);
}
Expand All @@ -68,8 +76,9 @@ public override bool Equals(object obj)

private bool Equals(Architecture other)
{
return Assemblies.Equals(other.Assemblies) && Namespaces.Equals(other.Namespaces) &&
Types.Equals(other.Types);
return Assemblies.Equals(other.Assemblies)
&& Namespaces.Equals(other.Namespaces)
&& Types.Equals(other.Types);
}

public override int GetHashCode()
Expand All @@ -83,4 +92,4 @@ public override int GetHashCode()
}
}
}
}
}
Loading
Loading