Skip to content

Commit 02f67a8

Browse files
authored
Format source code and add format check on ci (#758)
1 parent 3ce2d66 commit 02f67a8

File tree

79 files changed

+418
-367
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+418
-367
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trim_trailing_whitespace = true
77
indent_size = 4
88
indent_style = space
99

10-
[*.{sln,csproj,fsproj,yml}]
10+
[*.{sln,csproj,fsproj,yml,props}]
1111
indent_size = 2
1212
indent_style = space
1313

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: Build and Test
2-
1+
name: Build, Test, and Format
32
on: [push, pull_request]
3+
44
jobs:
55
test:
66
strategy:
@@ -10,42 +10,42 @@ jobs:
1010
include:
1111
- os: windows-latest
1212
framework: net462
13-
13+
1414
runs-on: ${{ matrix.os }}
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v3
18-
18+
1919
- name: Setup .NET
2020
uses: actions/setup-dotnet@v3
2121
with:
2222
dotnet-version: |
2323
6.0.x
2424
7.0.x
2525
8.0.x
26-
26+
2727
- name: Build
2828
run: dotnet build
29-
29+
3030
- name: Test
3131
run: dotnet test -f ${{ matrix.framework }} --no-build --no-restore
32-
32+
3333
test-documentation:
3434
runs-on: windows-latest
3535
steps:
3636
- name: Checkout
3737
uses: actions/checkout@v3
3838
with:
3939
fetch-depth: 0
40-
40+
4141
- name: Setup .NET
4242
uses: actions/setup-dotnet@v3
4343
with:
4444
dotnet-version: |
4545
6.0.x
4646
7.0.x
4747
8.0.x
48-
48+
4949
# used for documentation
5050
- name: Setup Ruby
5151
uses: ruby/setup-ruby@v1
@@ -54,4 +54,18 @@ jobs:
5454
bundler-cache: true
5555

5656
- name: Build all targets
57-
run: build\build.cmd --target All
57+
run: build\build.cmd --target All
58+
59+
format-verify:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v3
64+
65+
- name: Setup .NET
66+
uses: actions/setup-dotnet@v3
67+
with:
68+
dotnet-version: 8.0.x
69+
70+
- name: Format
71+
run: dotnet format --verify-no-changes

src/NSubstitute/Arg.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static ref TDelegate InvokeDelegate<TDelegate>(params object[] arguments)
114114
/// </summary>
115115
public static ref T Do<T>(Action<T> useArgument)
116116
{
117-
return ref ArgumentMatcher.Enqueue<T>(new AnyArgumentMatcher(typeof(T)), x => useArgument((T) x!));
117+
return ref ArgumentMatcher.Enqueue<T>(new AnyArgumentMatcher(typeof(T)), x => useArgument((T)x!));
118118
}
119119

120120
/// <summary>
@@ -225,7 +225,7 @@ public static class Compat
225225

226226
private static Action<object> InvokeDelegateAction(params object[] arguments)
227227
{
228-
return x => ((Delegate) x).DynamicInvoke(arguments);
228+
return x => ((Delegate)x).DynamicInvoke(arguments);
229229
}
230230
}
231231
}

src/NSubstitute/ClearOptions.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
namespace NSubstitute
44
{
5-
[Flags]
6-
public enum ClearOptions
7-
{
8-
/// <summary>
9-
/// Clear all the received calls
10-
/// </summary>
11-
ReceivedCalls = 1,
5+
[Flags]
6+
public enum ClearOptions
7+
{
8+
/// <summary>
9+
/// Clear all the received calls
10+
/// </summary>
11+
ReceivedCalls = 1,
1212

13-
/// <summary>
14-
/// Clear all configured return results (including auto-substituted values).
15-
/// </summary>
16-
ReturnValues = 2,
13+
/// <summary>
14+
/// Clear all configured return results (including auto-substituted values).
15+
/// </summary>
16+
ReturnValues = 2,
1717

18-
/// <summary>
19-
/// Clear all call actions configured for this substitute (via When..Do, Arg.Invoke, and Arg.Do)
20-
/// </summary>
21-
CallActions = 4,
18+
/// <summary>
19+
/// Clear all call actions configured for this substitute (via When..Do, Arg.Invoke, and Arg.Do)
20+
/// </summary>
21+
CallActions = 4,
2222

23-
/// <summary>
24-
/// Clears all received calls and configured return values and callbacks.
25-
/// </summary>
26-
All = ReceivedCalls | ReturnValues | CallActions
27-
}
23+
/// <summary>
24+
/// Clears all received calls and configured return values and callbacks.
25+
/// </summary>
26+
All = ReceivedCalls | ReturnValues | CallActions
27+
}
2828
}

