Skip to content

Commit

Permalink
Merge pull request serilog#1042 from tsimbalar/resharper-green-again
Browse files Browse the repository at this point in the history
Make Resharper green again
  • Loading branch information
nblumhardt authored Oct 19, 2017
2 parents 8528ae3 + f41eaf1 commit c10e625
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions Serilog.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleNullReferenceException/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PossibleUnintendedReferenceComparison/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=PrivateFieldCanBeConvertedToLocalVariable/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantArgumentDefaultValue/@EntryIndexedValue">SUGGESTION</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantAssignment/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBaseConstructorCall/@EntryIndexedValue">ERROR</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=RedundantBoolCompare/@EntryIndexedValue">ERROR</s:String>
Expand Down
1 change: 1 addition & 0 deletions src/Serilog/Capturing/PropertyValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ bool TryConvertValueTuple(object value, Destructuring destructuring, Type valueT
definition == typeof(ValueTuple<,,,,>) || definition == typeof(ValueTuple<,,,,,>) ||
definition == typeof(ValueTuple<,,,,,,>))
#else
// ReSharper disable once PossibleNullReferenceException
var defn = definition.FullName;
if (defn == "System.ValueTuple`1" || defn == "System.ValueTuple`2" ||
defn == "System.ValueTuple`3" || defn == "System.ValueTuple`4" ||
Expand Down
2 changes: 2 additions & 0 deletions src/Serilog/Context/LogContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public DisposableObjectHandle(object o) : base(o)
public override object InitializeLifetimeService()
{
var lease = (ILease)base.InitializeLifetimeService();
// ReSharper disable once PossibleNullReferenceException
// not 100% sure this will never occur ...
lease.Register(LifeTimeSponsor);
return lease;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Serilog/Core/Pipeline/MessageTemplateCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public MessageTemplate Parse(string messageTemplate)
return _innerParser.Parse(messageTemplate);

#if HASHTABLE
// ReSharper disable once InconsistentlySynchronizedField
// ignored warning because this is by design
var result = (MessageTemplate)_templates[messageTemplate];
if (result != null)
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where matchCallables.IsMatch(wt.Key)

if (callableDirectives.Any())
{
var configurationAssemblies = LoadConfigurationAssemblies(directives);
var configurationAssemblies = LoadConfigurationAssemblies(directives).ToList();

foreach (var receiverGroup in callableDirectives.GroupBy(d => d.ReceiverType))
{
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Tests/Capturing/PropertyValueConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PropertyValueConverterTests
[Fact]
public async Task MaximumDepthIsEffectiveAndThreadSafe()
{
var _converter = new PropertyValueConverter(3, 1000, 1000, Enumerable.Empty<Type>(), Enumerable.Empty<IDestructuringPolicy>(), false);
var converter = new PropertyValueConverter(3, 1000, 1000, Enumerable.Empty<Type>(), Enumerable.Empty<IDestructuringPolicy>(), false);

var barrier = new Barrier(participantCount: 3);

Expand Down Expand Up @@ -63,7 +63,7 @@ void DoThreadTest(object logObject, Action<string> assertAction)
{
barrier.SignalAndWait();

var propValue = _converter.CreatePropertyValue(logObject, true);
var propValue = converter.CreatePropertyValue(logObject, true);

Assert.IsType<StructureValue>(propValue);

Expand Down
6 changes: 5 additions & 1 deletion test/Serilog.Tests/Context/LogContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static LogContextTests()
public LogContextTests()
{
#if REMOTING
// ReSharper disable AssignNullToNotNullAttribute
CallContext.LogicalSetData(typeof(LogContext).FullName, null);
// ReSharper restore AssignNullToNotNullAttribute
#endif
}

Expand Down Expand Up @@ -266,7 +268,9 @@ public void DoesNotPreventCrossDomainCalls()
{
domain = AppDomain.CreateDomain("LogContextTests", null, AppDomain.CurrentDomain.SetupInformation);

// ReSharper disable AssignNullToNotNullAttribute
var callable = (RemotelyCallable)domain.CreateInstanceAndUnwrap(typeof(RemotelyCallable).Assembly.FullName, typeof(RemotelyCallable).FullName);
// ReSharper restore AssignNullToNotNullAttribute

using (LogContext.PushProperty("Anything", 1001))
Assert.True(callable.IsCallable());
Expand Down Expand Up @@ -381,4 +385,4 @@ public bool IsCallable()
}
}
#endif
}
}
17 changes: 6 additions & 11 deletions test/Serilog.Tests/MethodOverloadConventionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,7 @@ public void ValidateIsEnabledMethods(Type loggerType)
Assert.Equal(parameter.Name, "level");
Assert.Equal(parameter.ParameterType, typeof(LogEventLevel));

CollectingSink sink;

var logger = GetLogger(loggerType, out sink, LogEventLevel.Information);
var logger = GetLogger(loggerType, out _, LogEventLevel.Information);

var falseResult = InvokeMethod(method, logger, new object[] { LogEventLevel.Verbose });

Expand Down Expand Up @@ -503,6 +501,7 @@ void ForContextMethod4(MethodInfo method)
TestForContextResult(method, logger, normalResult: enrichedLogger);
}

// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
void TestForContextResult(MethodInfo method, ILogger logger, object normalResult)
{
Assert.NotNull(normalResult);
Expand Down Expand Up @@ -761,10 +760,7 @@ static void InvokeConventionMethod(

static void InvokeConventionMethod(MethodInfo method, Type[] typeArgs, object[] parameters)
{
CollectingSink sink;
LogEventLevel level;

InvokeConventionMethod(method, typeArgs, parameters, out level, out sink);
InvokeConventionMethod(method, typeArgs, parameters, out _, out _);
}

static void InvokeConventionMethodAndTest(MethodInfo method, Type[] typeArgs, object[] parameters)
Expand Down Expand Up @@ -889,6 +885,7 @@ static object InvokeMethod(
return method.Invoke(instance, parameters);
}

// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
static void EvaluateSingleResult(LogEventLevel level, CollectingSink results)
{
//evaluate single log event
Expand All @@ -901,9 +898,7 @@ static void EvaluateSingleResult(LogEventLevel level, CollectingSink results)

static ILogger GetLogger(Type loggerType)
{
CollectingSink sink;

return GetLogger(loggerType, out sink);
return GetLogger(loggerType, out _);
}

static ILogger GetLogger(Type loggerType, out CollectingSink sink, LogEventLevel level = LogEventLevel.Verbose)
Expand Down Expand Up @@ -940,4 +935,4 @@ static ILogger GetLogger(Type loggerType, out CollectingSink sink, LogEventLevel
throw new ArgumentException($"Logger Type of {loggerType} is not supported");
}
}
}
}
1 change: 1 addition & 0 deletions test/Serilog.Tests/Parsing/MessageTemplateParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static MessageTemplateToken[] Parse(string messsageTemplate)
return new MessageTemplateParser().Parse(messsageTemplate).Tokens.ToArray();
}

// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
static void AssertParsedAs(string message, params MessageTemplateToken[] messageTemplateTokens)
{
var parsed = Parse(message);
Expand Down
2 changes: 2 additions & 0 deletions test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,14 @@ public void LoggingLevelSwitchCanBeUsedForMinimumLevelOverrides()
systemLogger.Write(Some.WarningEvent());
Assert.False(evt is null, "LoggingLevelSwitch initial level was Warning for logger System.*. It should log Warning messages for SourceContext System.Bar");

// ReSharper disable HeuristicUnreachableCode
evt = null;
var controlSwitch = DummyWithLevelSwitchSink.ControlLevelSwitch;

controlSwitch.MinimumLevel = LogEventLevel.Information;
systemLogger.Write(Some.InformationEvent());
Assert.False(evt is null, "LoggingLevelSwitch level was changed to Information for logger System.*. It should now log Information events for SourceContext System.Bar.");
// ReSharper restore HeuristicUnreachableCode
}

}
Expand Down
4 changes: 2 additions & 2 deletions test/Serilog.Tests/Settings/SettingValueConversionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void EmptyStringValuesConvertToNullIfTargetIsNullable()
[Fact]
public void ValuesConvertToNullableTimeSpan()
{
var result = (System.TimeSpan?)SettingValueConversions.ConvertToType("00:01:00", typeof(System.TimeSpan?));
Assert.Equal(System.TimeSpan.FromMinutes(1), result);
var result = (TimeSpan?)SettingValueConversions.ConvertToType("00:01:00", typeof(TimeSpan?));
Assert.Equal(TimeSpan.FromMinutes(1), result);
}

