From 01fd7a3ca8a9d153f3d7f13a4bd4770a7943f65c Mon Sep 17 00:00:00 2001 From: Glenn <5834289+glennawatson@users.noreply.github.com> Date: Mon, 5 Apr 2021 20:34:07 +1000 Subject: [PATCH 1/2] housekeeping: Use editorconfig for analyzer settings (#691) Fix all outstanding warnings --- src/Directory.build.props | 4 +- .../AutofacDependencyResolver.cs | 4 +- ...alTests.SplatUIProject.net5.0.approved.txt | 2 +- ....SplatUIProject.netcoreapp3.1.approved.txt | 2 +- .../Cocoa/Bitmaps/PlatformBitmapLoader.cs | 6 +- .../WinRT/Bitmaps/PlatformBitmapLoader.cs | 4 +- .../net4/Bitmaps/PlatformBitmapLoader.cs | 4 +- .../net5/Bitmaps/PlatformBitmapLoader.cs | 4 +- .../Bitmaps/PlatformBitmapLoader.cs | 4 +- ...xceptionlessFeatureUsageTrackingSession.cs | 4 +- .../MicrosoftDependencyResolver.cs | 2 +- src/Splat.NLog/NLogLogger.cs | 40 +-- src/Splat.Prism.Forms/PrismApplication.cs | 2 +- src/Splat.Prism/SplatContainerExtension.cs | 5 + .../RaygunFeatureUsageTrackingSession.cs | 4 +- src/Splat.Serilog/SerilogFullLogger.cs | 60 ++-- .../SimpleInjectorDependencyResolver.cs | 15 +- .../SimpleInjectorInitializer.cs | 28 +- .../Splat.SimpleInjector.csproj | 3 +- .../TransientSimpleInjectorRegistration.cs | 2 +- ...ovalTests.SplatProject.net5.0.approved.txt | 8 +- ...ts.SplatProject.netcoreapp3.1.approved.txt | 8 +- src/Splat.Tests/ApiExtensions.cs | 2 +- ...ableFeatureUsageTrackingExtensionsTests.cs | 1 + .../Logging/Helpers/FormatHelper.cs | 1 + src/Splat.Tests/Logging/StaticLoggerTests.cs | 2 - src/Splat.sln | 5 +- .../EnableFeatureUsageTrackingExtensions.cs | 17 +- src/Splat/Logging/AllocationFreeLoggerBase.cs | 16 +- src/Splat/Logging/LogHost.cs | 2 +- src/Splat/Logging/LogLevel.cs | 1 + src/Splat/MemoizingMRUCache.cs | 8 +- src/Splat/ServiceLocation/Locator.cs | 1 + src/analyzers.ruleset | 282 ------------------ 34 files changed, 148 insertions(+), 405 deletions(-) delete mode 100644 src/analyzers.ruleset diff --git a/src/Directory.build.props b/src/Directory.build.props index a2c6d54d4..76f3a581a 100644 --- a/src/Directory.build.props +++ b/src/Directory.build.props @@ -5,8 +5,6 @@ AnyCPU $(MSBuildProjectName.Contains('Tests')) embedded - $(MSBuildThisFileDirectory)analyzers.ruleset - .NET Foundation and Contributors Copyright (c) .NET Foundation and Contributors MIT @@ -68,7 +66,7 @@ - + diff --git a/src/Splat.Autofac/AutofacDependencyResolver.cs b/src/Splat.Autofac/AutofacDependencyResolver.cs index 364854e0b..6c41b5e27 100644 --- a/src/Splat.Autofac/AutofacDependencyResolver.cs +++ b/src/Splat.Autofac/AutofacDependencyResolver.cs @@ -71,7 +71,7 @@ public void SetLifetimeScope(ILifetimeScope lifetimeScope) { if (_lifetimeScopeSet) { - throw new Exception("Lifetime scope of the Autofac resolver has already been set"); + throw new InvalidOperationException("Lifetime scope of the Autofac resolver has already been set"); } _lifetimeScopeSet = true; @@ -135,7 +135,7 @@ public virtual void Register(Func factory, Type serviceType, string cont { if (_lifetimeScopeSet) { - throw new Exception("Container has already been built and the lifetime scope set, so it is not possible to modify it anymore."); + throw new InvalidOperationException("Container has already been built and the lifetime scope set, so it is not possible to modify it anymore."); } // We register every ReactiveUI service twice. diff --git a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.net5.0.approved.txt b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.net5.0.approved.txt index ff4c5127a..c855326e7 100644 --- a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.net5.0.approved.txt +++ b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.net5.0.approved.txt @@ -239,7 +239,7 @@ namespace Splat public PlatformBitmapLoader() { } public Splat.IBitmap Create(float width, float height) { } public System.Threading.Tasks.Task Load(System.IO.Stream sourceStream, float? desiredWidth, float? desiredHeight) { } - public System.Threading.Tasks.Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) { } + public System.Threading.Tasks.Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { } } public static class PlatformModeDetector { diff --git a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.netcoreapp3.1.approved.txt b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.netcoreapp3.1.approved.txt index c324598db..b2cc9248c 100644 --- a/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.netcoreapp3.1.approved.txt +++ b/src/Splat.Drawing.Tests/API/ApiApprovalTests.SplatUIProject.netcoreapp3.1.approved.txt @@ -237,7 +237,7 @@ namespace Splat public PlatformBitmapLoader() { } public Splat.IBitmap Create(float width, float height) { } public System.Threading.Tasks.Task Load(System.IO.Stream sourceStream, float? desiredWidth, float? desiredHeight) { } - public System.Threading.Tasks.Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) { } + public System.Threading.Tasks.Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { } } public static class PlatformModeDetector { diff --git a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs index cdc0389e1..c44b87a35 100644 --- a/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/Cocoa/Bitmaps/PlatformBitmapLoader.cs @@ -41,7 +41,7 @@ public Task Load(Stream sourceStream, float? desiredWidth, float? desir var bitmap = UIImage.LoadFromData(data); if (bitmap == null) { - throw new Exception("Failed to load image"); + throw new InvalidOperationException("Failed to load image"); } tcs.TrySetResult(new CocoaBitmap(bitmap)); @@ -72,7 +72,7 @@ public Task LoadFromResource(string source, float? desiredWidth, float? var bitmap = UIImage.FromBundle(source); if (bitmap == null) { - throw new Exception("Failed to load image from resource: " + source); + throw new InvalidOperationException("Failed to load image from resource: " + source); } tcs.TrySetResult(new CocoaBitmap(bitmap)); @@ -91,7 +91,7 @@ public Task LoadFromResource(string source, float? desiredWidth, float? var bitmap = UIImage.ImageNamed(source); if (bitmap == null) { - throw new Exception("Failed to load image from resource: " + source); + throw new InvalidOperationException("Failed to load image from resource: " + source); } tcs.TrySetResult(new CocoaBitmap(bitmap)); diff --git a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs index 3fd4054d0..ed4a055c7 100644 --- a/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/WinRT/Bitmaps/PlatformBitmapLoader.cs @@ -62,11 +62,11 @@ public Task Load(Stream sourceStream, float? desiredWidth, float? desir } /// - public Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { return GetDispatcher().RunTaskAsync(async () => { - var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(resource)); + var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(source)); using (var stream = await file.OpenAsync(FileAccessMode.Read)) { return await Load(stream.AsStreamForRead(), desiredWidth, desiredHeight).ConfigureAwait(false); diff --git a/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs index 7fab9d4ed..48a35b5a3 100644 --- a/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/net4/Bitmaps/PlatformBitmapLoader.cs @@ -44,7 +44,7 @@ public Task Load(Stream sourceStream, float? desiredWidth, float? desir } /// - public Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { return Task.Run(() => { @@ -61,7 +61,7 @@ public Task LoadFromResource(string resource, float? desiredWidth, floa x.DecodePixelHeight = (int)desiredHeight; } - x.UriSource = new Uri(resource, UriKind.RelativeOrAbsolute); + x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); }); return (IBitmap)new BitmapSourceBitmap(ret); diff --git a/src/Splat.Drawing/Platforms/net5/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/net5/Bitmaps/PlatformBitmapLoader.cs index 40a3acde1..238514813 100644 --- a/src/Splat.Drawing/Platforms/net5/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/net5/Bitmaps/PlatformBitmapLoader.cs @@ -44,7 +44,7 @@ public Task Load(Stream sourceStream, float? desiredWidth, float? desir } /// - public Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { return Task.Run(() => { @@ -61,7 +61,7 @@ public Task LoadFromResource(string resource, float? desiredWidth, floa x.DecodePixelHeight = (int)desiredHeight; } - x.UriSource = new Uri(resource, UriKind.RelativeOrAbsolute); + x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); }); return (IBitmap)new BitmapSourceBitmap(ret); diff --git a/src/Splat.Drawing/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs b/src/Splat.Drawing/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs index 40a3acde1..238514813 100644 --- a/src/Splat.Drawing/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs +++ b/src/Splat.Drawing/Platforms/netcoreapp3/Bitmaps/PlatformBitmapLoader.cs @@ -44,7 +44,7 @@ public Task Load(Stream sourceStream, float? desiredWidth, float? desir } /// - public Task LoadFromResource(string resource, float? desiredWidth, float? desiredHeight) + public Task LoadFromResource(string source, float? desiredWidth, float? desiredHeight) { return Task.Run(() => { @@ -61,7 +61,7 @@ public Task LoadFromResource(string resource, float? desiredWidth, floa x.DecodePixelHeight = (int)desiredHeight; } - x.UriSource = new Uri(resource, UriKind.RelativeOrAbsolute); + x.UriSource = new Uri(source, UriKind.RelativeOrAbsolute); }); return (IBitmap)new BitmapSourceBitmap(ret); diff --git a/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs b/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs index 2f17f48e3..088c7c081 100644 --- a/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs +++ b/src/Splat.Exceptionless/ExceptionlessFeatureUsageTrackingSession.cs @@ -58,10 +58,10 @@ internal ExceptionlessFeatureUsageTrackingSession( public string FeatureName { get; } /// - public IFeatureUsageTrackingSession SubFeature(string name) + public IFeatureUsageTrackingSession SubFeature(string description) { return new ExceptionlessFeatureUsageTrackingSession( - name, + description, FeatureReference); } diff --git a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs index d63f7ac9e..4c20bb50d 100644 --- a/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs +++ b/src/Splat.Microsoft.Extensions.DependencyInjection/MicrosoftDependencyResolver.cs @@ -323,7 +323,7 @@ private ContractDictionary GetContractDictionary(Type serviceType, bool createIf { lock (_syncLock) { - if (createIfNotExists && dic == null) + if (createIfNotExists) { dic = (ContractDictionary)Activator.CreateInstance(dicType); _serviceCollection.AddSingleton(dicType, dic); diff --git a/src/Splat.NLog/NLogLogger.cs b/src/Splat.NLog/NLogLogger.cs index 55317c02b..4f46357b5 100644 --- a/src/Splat.NLog/NLogLogger.cs +++ b/src/Splat.NLog/NLogLogger.cs @@ -94,15 +94,15 @@ public void Write(Exception exception, string message, Type type, LogLevel logLe } /// - public void Debug(string message, TArgument argument) + public void Debug(string message, TArgument args) { - _inner.Debug(CultureInfo.InvariantCulture, message, argument); + _inner.Debug(CultureInfo.InvariantCulture, message, args); } /// - public void Debug(string message, TArgument1 argument1, TArgument2 argument2) + public void Debug(string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _inner.Debug(CultureInfo.InvariantCulture, message, argument1, argument2); + _inner.Debug(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); } /// @@ -154,15 +154,15 @@ public void Debug - public void Info(string message, TArgument argument) + public void Info(string message, TArgument args) { - _inner.Info(CultureInfo.InvariantCulture, message, argument); + _inner.Info(CultureInfo.InvariantCulture, message, args); } /// - public void Info(string message, TArgument1 argument1, TArgument2 argument2) + public void Info(string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _inner.Info(CultureInfo.InvariantCulture, message, argument1, argument2); + _inner.Info(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); } /// @@ -214,15 +214,15 @@ public void Info - public void Warn(string message, TArgument argument) + public void Warn(string message, TArgument args) { - _inner.Warn(CultureInfo.InvariantCulture, message, argument); + _inner.Warn(CultureInfo.InvariantCulture, message, args); } /// - public void Warn(string message, TArgument1 argument1, TArgument2 argument2) + public void Warn(string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _inner.Warn(CultureInfo.InvariantCulture, message, argument1, argument2); + _inner.Warn(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); } /// @@ -274,15 +274,15 @@ public void Warn - public void Error(string message, TArgument argument) + public void Error(string message, TArgument args) { - _inner.Error(CultureInfo.InvariantCulture, message, argument); + _inner.Error(CultureInfo.InvariantCulture, message, args); } /// - public void Error(string message, TArgument1 argument1, TArgument2 argument2) + public void Error(string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _inner.Error(CultureInfo.InvariantCulture, message, argument1, argument2); + _inner.Error(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); } /// @@ -334,15 +334,15 @@ public void Error - public void Fatal(string message, TArgument argument) + public void Fatal(string message, TArgument args) { - _inner.Fatal(CultureInfo.InvariantCulture, message, argument); + _inner.Fatal(CultureInfo.InvariantCulture, message, args); } /// - public void Fatal(string message, TArgument1 argument1, TArgument2 argument2) + public void Fatal(string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _inner.Fatal(CultureInfo.InvariantCulture, message, argument1, argument2); + _inner.Fatal(CultureInfo.InvariantCulture, messageFormat, argument1, argument2); } /// diff --git a/src/Splat.Prism.Forms/PrismApplication.cs b/src/Splat.Prism.Forms/PrismApplication.cs index 37eea6a4a..c36d60443 100644 --- a/src/Splat.Prism.Forms/PrismApplication.cs +++ b/src/Splat.Prism.Forms/PrismApplication.cs @@ -22,7 +22,7 @@ public abstract class PrismApplication : PrismApplicationBase /// Initializes a new instance of the class. /// /// An initializer for initializing the platform. - public PrismApplication(IPlatformInitializer initializer = null) + protected PrismApplication(IPlatformInitializer initializer = null) : base(initializer) { } diff --git a/src/Splat.Prism/SplatContainerExtension.cs b/src/Splat.Prism/SplatContainerExtension.cs index ea072bca1..04f3add55 100644 --- a/src/Splat.Prism/SplatContainerExtension.cs +++ b/src/Splat.Prism/SplatContainerExtension.cs @@ -129,6 +129,11 @@ public IContainerRegistry Register(Type type, Func f /// public IContainerRegistry RegisterMany(Type type, params Type[] serviceTypes) { + if (serviceTypes is null) + { + return this; + } + foreach (Type serviceType in serviceTypes) { Instance.Register(() => Activator.CreateInstance(type), serviceType); diff --git a/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs b/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs index 88a9c2596..c5325bd79 100644 --- a/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs +++ b/src/Splat.Raygun/RaygunFeatureUsageTrackingSession.cs @@ -88,10 +88,10 @@ internal RaygunFeatureUsageTrackingSession( public string FeatureName { get; } /// - public IFeatureUsageTrackingSession SubFeature(string name) + public IFeatureUsageTrackingSession SubFeature(string description) { return new RaygunFeatureUsageTrackingSession( - name, + description, FeatureReference, _raygunClient, _raygunSettings); diff --git a/src/Splat.Serilog/SerilogFullLogger.cs b/src/Splat.Serilog/SerilogFullLogger.cs index c974020a3..4d621400f 100644 --- a/src/Splat.Serilog/SerilogFullLogger.cs +++ b/src/Splat.Serilog/SerilogFullLogger.cs @@ -112,9 +112,9 @@ public void Debug(IFormatProvider formatProvider, [Localizable(false) } /// - public void Debug([Localizable(false)] string message, TArgument argument) + public void Debug([Localizable(false)] string message, TArgument args) { - _logger.Debug(message, argument); + _logger.Debug(message, args); } /// @@ -124,9 +124,9 @@ public void Debug(IFormatProvider formatProvider, [Local } /// - public void Debug([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _logger.Debug(message, argument1, argument2); + _logger.Debug(messageFormat, argument1, argument2); } /// @@ -136,9 +136,9 @@ public void Debug(IFormatProvider formatProv } /// - public void Debug([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + public void Debug([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { - _logger.Debug(message, argument1, argument2, argument3); + _logger.Debug(messageFormat, argument1, argument2, argument3); } /// @@ -250,9 +250,9 @@ public void Error(IFormatProvider formatProvider, [Localizable(false) } /// - public void Error([Localizable(false)] string message, TArgument argument) + public void Error([Localizable(false)] string message, TArgument args) { - _logger.Error(message, argument); + _logger.Error(message, args); } /// @@ -262,9 +262,9 @@ public void Error(IFormatProvider formatProvider, [Local } /// - public void Error([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _logger.Error(message, argument1, argument2); + _logger.Error(messageFormat, argument1, argument2); } /// @@ -274,9 +274,9 @@ public void Error(IFormatProvider formatProv } /// - public void Error([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + public void Error([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { - _logger.Error(message, argument1, argument2, argument3); + _logger.Error(messageFormat, argument1, argument2, argument3); } /// @@ -382,9 +382,9 @@ public void Fatal(IFormatProvider formatProvider, [Localizable(false) } /// - public void Fatal([Localizable(false)] string message, TArgument argument) + public void Fatal([Localizable(false)] string message, TArgument args) { - _logger.Fatal(message, argument); + _logger.Fatal(message, args); } /// @@ -394,9 +394,9 @@ public void Fatal(IFormatProvider formatProvider, [Local } /// - public void Fatal([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _logger.Fatal(message, argument1, argument2); + _logger.Fatal(messageFormat, argument1, argument2); } /// @@ -406,9 +406,9 @@ public void Fatal(IFormatProvider formatProv } /// - public void Fatal([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + public void Fatal([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { - _logger.Fatal(message, argument1, argument2, argument3); + _logger.Fatal(messageFormat, argument1, argument2, argument3); } /// @@ -514,9 +514,9 @@ public void Info(IFormatProvider formatProvider, [Localizable(false)] } /// - public void Info([Localizable(false)] string message, TArgument argument) + public void Info([Localizable(false)] string message, TArgument args) { - _logger.Information(message, argument); + _logger.Information(message, args); } /// @@ -526,9 +526,9 @@ public void Info(IFormatProvider formatProvider, [Locali } /// - public void Info([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _logger.Information(message, argument1, argument2); + _logger.Information(messageFormat, argument1, argument2); } /// @@ -538,9 +538,9 @@ public void Info(IFormatProvider formatProvi } /// - public void Info([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + public void Info([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { - _logger.Information(message, argument1, argument2, argument3); + _logger.Information(messageFormat, argument1, argument2, argument3); } /// @@ -646,9 +646,9 @@ public void Warn(IFormatProvider formatProvider, [Localizable(false)] } /// - public void Warn([Localizable(false)] string message, TArgument argument) + public void Warn([Localizable(false)] string message, TArgument args) { - _logger.Warning(message, argument); + _logger.Warning(message, args); } /// @@ -658,9 +658,9 @@ public void Warn(IFormatProvider formatProvider, [Locali } /// - public void Warn([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2) + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2) { - _logger.Warning(message, argument1, argument2); + _logger.Warning(messageFormat, argument1, argument2); } /// @@ -670,9 +670,9 @@ public void Warn(IFormatProvider formatProvi } /// - public void Warn([Localizable(false)] string message, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) + public void Warn([Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3) { - _logger.Warning(message, argument1, argument2, argument3); + _logger.Warning(messageFormat, argument1, argument2, argument3); } /// diff --git a/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs b/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs index 98ad662f8..558d56139 100644 --- a/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs +++ b/src/Splat.SimpleInjector/SimpleInjectorDependencyResolver.cs @@ -32,7 +32,7 @@ public SimpleInjectorDependencyResolver(Container container, SimpleInjectorIniti } /// - public object GetService(Type serviceType, string contract = null) + public object? GetService(Type serviceType, string? contract = null) { try { @@ -52,7 +52,7 @@ public object GetService(Type serviceType, string contract = null) } /// - public IEnumerable GetServices(Type serviceType, string contract = null) + public IEnumerable GetServices(Type serviceType, string? contract = null) { try { @@ -71,26 +71,26 @@ public IEnumerable GetServices(Type serviceType, string contract = null) } /// - public bool HasRegistration(Type serviceType, string contract = null) + public bool HasRegistration(Type serviceType, string? contract = null) { return _container.GetCurrentRegistrations().Any(x => x.ServiceType == serviceType); } /// - public void Register(Func factory, Type serviceType, string contract = null) + public void Register(Func factory, Type serviceType, string? contract = null) { // The function does nothing because there should be no registration called on this object. // Anyway, Locator.SetLocator performs some unnecessary registrations. } /// - public void UnregisterCurrent(Type serviceType, string contract = null) + public void UnregisterCurrent(Type serviceType, string? contract = null) { throw new NotImplementedException(); } /// - public void UnregisterAll(Type serviceType, string contract = null) + public void UnregisterAll(Type serviceType, string? contract = null) { throw new NotImplementedException(); } @@ -116,8 +116,7 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - _container?.Dispose(); - _container = null; + _container.Dispose(); } } diff --git a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs index 94a226f52..e47ac3e35 100644 --- a/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs +++ b/src/Splat.SimpleInjector/SimpleInjectorInitializer.cs @@ -26,17 +26,17 @@ public class SimpleInjectorInitializer : IDependencyResolver = new Dictionary>>(); /// - public object GetService(Type serviceType, string contract = null) + public object? GetService(Type serviceType, string? contract = null) { lock (_lockObject) { - Func fact = RegisteredFactories[serviceType].LastOrDefault(); + Func? fact = RegisteredFactories[serviceType].LastOrDefault(); return fact?.Invoke(); } } /// - public IEnumerable GetServices(Type serviceType, string contract = null) + public IEnumerable GetServices(Type serviceType, string? contract = null) { lock (_lockObject) { @@ -46,17 +46,17 @@ public IEnumerable GetServices(Type serviceType, string contract = null) } /// - public bool HasRegistration(Type serviceType, string contract = null) + public bool HasRegistration(Type serviceType, string? contract = null) { lock (_lockObject) { - return RegisteredFactories.TryGetValue(serviceType, out List> values) - && values.Any(); + return RegisteredFactories.TryGetValue(serviceType, out var values) + && values.Count > 0; } } /// - public void Register(Func factory, Type serviceType, string contract = null) + public void Register(Func factory, Type serviceType, string? contract = null) { lock (_lockObject) { @@ -70,13 +70,13 @@ public void Register(Func factory, Type serviceType, string contract = n } /// - public void UnregisterCurrent(Type serviceType, string contract = null) + public void UnregisterCurrent(Type serviceType, string? contract = null) { throw new NotImplementedException(); } /// - public void UnregisterAll(Type serviceType, string contract = null) + public void UnregisterAll(Type serviceType, string? contract = null) { lock (_lockObject) { @@ -97,6 +97,16 @@ public IDisposable ServiceRegistrationCallback(Type serviceType, string contract #pragma warning disable CA1063 // Implement IDisposable Correctly public void Dispose() #pragma warning restore CA1063 // Implement IDisposable Correctly + { + GC.SuppressFinalize(this); + Dispose(true); + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool isDisposing) { } } diff --git a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj index 31a07d198..f50f4306c 100644 --- a/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj +++ b/src/Splat.SimpleInjector/Splat.SimpleInjector.csproj @@ -4,7 +4,8 @@ netstandard2.0;net5.0 $(TargetFrameworks);net461 SimpleInjector adapter for Splat - latest + latest + enable diff --git a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs index 247b97cba..8852cf33c 100644 --- a/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs +++ b/src/Splat.SimpleInjector/TransientSimpleInjectorRegistration.cs @@ -11,7 +11,7 @@ namespace Splat.SimpleInjector { internal class TransientSimpleInjectorRegistration : Registration { - public TransientSimpleInjectorRegistration(Container container, Type implementationType, Func instanceCreator = null) + public TransientSimpleInjectorRegistration(Container container, Type implementationType, Func? instanceCreator = null) : base(Lifestyle.Transient, container, implementationType, instanceCreator) { } diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net5.0.approved.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net5.0.approved.txt index d5e2f3080..c77a2a66a 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net5.0.approved.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.net5.0.approved.txt @@ -123,10 +123,10 @@ namespace Splat public void Warn(System.Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) { } public virtual void Warn([System.ComponentModel.Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) { } public void Warn(System.Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) { } - public void Write([System.ComponentModel.Localizable(false)] string messageFormat, Splat.LogLevel logLevel) { } - public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string messageFormat, Splat.LogLevel logLevel) { } - public void Write([System.ComponentModel.Localizable(false)] string messageFormat, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } - public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string messageFormat, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } + public void Write([System.ComponentModel.Localizable(false)] string message, Splat.LogLevel logLevel) { } + public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string message, Splat.LogLevel logLevel) { } + public void Write([System.ComponentModel.Localizable(false)] string message, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } + public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string message, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } } public class ConsoleLogger : Splat.ILogger { diff --git a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.1.approved.txt b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.1.approved.txt index bc03fe6e0..e9726383c 100644 --- a/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.1.approved.txt +++ b/src/Splat.Tests/API/ApiApprovalTests.SplatProject.netcoreapp3.1.approved.txt @@ -123,10 +123,10 @@ namespace Splat public void Warn(System.Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9) { } public virtual void Warn([System.ComponentModel.Localizable(false)] string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) { } public void Warn(System.Exception exception, string messageFormat, TArgument1 argument1, TArgument2 argument2, TArgument3 argument3, TArgument4 argument4, TArgument5 argument5, TArgument6 argument6, TArgument7 argument7, TArgument8 argument8, TArgument9 argument9, TArgument10 argument10) { } - public void Write([System.ComponentModel.Localizable(false)] string messageFormat, Splat.LogLevel logLevel) { } - public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string messageFormat, Splat.LogLevel logLevel) { } - public void Write([System.ComponentModel.Localizable(false)] string messageFormat, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } - public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string messageFormat, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } + public void Write([System.ComponentModel.Localizable(false)] string message, Splat.LogLevel logLevel) { } + public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string message, Splat.LogLevel logLevel) { } + public void Write([System.ComponentModel.Localizable(false)] string message, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } + public void Write(System.Exception exception, [System.ComponentModel.Localizable(false)] string message, [System.ComponentModel.Localizable(false)] System.Type type, Splat.LogLevel logLevel) { } } public class ConsoleLogger : Splat.ILogger { diff --git a/src/Splat.Tests/ApiExtensions.cs b/src/Splat.Tests/ApiExtensions.cs index 78bd5378b..6db5f1c35 100644 --- a/src/Splat.Tests/ApiExtensions.cs +++ b/src/Splat.Tests/ApiExtensions.cs @@ -53,7 +53,7 @@ public static void CheckApproval(this Assembly assembly, [CallerMemberName] stri var generatorOptions = new ApiGeneratorOptions { WhitelistedNamespacePrefixes = new[] { "Splat" } }; var receivedPublicApi = Filter(ApiGenerator.GeneratePublicApi(assembly, generatorOptions)); - if (!string.Equals(receivedPublicApi, approvedPublicApi, StringComparison.InvariantCulture)) + if (!string.Equals(receivedPublicApi, approvedPublicApi, StringComparison.Ordinal)) { File.WriteAllText(receivedFileName, receivedPublicApi); DiffRunner.Launch(receivedFileName, approvedFileName); diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs index 1c2d1a627..4878cc3c1 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs @@ -14,6 +14,7 @@ namespace Splat.Tests.ApplicationPerformanceMonitoring /// /// Unit Tests for the IEnableFeatureUsageTracking Extensions. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] public static class EnableFeatureUsageTrackingExtensionsTests { /// diff --git a/src/Splat.Tests/Logging/Helpers/FormatHelper.cs b/src/Splat.Tests/Logging/Helpers/FormatHelper.cs index 45f410911..1f5e07246 100644 --- a/src/Splat.Tests/Logging/Helpers/FormatHelper.cs +++ b/src/Splat.Tests/Logging/Helpers/FormatHelper.cs @@ -10,6 +10,7 @@ namespace Splat.Tests.Logging /// /// Contains help with formatting. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2201:Do not raise reserved exception types", Justification = "Deliberate Usage")] public static class FormatHelper { /// diff --git a/src/Splat.Tests/Logging/StaticLoggerTests.cs b/src/Splat.Tests/Logging/StaticLoggerTests.cs index 87a27e0f2..d546cf400 100644 --- a/src/Splat.Tests/Logging/StaticLoggerTests.cs +++ b/src/Splat.Tests/Logging/StaticLoggerTests.cs @@ -13,8 +13,6 @@ namespace Splat.Tests.Logging [ExcludeFromCodeCoverage] public sealed class StaticLoggerTests { - private const string Message = "Message"; - private static char[] NewLine => Environment.NewLine.ToCharArray(); /// diff --git a/src/Splat.sln b/src/Splat.sln index ce107c545..a756c6ef3 100644 --- a/src/Splat.sln +++ b/src/Splat.sln @@ -7,8 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat", "Splat\Splat.csproj EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C7B370F1-BEF3-4AB7-BA08-CC5D83E74598}" ProjectSection(SolutionItems) = preProject - analyzers.ruleset = analyzers.ruleset - ApiGeneratorGlobalSuppressions.cs = ApiGeneratorGlobalSuppressions.cs + ..\.editorconfig = ..\.editorconfig Directory.build.props = Directory.build.props Directory.build.targets = Directory.build.targets global.json = global.json @@ -67,7 +66,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Prism.Forms", "Splat. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Prism.Tests", "Splat.Prism.Tests\Splat.Prism.Tests.csproj", "{905A96B2-03C9-4D08-8E8B-E5B0F7F9F33A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Splat.Drawing.Tests", "Splat.Drawing.Tests\Splat.Drawing.Tests.csproj", "{7E350DE5-B8C4-4EF1-9211-7B35643B1971}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Splat.Drawing.Tests", "Splat.Drawing.Tests\Splat.Drawing.Tests.csproj", "{7E350DE5-B8C4-4EF1-9211-7B35643B1971}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs index 09b79d349..1c1df0e3d 100644 --- a/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs +++ b/src/Splat/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensions.cs @@ -26,7 +26,7 @@ public static IFeatureUsageTrackingSession FeatureUsageTrackingSession( var featureUsageTrackingSession = Locator.Current.GetService(); if (featureUsageTrackingSession == null) { - throw new Exception("Feature Usage Tracking Manager is null. This should never happen, your dependency resolver is broken"); + throw new InvalidOperationException("Feature Usage Tracking Manager is null. This should never happen, your dependency resolver is broken"); } return featureUsageTrackingSession.GetFeatureUsageTrackingSession(featureName); @@ -43,6 +43,11 @@ public static void WithFeatureUsageTrackingSession( string featureName, Action action) { + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + using (var session = instance.FeatureUsageTrackingSession(featureName)) { try @@ -68,6 +73,16 @@ public static void WithSubFeatureUsageTrackingSession( string featureName, Action action) { + if (instance is null) + { + throw new ArgumentNullException(nameof(instance)); + } + + if (action is null) + { + throw new ArgumentNullException(nameof(action)); + } + using (var session = instance.SubFeature(featureName)) { try diff --git a/src/Splat/Logging/AllocationFreeLoggerBase.cs b/src/Splat/Logging/AllocationFreeLoggerBase.cs index 8f2132a05..1c628181e 100644 --- a/src/Splat/Logging/AllocationFreeLoggerBase.cs +++ b/src/Splat/Logging/AllocationFreeLoggerBase.cs @@ -2454,27 +2454,27 @@ public virtual void Fatal - public void Write([Localizable(false)] string messageFormat, LogLevel logLevel) + public void Write([Localizable(false)] string message, LogLevel logLevel) { - _inner.Write(messageFormat, logLevel); + _inner.Write(message, logLevel); } /// - public void Write(Exception exception, [Localizable(false)] string messageFormat, LogLevel logLevel) + public void Write(Exception exception, [Localizable(false)] string message, LogLevel logLevel) { - _inner.Write(exception, messageFormat, logLevel); + _inner.Write(exception, message, logLevel); } /// - public void Write([Localizable(false)] string messageFormat, [Localizable(false)] Type type, LogLevel logLevel) + public void Write([Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) { - _inner.Write(messageFormat, type, logLevel); + _inner.Write(message, type, logLevel); } /// - public void Write(Exception exception, [Localizable(false)] string messageFormat, [Localizable(false)] Type type, LogLevel logLevel) + public void Write(Exception exception, [Localizable(false)] string message, [Localizable(false)] Type type, LogLevel logLevel) { - _inner.Write(exception, messageFormat, type, logLevel); + _inner.Write(exception, message, type, logLevel); } } } diff --git a/src/Splat/Logging/LogHost.cs b/src/Splat/Logging/LogHost.cs index 63b4b704c..a27ab1849 100644 --- a/src/Splat/Logging/LogHost.cs +++ b/src/Splat/Logging/LogHost.cs @@ -53,7 +53,7 @@ public static IFullLogger Log(this T logClassInstance) var factory = Locator.Current.GetService(); if (factory == null) { - throw new Exception("ILogManager is null. This should never happen, your dependency resolver is broken"); + throw new InvalidOperationException("ILogManager is null. This should never happen, your dependency resolver is broken"); } return factory.GetLogger(); diff --git a/src/Splat/Logging/LogLevel.cs b/src/Splat/Logging/LogLevel.cs index 268228668..45dba8fd2 100644 --- a/src/Splat/Logging/LogLevel.cs +++ b/src/Splat/Logging/LogLevel.cs @@ -8,6 +8,7 @@ namespace Splat /// /// Represents the minimum log level a will start emitting from. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1008:Enums should have zero value", Justification = "Deliberate none zero value.")] public enum LogLevel { /// diff --git a/src/Splat/MemoizingMRUCache.cs b/src/Splat/MemoizingMRUCache.cs index f921b06ea..9473a1911 100644 --- a/src/Splat/MemoizingMRUCache.cs +++ b/src/Splat/MemoizingMRUCache.cs @@ -203,7 +203,6 @@ public void Invalidate(TParam key) /// Flag to indicate whether Exceptions during the resource Release call should not fail on the first item. /// But should try all items then throw an aggregate exception. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exception passed to exceptions list.")] public void InvalidateAll(bool aggregateReleaseExceptions = false) { Dictionary param, TVal value)> oldCacheToClear = null; @@ -223,11 +222,8 @@ public void InvalidateAll(bool aggregateReleaseExceptions = false) // by moving to a temp variable // can free up the lock quicker for other calls to MRU - if (_releaseFunction != null) - { - // no point doing it, if nothing to release - oldCacheToClear = _cacheEntries; - } + // no point doing it, if nothing to release + oldCacheToClear = _cacheEntries; _cacheMRUList = new LinkedList(); _cacheEntries = new Dictionary param, TVal value)>(_comparer); diff --git a/src/Splat/ServiceLocation/Locator.cs b/src/Splat/ServiceLocation/Locator.cs index 5e2a4848b..35b8c1b94 100644 --- a/src/Splat/ServiceLocation/Locator.cs +++ b/src/Splat/ServiceLocation/Locator.cs @@ -54,6 +54,7 @@ public static void SetLocator(IDependencyResolver dependencyResolver) /// Note you should use or in most situations. /// /// The locator. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = "Can be a expensive operation.")] public static IDependencyResolver GetLocator() { return InternalLocator.Internal; diff --git a/src/analyzers.ruleset b/src/analyzers.ruleset deleted file mode 100644 index ab6f3f0da..000000000 --- a/src/analyzers.ruleset +++ /dev/null @@ -1,282 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From d87d6cabd3e9cb782551816c0492793ce8d54217 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Mon, 5 Apr 2021 20:43:14 +1000 Subject: [PATCH 2/2] housekeeping: add missing editorconfig file --- .editorconfig | 341 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 323 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8a7cddf75..22e454e94 100644 --- a/.editorconfig +++ b/.editorconfig @@ -29,9 +29,13 @@ csharp_new_line_between_query_expression_clauses = true csharp_indent_block_contents = true csharp_indent_braces = false csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true csharp_indent_switch_labels = true csharp_indent_labels = one_less_than_current +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion + # avoid this. unless absolutely necessary dotnet_style_qualification_for_field = false:suggestion dotnet_style_qualification_for_property = false:suggestion @@ -40,10 +44,13 @@ dotnet_style_qualification_for_event = false:suggestion # only use var when it's obvious what the variable type is csharp_style_var_for_built_in_types = false:none -csharp_style_var_when_type_is_apparent = false:suggestion -csharp_style_var_elsewhere = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion -# use language keywords instead of BCL types +# Types: use keywords instead of BCL types, and permit var only when the type is clear +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = false:none +csharp_style_var_elsewhere = false:suggestion dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_member_access = true:suggestion @@ -51,33 +58,42 @@ dotnet_style_predefined_type_for_member_access = true:suggestion dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style - dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.required_modifiers = const - dotnet_naming_style.pascal_case_style.capitalization = pascal_case # static fields should have s_ prefix +dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion +dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields +dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static - -dotnet_naming_style.static_prefix_style.capitalization = camel_case +dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected +dotnet_naming_style.static_prefix_style.required_prefix = s_ +dotnet_naming_style.static_prefix_style.capitalization = camel_case # internal and private fields should be _camelCase dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style - dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal - dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case # Code style defaults +csharp_using_directive_placement = outside_namespace:suggestion dotnet_sort_system_directives_first = true -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = false +csharp_prefer_braces = true:silent +csharp_preserve_single_line_blocks = true:none +csharp_preserve_single_line_statements = false:none +csharp_prefer_static_local_function = true:suggestion +csharp_prefer_simple_using_statement = false:none +csharp_style_prefer_switch_expression = true:suggestion + +# Code quality +dotnet_style_readonly_field = true:suggestion +dotnet_code_quality_unused_parameters = non_public:suggestion # Expression-level preferences dotnet_style_object_initializer = true:suggestion @@ -85,14 +101,23 @@ dotnet_style_collection_initializer = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +csharp_prefer_simple_default_expression = true:suggestion # Expression-bodied members -csharp_style_expression_bodied_methods = false:none -csharp_style_expression_bodied_constructors = false:none -csharp_style_expression_bodied_operators = false:none +csharp_style_expression_bodied_methods = true:suggestion +csharp_style_expression_bodied_constructors = true:suggestion +csharp_style_expression_bodied_operators = true:suggestion csharp_style_expression_bodied_properties = true:suggestion -csharp_style_expression_bodied_indexers = true:none -csharp_style_expression_bodied_accessors = true:none +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = true:suggestion # Pattern matching csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion @@ -103,6 +128,11 @@ csharp_style_inlined_variable_declaration = true:suggestion csharp_style_throw_expression = true:suggestion csharp_style_conditional_delegate_call = true:suggestion +# Other features +csharp_style_prefer_index_operator = false:none +csharp_style_prefer_range_operator = false:none +csharp_style_pattern_local_over_anonymous_function = false:none + # Space preferences csharp_space_after_cast = false csharp_space_after_colon_in_inheritance_clause = true @@ -127,6 +157,281 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false csharp_space_between_square_brackets = false +# analyzers +dotnet_diagnostic.AvoidAsyncVoid.severity = suggestion + +dotnet_diagnostic.CA1000.severity = none +dotnet_diagnostic.CA1001.severity = error +dotnet_diagnostic.CA1009.severity = error +dotnet_diagnostic.CA1014.severity = none +dotnet_diagnostic.CA1016.severity = error +dotnet_diagnostic.CA1030.severity = none +dotnet_diagnostic.CA1031.severity = none +dotnet_diagnostic.CA1033.severity = none +dotnet_diagnostic.CA1036.severity = none +dotnet_diagnostic.CA1049.severity = error +dotnet_diagnostic.CA1056.severity = suggestion +dotnet_diagnostic.CA1060.severity = error +dotnet_diagnostic.CA1061.severity = error +dotnet_diagnostic.CA1063.severity = error +dotnet_diagnostic.CA1065.severity = error +dotnet_diagnostic.CA1301.severity = error +dotnet_diagnostic.CA1303.severity = none +dotnet_diagnostic.CA1308.severity = none +dotnet_diagnostic.CA1400.severity = error +dotnet_diagnostic.CA1401.severity = error +dotnet_diagnostic.CA1403.severity = error +dotnet_diagnostic.CA1404.severity = error +dotnet_diagnostic.CA1405.severity = error +dotnet_diagnostic.CA1410.severity = error +dotnet_diagnostic.CA1415.severity = error +dotnet_diagnostic.CA1507.severity = error +dotnet_diagnostic.CA1710.severity = suggestion +dotnet_diagnostic.CA1716.severity = suggestion +dotnet_diagnostic.CA1724.severity = none +dotnet_diagnostic.CA1810.severity = none +dotnet_diagnostic.CA1821.severity = error +dotnet_diagnostic.CA1900.severity = error +dotnet_diagnostic.CA1901.severity = error +dotnet_diagnostic.CA2000.severity = none +dotnet_diagnostic.CA2002.severity = error +dotnet_diagnostic.CA2007.severity = none +dotnet_diagnostic.CA2100.severity = error +dotnet_diagnostic.CA2101.severity = error +dotnet_diagnostic.CA2108.severity = error +dotnet_diagnostic.CA2111.severity = error +dotnet_diagnostic.CA2112.severity = error +dotnet_diagnostic.CA2114.severity = error +dotnet_diagnostic.CA2116.severity = error +dotnet_diagnostic.CA2117.severity = error +dotnet_diagnostic.CA2122.severity = error +dotnet_diagnostic.CA2123.severity = error +dotnet_diagnostic.CA2124.severity = error +dotnet_diagnostic.CA2126.severity = error +dotnet_diagnostic.CA2131.severity = error +dotnet_diagnostic.CA2132.severity = error +dotnet_diagnostic.CA2133.severity = error +dotnet_diagnostic.CA2134.severity = error +dotnet_diagnostic.CA2137.severity = error +dotnet_diagnostic.CA2138.severity = error +dotnet_diagnostic.CA2140.severity = error +dotnet_diagnostic.CA2141.severity = error +dotnet_diagnostic.CA2146.severity = error +dotnet_diagnostic.CA2147.severity = error +dotnet_diagnostic.CA2149.severity = error +dotnet_diagnostic.CA2200.severity = error +dotnet_diagnostic.CA2202.severity = error +dotnet_diagnostic.CA2207.severity = error +dotnet_diagnostic.CA2212.severity = error +dotnet_diagnostic.CA2213.severity = error +dotnet_diagnostic.CA2214.severity = error +dotnet_diagnostic.CA2216.severity = error +dotnet_diagnostic.CA2220.severity = error +dotnet_diagnostic.CA2229.severity = error +dotnet_diagnostic.CA2231.severity = error +dotnet_diagnostic.CA2232.severity = error +dotnet_diagnostic.CA2235.severity = error +dotnet_diagnostic.CA2236.severity = error +dotnet_diagnostic.CA2237.severity = error +dotnet_diagnostic.CA2238.severity = error +dotnet_diagnostic.CA2240.severity = error +dotnet_diagnostic.CA2241.severity = error +dotnet_diagnostic.CA2242.severity = error + +dotnet_diagnostic.RCS1001.severity = error +dotnet_diagnostic.RCS1018.severity = error +dotnet_diagnostic.RCS1037.severity = error +dotnet_diagnostic.RCS1055.severity = error +dotnet_diagnostic.RCS1062.severity = error +dotnet_diagnostic.RCS1066.severity = error +dotnet_diagnostic.RCS1069.severity = error +dotnet_diagnostic.RCS1071.severity = error +dotnet_diagnostic.RCS1074.severity = error +dotnet_diagnostic.RCS1090.severity = error +dotnet_diagnostic.RCS1138.severity = error +dotnet_diagnostic.RCS1139.severity = error +dotnet_diagnostic.RCS1163.severity = suggestion +dotnet_diagnostic.RCS1168.severity = suggestion +dotnet_diagnostic.RCS1188.severity = error +dotnet_diagnostic.RCS1201.severity = error +dotnet_diagnostic.RCS1207.severity = error +dotnet_diagnostic.RCS1211.severity = error +dotnet_diagnostic.RCS1507.severity = error + +dotnet_diagnostic.SA1000.severity = error +dotnet_diagnostic.SA1001.severity = error +dotnet_diagnostic.SA1002.severity = error +dotnet_diagnostic.SA1003.severity = error +dotnet_diagnostic.SA1004.severity = error +dotnet_diagnostic.SA1005.severity = error +dotnet_diagnostic.SA1006.severity = error +dotnet_diagnostic.SA1007.severity = error +dotnet_diagnostic.SA1008.severity = error +dotnet_diagnostic.SA1009.severity = error +dotnet_diagnostic.SA1010.severity = error +dotnet_diagnostic.SA1011.severity = error +dotnet_diagnostic.SA1012.severity = error +dotnet_diagnostic.SA1013.severity = error +dotnet_diagnostic.SA1014.severity = error +dotnet_diagnostic.SA1015.severity = error +dotnet_diagnostic.SA1016.severity = error +dotnet_diagnostic.SA1017.severity = error +dotnet_diagnostic.SA1018.severity = error +dotnet_diagnostic.SA1019.severity = error +dotnet_diagnostic.SA1020.severity = error +dotnet_diagnostic.SA1021.severity = error +dotnet_diagnostic.SA1022.severity = error +dotnet_diagnostic.SA1023.severity = error +dotnet_diagnostic.SA1024.severity = error +dotnet_diagnostic.SA1025.severity = error +dotnet_diagnostic.SA1026.severity = error +dotnet_diagnostic.SA1027.severity = error +dotnet_diagnostic.SA1028.severity = error +dotnet_diagnostic.SA1100.severity = error +dotnet_diagnostic.SA1101.severity = none +dotnet_diagnostic.SA1102.severity = error +dotnet_diagnostic.SA1103.severity = error +dotnet_diagnostic.SA1104.severity = error +dotnet_diagnostic.SA1105.severity = error +dotnet_diagnostic.SA1106.severity = error +dotnet_diagnostic.SA1107.severity = error +dotnet_diagnostic.SA1108.severity = error +dotnet_diagnostic.SA1110.severity = error +dotnet_diagnostic.SA1111.severity = error +dotnet_diagnostic.SA1112.severity = error +dotnet_diagnostic.SA1113.severity = error +dotnet_diagnostic.SA1114.severity = error +dotnet_diagnostic.SA1115.severity = error +dotnet_diagnostic.SA1116.severity = error +dotnet_diagnostic.SA1117.severity = error +dotnet_diagnostic.SA1118.severity = error +dotnet_diagnostic.SA1119.severity = error +dotnet_diagnostic.SA1120.severity = error +dotnet_diagnostic.SA1121.severity = error +dotnet_diagnostic.SA1122.severity = error +dotnet_diagnostic.SA1123.severity = error +dotnet_diagnostic.SA1124.severity = error +dotnet_diagnostic.SA1125.severity = error +dotnet_diagnostic.SA1127.severity = error +dotnet_diagnostic.SA1128.severity = error +dotnet_diagnostic.SA1129.severity = error +dotnet_diagnostic.SA1130.severity = error +dotnet_diagnostic.SA1131.severity = error +dotnet_diagnostic.SA1132.severity = error +dotnet_diagnostic.SA1133.severity = error +dotnet_diagnostic.SA1134.severity = error +dotnet_diagnostic.SA1135.severity = error +dotnet_diagnostic.SA1136.severity = error +dotnet_diagnostic.SA1137.severity = error +dotnet_diagnostic.SA1139.severity = error +dotnet_diagnostic.SA1200.severity = none +dotnet_diagnostic.SA1201.severity = error +dotnet_diagnostic.SA1202.severity = error +dotnet_diagnostic.SA1203.severity = error +dotnet_diagnostic.SA1204.severity = error +dotnet_diagnostic.SA1205.severity = error +dotnet_diagnostic.SA1206.severity = error +dotnet_diagnostic.SA1207.severity = error +dotnet_diagnostic.SA1208.severity = error +dotnet_diagnostic.SA1209.severity = error +dotnet_diagnostic.SA1210.severity = error +dotnet_diagnostic.SA1211.severity = error +dotnet_diagnostic.SA1212.severity = error +dotnet_diagnostic.SA1213.severity = error +dotnet_diagnostic.SA1214.severity = error +dotnet_diagnostic.SA1216.severity = error +dotnet_diagnostic.SA1217.severity = error +dotnet_diagnostic.SA1300.severity = error +dotnet_diagnostic.SA1302.severity = error +dotnet_diagnostic.SA1303.severity = error +dotnet_diagnostic.SA1304.severity = error +dotnet_diagnostic.SA1306.severity = none +dotnet_diagnostic.SA1307.severity = error +dotnet_diagnostic.SA1308.severity = error +dotnet_diagnostic.SA1309.severity = none +dotnet_diagnostic.SA1310.severity = error +dotnet_diagnostic.SA1311.severity = none +dotnet_diagnostic.SA1312.severity = error +dotnet_diagnostic.SA1313.severity = error +dotnet_diagnostic.SA1314.severity = error +dotnet_diagnostic.SA1316.severity = none +dotnet_diagnostic.SA1400.severity = error +dotnet_diagnostic.SA1401.severity = error +dotnet_diagnostic.SA1402.severity = error +dotnet_diagnostic.SA1403.severity = error +dotnet_diagnostic.SA1404.severity = error +dotnet_diagnostic.SA1405.severity = error +dotnet_diagnostic.SA1406.severity = error +dotnet_diagnostic.SA1407.severity = error +dotnet_diagnostic.SA1408.severity = error +dotnet_diagnostic.SA1410.severity = error +dotnet_diagnostic.SA1411.severity = error +dotnet_diagnostic.SA1413.severity = none +dotnet_diagnostic.SA1500.severity = error +dotnet_diagnostic.SA1501.severity = error +dotnet_diagnostic.SA1502.severity = error +dotnet_diagnostic.SA1503.severity = error +dotnet_diagnostic.SA1504.severity = error +dotnet_diagnostic.SA1505.severity = error +dotnet_diagnostic.SA1506.severity = error +dotnet_diagnostic.SA1507.severity = error +dotnet_diagnostic.SA1508.severity = error +dotnet_diagnostic.SA1509.severity = error +dotnet_diagnostic.SA1510.severity = error +dotnet_diagnostic.SA1511.severity = error +dotnet_diagnostic.SA1512.severity = error +dotnet_diagnostic.SA1513.severity = error +dotnet_diagnostic.SA1514.severity = error +dotnet_diagnostic.SA1515.severity = error +dotnet_diagnostic.SA1516.severity = error +dotnet_diagnostic.SA1517.severity = error +dotnet_diagnostic.SA1518.severity = error +dotnet_diagnostic.SA1519.severity = error +dotnet_diagnostic.SA1520.severity = error +dotnet_diagnostic.SA1600.severity = error +dotnet_diagnostic.SA1601.severity = error +dotnet_diagnostic.SA1602.severity = error +dotnet_diagnostic.SA1604.severity = error +dotnet_diagnostic.SA1605.severity = error +dotnet_diagnostic.SA1606.severity = error +dotnet_diagnostic.SA1607.severity = error +dotnet_diagnostic.SA1608.severity = error +dotnet_diagnostic.SA1610.severity = error +dotnet_diagnostic.SA1611.severity = error +dotnet_diagnostic.SA1612.severity = error +dotnet_diagnostic.SA1613.severity = error +dotnet_diagnostic.SA1614.severity = error +dotnet_diagnostic.SA1615.severity = error +dotnet_diagnostic.SA1616.severity = error +dotnet_diagnostic.SA1617.severity = error +dotnet_diagnostic.SA1618.severity = error +dotnet_diagnostic.SA1619.severity = error +dotnet_diagnostic.SA1620.severity = error +dotnet_diagnostic.SA1621.severity = error +dotnet_diagnostic.SA1622.severity = error +dotnet_diagnostic.SA1623.severity = error +dotnet_diagnostic.SA1624.severity = error +dotnet_diagnostic.SA1625.severity = error +dotnet_diagnostic.SA1626.severity = error +dotnet_diagnostic.SA1627.severity = error +dotnet_diagnostic.SA1629.severity = error +dotnet_diagnostic.SA1633.severity = error +dotnet_diagnostic.SA1634.severity = error +dotnet_diagnostic.SA1635.severity = error +dotnet_diagnostic.SA1636.severity = error +dotnet_diagnostic.SA1637.severity = none +dotnet_diagnostic.SA1638.severity = none +dotnet_diagnostic.SA1640.severity = error +dotnet_diagnostic.SA1641.severity = error +dotnet_diagnostic.SA1642.severity = error +dotnet_diagnostic.SA1643.severity = error +dotnet_diagnostic.SA1649.severity = error +dotnet_diagnostic.SA1651.severity = error + +dotnet_diagnostic.SX1101.severity = error +dotnet_diagnostic.SX1309.severity = error +dotnet_diagnostic.SX1623.severity = none + # C++ Files [*.{cpp,h,in}] curly_bracket_next_line = true @@ -152,4 +457,4 @@ indent_size = 2 [*.sh] end_of_line = lf [*.{cmd, bat}] -end_of_line = crlf \ No newline at end of file +end_of_line = crlf