Skip to content

Commit

Permalink
Enable SA1127
Browse files Browse the repository at this point in the history
References #23
  • Loading branch information
andreashuber-lawo committed May 2, 2016
1 parent 918d597 commit 0d53a67
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 48 deletions.
1 change: 0 additions & 1 deletion CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1637" Action="None" />
<Rule Id="SA1649" Action="None" />
<Rule Id="SA1127" Action="None" />
<Rule Id="SA1128" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1648" Action="None" />
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/CollectionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace Lawo.EmberPlusSharp.Model
/// </typeparam>
/// <threadsafety static="true" instance="false"/>
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance", Justification = "Fewer levels of inheritance would lead to more code duplication.")]
public sealed class CollectionNode<TElement> : Node<CollectionNode<TElement>> where TElement : IElement
public sealed class CollectionNode<TElement> : Node<CollectionNode<TElement>>
where TElement : IElement
{
private static readonly ReadContentsMethod ReadContentsCallback = GetReadContentsMethod();
private readonly ObservableCollection<TElement> children = new ObservableCollection<TElement>();
Expand Down
6 changes: 4 additions & 2 deletions Lawo.EmberPlusSharp/Model/Element1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace Lawo.EmberPlusSharp.Model
/// <see cref="Consumer{T}.Root">Consumer&lt;TRoot&gt;.Root</see>.</remarks>
/// <typeparam name="TMostDerived">The most-derived subtype of this class.</typeparam>
/// <threadsafety static="true" instance="false"/>
public abstract class Element<TMostDerived> : Element where TMostDerived : Element<TMostDerived>
public abstract class Element<TMostDerived> : Element
where TMostDerived : Element<TMostDerived>
{
private static readonly Func<TMostDerived> Constructor = GetConstructor();

Expand All @@ -44,7 +45,8 @@ internal int ReadInt(EmberReader reader, string fieldName)
}
}