[Fact]
Expand Down
2 changes: 2 additions & 0 deletions test/TestDummies/DummyRollingFileAuditSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace TestDummies
public class DummyRollingFileAuditSink : ILogEventSink
{
[ThreadStatic]
// ReSharper disable ThreadStaticFieldHasInitializer
public static List<LogEvent> Emitted = new List<LogEvent>();
// ReSharper restore ThreadStaticFieldHasInitializer

public void Emit(LogEvent logEvent)
{
Expand Down
2 changes: 2 additions & 0 deletions test/TestDummies/DummyRollingFileSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace TestDummies
public class DummyRollingFileSink : ILogEventSink
{
[ThreadStatic]
// ReSharper disable ThreadStaticFieldHasInitializer
public static List<LogEvent> Emitted = new List<LogEvent>();
// ReSharper restore ThreadStaticFieldHasInitializer

public void Emit(LogEvent logEvent)
{
Expand Down
2 changes: 2 additions & 0 deletions test/TestDummies/DummyWithLevelSwitchSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public DummyWithLevelSwitchSink(LoggingLevelSwitch loggingControlLevelSwitch)
public static LoggingLevelSwitch ControlLevelSwitch;

[ThreadStatic]
// ReSharper disable ThreadStaticFieldHasInitializer
public static List<LogEvent> Emitted = new List<LogEvent>();
// ReSharper restore ThreadStaticFieldHasInitializer

public void Emit(LogEvent logEvent)
{
Expand Down
4 changes: 3 additions & 1 deletion test/TestDummies/DummyWrappingSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace TestDummies
public class DummyWrappingSink : ILogEventSink
{
[ThreadStatic]
// ReSharper disable ThreadStaticFieldHasInitializer
public static List<LogEvent> Emitted = new List<LogEvent>();
// ReSharper restore ThreadStaticFieldHasInitializer

private readonly ILogEventSink _sink;

Expand All @@ -23,4 +25,4 @@ public void Emit(LogEvent logEvent)
_sink.Emit(logEvent);
}
}
}
}

0 comments on commit c10e625

Please sign in to comment.