src/NSubstitute/Core/Arguments/ArgumentFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ private string Format(object? arg)
1717
{
1818
return arg switch
1919
{
20-
null => "<null>",
21-
string str => $"\"{str}\"",
20+
null => "<null>",
21+
string str => $"\"{str}\"",
2222
{ } obj when HasDefaultToString(obj) => arg.GetType().GetNonMangledTypeName(),
23-
_ => arg.ToString() ?? string.Empty
23+
_ => arg.ToString() ?? string.Empty
2424
};
2525

2626
static bool HasDefaultToString(object obj)

src/NSubstitute/Core/Arguments/ArgumentMatchInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ public override bool Equals(object? obj)
3434
{
3535
if (ReferenceEquals(null, obj)) return false;
3636
if (ReferenceEquals(this, obj)) return true;
37-
if (obj.GetType() != typeof (ArgumentMatchInfo)) return false;
38-
return Equals((ArgumentMatchInfo) obj);
37+
if (obj.GetType() != typeof(ArgumentMatchInfo)) return false;
38+
return Equals((ArgumentMatchInfo)obj);
3939
}
4040

4141
public override int GetHashCode()
4242
{
4343
unchecked
4444
{
4545
int result = Index;
46-
result = (result*397) ^ (_argument != null ? _argument.GetHashCode() : 0);
47-
result = (result*397) ^ _specification.GetHashCode();
46+
result = (result * 397) ^ (_argument != null ? _argument.GetHashCode() : 0);
47+
result = (result * 397) ^ _specification.GetHashCode();
4848
return result;
4949
}
5050
}

src/NSubstitute/Core/Arguments/ArgumentMatcher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class ArgumentMatcher
1717
IArgumentMatcher nonGenericMatcher = argumentMatcher switch
1818
{
1919
IDescribeNonMatches => new GenericToNonGenericMatcherProxyWithDescribe<T>(argumentMatcher),
20-
_ => new GenericToNonGenericMatcherProxy<T>(argumentMatcher)
20+
_ => new GenericToNonGenericMatcherProxy<T>(argumentMatcher)
2121
};
2222

2323
return ref EnqueueArgSpecification<T>(new ArgumentSpecification(typeof(T), nonGenericMatcher));
@@ -44,7 +44,7 @@ public GenericToNonGenericMatcherProxy(IArgumentMatcher<T> matcher)
4444
_matcher = matcher;
4545
}
4646

47-
public bool IsSatisfiedBy(object? argument) => _matcher.IsSatisfiedBy((T?) argument!);
47+
public bool IsSatisfiedBy(object? argument) => _matcher.IsSatisfiedBy((T?)argument!);
4848
}
4949

5050
private class GenericToNonGenericMatcherProxyWithDescribe<T> : GenericToNonGenericMatcherProxy<T>, IDescribeNonMatches
@@ -54,7 +54,7 @@ public GenericToNonGenericMatcherProxyWithDescribe(IArgumentMatcher<T> matcher)
5454
if (matcher is not IDescribeNonMatches) throw new SubstituteInternalException("Should implement IDescribeNonMatches type.");
5555
}
5656

57-
public string DescribeFor(object? argument) => ((IDescribeNonMatches) _matcher).DescribeFor(argument);
57+
public string DescribeFor(object? argument) => ((IDescribeNonMatches)_matcher).DescribeFor(argument);
5858
}
5959

6060
private class DefaultValueContainer<T>

src/NSubstitute/Core/Arguments/ArrayContentsArgumentMatcher.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public bool IsSatisfiedBy(object? argument)
1717
{
1818
if (argument != null)
1919
{
20-
var argumentArray = ((IEnumerable) argument).Cast<object>().ToArray();
20+
var argumentArray = ((IEnumerable)argument).Cast<object>().ToArray();
2121
if (argumentArray.Length == _argumentSpecifications.Length)
2222
{
2323
return _argumentSpecifications
@@ -41,9 +41,10 @@ private IEnumerable<string> Format(object[] args, IArgumentSpecification[] specs
4141
{
4242
if (specs.Any() && !args.Any())
4343
{
44-
return new [] { "**" };
44+
return new[] { "**" };
4545
}
46-
return args.Select((arg, index) => {
46+
return args.Select((arg, index) =>
47+
{
4748
var hasSpecForThisArg = index < specs.Length;
4849
return hasSpecForThisArg ? specs[index].FormatArgument(arg) : ArgumentFormatter.Default.Format(arg, true);
4950
});

src/NSubstitute/Core/CallFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class CallFactory : ICallFactory
1010
{
1111
public ICall Create(MethodInfo methodInfo, object?[] arguments, object target, IList<IArgumentSpecification> argumentSpecifications, Func<object>? baseMethod)
1212
{
13-
return new Call(methodInfo, arguments, target, argumentSpecifications , baseMethod);
13+
return new Call(methodInfo, arguments, target, argumentSpecifications, baseMethod);
1414
}
1515

1616
public ICall Create(MethodInfo methodInfo, object?[] arguments, object target, IList<IArgumentSpecification> argumentSpecifications)

src/NSubstitute/Core/CallInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public T ArgAt<T>(int position)
114114

115115
try
116116
{
117-
return (T) _callArguments[position].Value!;
117+
return (T)_callArguments[position].Value!;
118118
}
119119
catch (InvalidCastException)
120120
{

0 commit comments

Comments
 (0)