internal T ReadEnum<T>(EmberReader reader, string fieldName) where T : struct
internal T ReadEnum<T>(EmberReader reader, string fieldName)
where T : struct
{
Exception exception = null;

Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/EnumParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace Lawo.EmberPlusSharp.Model
/// <typeparam name="TEnum">The enumeration type.</typeparam>
/// <threadsafety static="true" instance="false"/>
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance", Justification = "Fewer levels of inheritance would lead to more code duplication.")]
public sealed class EnumParameter<TEnum> : ValueParameter<EnumParameter<TEnum>, TEnum> where TEnum : struct
public sealed class EnumParameter<TEnum> : ValueParameter<EnumParameter<TEnum>, TEnum>
where TEnum : struct
{
private readonly EnumParameterImpl<TEnum> impl;

Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/EnumParameterImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Lawo.EmberPlusSharp.Model

using Ember;

internal sealed class EnumParameterImpl<TEnum> where TEnum : struct
internal sealed class EnumParameterImpl<TEnum>
where TEnum : struct
{
private static readonly bool IsEnum = typeof(TEnum).GetTypeInfo().IsEnum;
private readonly IParameter parent;
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace Lawo.EmberPlusSharp.Model
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <threadsafety static="true" instance="false"/>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Function", Justification = "Intentional, usability from other languages is not a priority.")]
public sealed class Function<TResult> : StaticFunction<Function<TResult>> where TResult : ResultBase<TResult>, new()
public sealed class Function<TResult> : StaticFunction<Function<TResult>>
where TResult : ResultBase<TResult>, new()
{
/// <summary>Schedules an invocation of this function.</summary>
/// <exception cref="InvocationFailedException">The provider reported that the invocation failed.</exception>
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/FunctionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ internal FunctionBase(
this.result = result;
}

internal Task<TResult> InvokeCoreAsync<TResult>(
TResult invokeResult, params Action<EmberWriter>[] writers) where TResult : ResultBase<TResult>
internal Task<TResult> InvokeCoreAsync<TResult>(TResult invokeResult, params Action<EmberWriter>[] writers)
where TResult : ResultBase<TResult>
{
this.invocations.Enqueue(new KeyValuePair<IInvocationResult, Action<EmberWriter>[]>(invokeResult, writers));
this.HasChanges = true;
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/MetaElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Lawo.EmberPlusSharp.Model
using Ember;

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:PartialElementsMustBeDocumented", Justification = "Temporary, TODO")]
public abstract partial class FieldNode<TMostDerived> where TMostDerived : FieldNode<TMostDerived>
public abstract partial class FieldNode<TMostDerived>
where TMostDerived : FieldNode<TMostDerived>
{
private abstract class MetaElement
{
Expand Down
6 changes: 4 additions & 2 deletions Lawo.EmberPlusSharp/Model/MetaElement1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ namespace Lawo.EmberPlusSharp.Model
using Ember;

[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601:PartialElementsMustBeDocumented", Justification = "Temporary, TODO")]
public abstract partial class FieldNode<TMostDerived> where TMostDerived : FieldNode<TMostDerived>
public abstract partial class FieldNode<TMostDerived>
where TMostDerived : FieldNode<TMostDerived>
{
private sealed class MetaElement<TProperty> : MetaElement where TProperty : Element<TProperty>
private sealed class MetaElement<TProperty> : MetaElement
where TProperty : Element<TProperty>
{
private readonly Func<TMostDerived, TProperty> get;
private readonly Action<TMostDerived, TProperty> set;
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/ResultBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace Lawo.EmberPlusSharp.Model
/// <see cref="Consumer{T}.Root">Consumer&lt;TRoot&gt;.Root</see>.</remarks>
/// <typeparam name="TMostDerived">The most-derived subtype of this class.</typeparam>
/// <threadsafety static="true" instance="false"/>
public abstract class ResultBase<TMostDerived> : IInvocationResult where TMostDerived : ResultBase<TMostDerived>
public abstract class ResultBase<TMostDerived> : IInvocationResult
where TMostDerived : ResultBase<TMostDerived>
{
private readonly IValueReader[] valueReaders;
private readonly TaskCompletionSource<TMostDerived> taskCompletionSource =
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/Model/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace Lawo.EmberPlusSharp.Model
/// </remarks>
/// <threadsafety static="true" instance="false"/>
[SuppressMessage("Microsoft.Maintainability", "CA1501:AvoidExcessiveInheritance", Justification = "Fewer levels of inheritance would lead to more code duplication.")]
public abstract class Root<TMostDerived> : FieldNode<TMostDerived>, IParent where TMostDerived : Root<TMostDerived>
public abstract class Root<TMostDerived> : FieldNode<TMostDerived>, IParent
where TMostDerived : Root<TMostDerived>
{
/// <inheritdoc/>
void IParent.SetHasChanges()
Expand Down
3 changes: 2 additions & 1 deletion Lawo.EmberPlusSharp/S101/S101Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ await this.EnqueueLogOperation(
this.OnEvent(this.OutOfFrameByteReceived, e);
}

private void OnEvent<TEventArgs>(EventHandler<TEventArgs> handler, TEventArgs args) where TEventArgs : EventArgs
private void OnEvent<TEventArgs>(EventHandler<TEventArgs> handler, TEventArgs args)
where TEventArgs : EventArgs
{
if (handler != null)
{
Expand Down
6 changes: 4 additions & 2 deletions Lawo.EmberPlusSharpTest/Ember/CompatibilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ private void AssertEqual<T>(Action<EmberWriter, EmberId, T> write, Func<EmberLib
}

private void CollectionAssertEqual<T>(
Action<EmberWriter, EmberId, T> write, Func<EmberLib.EmberReader, T> read, T value) where T : ICollection
Action<EmberWriter, EmberId, T> write, Func<EmberLib.EmberReader, T> read, T value)
where T : ICollection
{
this.AssertEqual(write, read, value, (l, r) => CollectionAssert.AreEqual(l, r));
}
Expand All @@ -128,7 +129,8 @@ private void AssertEqual<T>(Action<EmberLib.EmberWriter, BerTag, T> write, Func<
}

private void CollectionAssertEqual<T>(
Action<EmberLib.EmberWriter, BerTag, T> write, Func<EmberReader, T> read, T value) where T : ICollection
Action<EmberLib.EmberWriter, BerTag, T> write, Func<EmberReader, T> read, T value)
where T : ICollection
{
this.AssertEqual(write, read, value, (l, r) => CollectionAssert.AreEqual(l, r));
}
Expand Down
18 changes: 12 additions & 6 deletions Lawo.EmberPlusSharpTest/Model/ConsumerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,8 @@ private Task StreamTestCore(
private static Task TestConsumerAfterFirstRequest<TRoot>(
Func<Task<Consumer<TRoot>>, S101Client, Task> testCallback,
IS101Logger consumerLogger,
IS101Logger providerLogger) where TRoot : Root<TRoot>
IS101Logger providerLogger)
where TRoot : Root<TRoot>
{
return TestNoExceptionsAsync(
async (consumerClient, providerClient) =>
Expand Down Expand Up @@ -1538,7 +1539,8 @@ private static void AssertAreEqual<TValue, TElement>(
}

private static void AssertNotified<TType, TProperty>(
TType obj, Expression<Func<TType, TProperty>> getValue, TProperty value) where TType : INotifyPropertyChanged
TType obj, Expression<Func<TType, TProperty>> getValue, TProperty value)
where TType : INotifyPropertyChanged
{
var propertyInfo = (PropertyInfo)((MemberExpression)getValue.Body).Member;
Assert.AreNotEqual(value, propertyInfo.GetValue(obj));
Expand Down Expand Up @@ -1673,7 +1675,8 @@ private static Task WaitForCompletion(Consumer<EmptyNodeRoot> consumer, bool del

[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Objects are disposed within the called method.")]
private static Task TestWithRobot<TRoot>(
Func<Consumer<TRoot>, Task> testCallback, bool log, string logXmlName, params object[] args) where TRoot : Root<TRoot>
Func<Consumer<TRoot>, Task> testCallback, bool log, string logXmlName, params object[] args)
where TRoot : Root<TRoot>
{
return TestWithRobot<ModelPayloads>(
client => MonitorConnection(Consumer<TRoot>.CreateAsync(client, 4000), c => testCallback(c)),
Expand Down Expand Up @@ -1714,7 +1717,8 @@ await AssertThrowAsync<TException>(
[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", Justification = "Test code.")]
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Test code.")]
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", Justification = "Test code.")]
private static async Task BigTreeAssemblyTestCore<TRoot>(int magnitude, bool writeLog) where TRoot : Root<TRoot>
private static async Task BigTreeAssemblyTestCore<TRoot>(int magnitude, bool writeLog)
where TRoot : Root<TRoot>
{
var encodedPayloadStream = await GetS101MessageStreamAsync(GetBigTreePayload(magnitude));
var encodedPayload = encodedPayloadStream.ToArray();
Expand Down Expand Up @@ -1874,7 +1878,8 @@ private static void CheckNumbers(MainRoot root)
root.CollectionNode[root.CollectionNode.Children[2].Number], root.CollectionNode.Children[2]);
}

private static TRoot GetRoot<TRoot>(string logXmlName) where TRoot : Root<TRoot>
private static TRoot GetRoot<TRoot>(string logXmlName)
where TRoot : Root<TRoot>
{
TRoot root = null;
AsyncPump.Run(
Expand All @@ -1883,7 +1888,8 @@ private static TRoot GetRoot<TRoot>(string logXmlName) where TRoot : Root<TRoot>
}

private static void AssertEqual<TCollectionNode>(
MainRoot mainRoot, InterfaceElementRoot<TCollectionNode> interfaceRoot) where TCollectionNode : INode
MainRoot mainRoot, InterfaceElementRoot<TCollectionNode> interfaceRoot)
where TCollectionNode : INode
{
Assert.AreEqual(mainRoot.BooleanParameter.Value, interfaceRoot.BooleanParameter.Value);
Assert.AreEqual(mainRoot.IntegerParameter.Value, interfaceRoot.IntegerParameter.Value);
Expand Down
9 changes: 6 additions & 3 deletions Lawo.EmberPlusSharpTest/S101/CommunicationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected static Task TestWithRobot<TResourceNamespace>(
protected static Task TestNoExceptionsAsync<TConsumer>(
Func<TConsumer, S101Client, Task> testCallback,
Func<Task<TConsumer>> createConsumer,
Func<Task<S101Client>> createProvider) where TConsumer : IMonitoredConnection
Func<Task<S101Client>> createProvider)
where TConsumer : IMonitoredConnection
{
return TestNoExceptionsAsync(
(ct, p) => MonitorConnection(ct, c => testCallback(c, p)), createConsumer, createProvider);
Expand All @@ -126,7 +127,8 @@ protected static Task TestNoExceptionsAsync<TConsumer>(
protected static Task TestNoExceptionsAsync<TConsumer>(
Func<Task<TConsumer>, S101Client, Task> testCallback,
Func<Task<TConsumer>> createConsumer,
Func<Task<S101Client>> createProvider) where TConsumer : IMonitoredConnection
Func<Task<S101Client>> createProvider)
where TConsumer : IMonitoredConnection
{
var providerTask = createProvider();
var consumerTask = createConsumer();
Expand Down Expand Up @@ -234,7 +236,8 @@ protected static async Task<MemoryStream> GetS101MessageStreamAsync(byte[] paylo
/// <typeparam name="TConnection">The type of the connection.</typeparam>
protected static async Task MonitorConnection<TConnection>(
Task<TConnection> connectionTask,
Func<TConnection, Task> callback) where TConnection : IMonitoredConnection
Func<TConnection, Task> callback)
where TConnection : IMonitoredConnection
{
Task waitForConnectionLost;

Expand Down
18 changes: 12 additions & 6 deletions Lawo.UnitTesting/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public abstract class TestBase
/// expected exception. Note: this exception is deliberately inaccessible to client code, so that it cannot be
/// caught.</exception>
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "There's no clean way around a type parameter here.")]
public static void AssertThrow<TException>(params Action[] actions) where TException : Exception
public static void AssertThrow<TException>(params Action[] actions)
where TException : Exception
{
AssertThrowCore<TException>(actions, null);
}
Expand All @@ -54,7 +55,8 @@ public static void AssertThrow<TException>(params Action[] actions) where TExcep
/// expected exception. Note: this exception is deliberately inaccessible to client code, so that it cannot be
/// caught.</exception>
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "There's no clean way around a type parameter here.")]
public static void AssertThrow<TException>(Action action, string expectedMessage) where TException : Exception
public static void AssertThrow<TException>(Action action, string expectedMessage)
where TException : Exception
{
AssertThrowCore<TException>(new[] { action }, expectedMessage);
}
Expand All @@ -68,7 +70,8 @@ public static void AssertThrow<TException>(Action action, string expectedMessage
/// expected exception. Note: this exception is deliberately inaccessible to client code, so that it cannot be
/// caught.</exception>
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "There's no clean way around a type parameter here.")]
public static Task AssertThrowAsync<TException>(params Func<Task>[] actions) where TException : Exception
public static Task AssertThrowAsync<TException>(params Func<Task>[] actions)
where TException : Exception
{
return AssertThrowCoreAsync<TException>(actions, null);
}
Expand Down Expand Up @@ -98,7 +101,8 @@ public static Task AssertThrowAsync<TException>(Func<Task> action, string expect
/// <exception cref="Exception">Some of the expected methods are not present. See message for more information.
/// </exception>
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "There's no clean way around a type parameter here.")]
public static void TestStandardExceptionConstructors<T>() where T : Exception, new()
public static void TestStandardExceptionConstructors<T>()
where T : Exception, new()
{
T innerException = new T();
CheckPropagation(innerException, null, null);
Expand All @@ -116,7 +120,8 @@ public static Task AssertThrowAsync<TException>(Func<Task> action, string expect
/// <param name="equal">References the equality operator.</param>
/// <param name="notEqual">References the inequality operator.</param>
public static void TestStructEquality<T>(
T obj1, T obj2, Func<T, T, bool> equal, Func<T, T, bool> notEqual) where T : struct, IEquatable<T>
T obj1, T obj2, Func<T, T, bool> equal, Func<T, T, bool> notEqual)
where T : struct, IEquatable<T>
{
if (equal == null)
{
Expand Down Expand Up @@ -153,7 +158,8 @@ public static void TestStructEquality<T>(
/// <typeparam name="TProperty">The type of the property.</typeparam>
/// <returns>The new value of the property.</returns>
public static async Task<TProperty> WaitForChangeAsync<TOwner, TProperty>(
IProperty<TOwner, TProperty> property, TProperty expected) where TOwner : INotifyPropertyChanged
IProperty<TOwner, TProperty> property, TProperty expected)
where TOwner : INotifyPropertyChanged
{
Predicate<TProperty> predicate = v => GenericCompare.Equals(expected, v);

Expand Down
3 changes: 2 additions & 1 deletion Lawo/ComponentModel/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public static IDisposable Create<TOwner, TProperty>(

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private sealed class Forwarder<TOwner, TProperty> : IDisposable where TOwner : INotifyPropertyChanged
private sealed class Forwarder<TOwner, TProperty> : IDisposable
where TOwner : INotifyPropertyChanged
{
private readonly IProperty<TOwner, TProperty> property;
private readonly Action<IProperty<TOwner, TProperty>> handler;
Expand Down
Loading

0 comments on commit 0d53a67

Please sign in to comment.