A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Enforce nullable
Etienne Baudouxc4910e81499f
diff --git a/src/.editorconfig b/src/.editorconfigindex 75b4d6754..906db32dc 100644--- a/src/.editorconfig+++ b/src/.editorconfig@@ -68,6 +68,16 @@ dotnet_naming_symbols.constant_fields.required_modifiers = constdotnet_style_namespace_match_folder=true:warningdotnet_style_allow_multiple_blank_lines_experimental=true:warningdotnet_code_quality_unused_parameters=all:warning+# CS8600: Converting null literal or possible null value to non-nullable type.+dotnet_diagnostic.CS8600.severity = error+# CS8604: Possible null reference argument.+dotnet_diagnostic.CS8604.severity = error+# CS8765: Nullability of type of parameter doesn't match overridden member (possibly because of nullability attributes).+dotnet_diagnostic.CS8765.severity = error+# CS8602: Dereference of a possibly null reference.+dotnet_diagnostic.CS8602.severity = error+# CS0162: Unreachable code detected+dotnet_diagnostic.CS0162.severity = error################################ C# Coding Conventions ################################diff --git a/src/dev/impl/DevToys.OutOfProcService/Core/Constants.cs b/src/dev/impl/DevToys.OutOfProcService/Core/Constants.csindex dcbf213ed..b11c2256d 100644--- a/src/dev/impl/DevToys.OutOfProcService/Core/Constants.cs+++ b/src/dev/impl/DevToys.OutOfProcService/Core/Constants.cs@@ -5,7 +5,7 @@ namespace DevToys.OutOfProcService.Core{internal static class Constants{- internal static readonly string AssetsFolderFullPath = Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule!.FileName)!, "Assets");+ internal static readonly string AssetsFolderFullPath = Path.Combine(Path.GetDirectoryName(System.Environment.ProcessPath)!, "Assets");internal const string EfficientCompressionToolFileName = "ect-0.8.3.exe";}diff --git a/src/dev/impl/DevToys/Core/OOP/AppService.cs b/src/dev/impl/DevToys/Core/OOP/AppService.csindex 152a39293..c2489ed92 100644--- a/src/dev/impl/DevToys/Core/OOP/AppService.cs+++ b/src/dev/impl/DevToys/Core/OOP/AppService.cs@@ -132,16 +132,15 @@ namespace DevToys.Core.OOPif (waitForResult){// Wait for the answer of the app service.- using (CancellationTokenRegistration cancellationTokenRegistration+ using CancellationTokenRegistration cancellationTokenRegistration= cancellationToken.Register(() =>{OnSendMessageCanceledAsync(messageId).Forget();- }))- {- AppServiceMessageBase result = await messageCompletionSource.Task;- _progressReporters.TryRemove(message.MessageId.Value, out _);- return result;- }+ });++ AppServiceMessageBase result = await messageCompletionSource.Task;+ _progressReporters.TryRemove(message.MessageId.Value, out _);+ return result;}}catch (Exception ex)diff --git a/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.csindex b352323d2..cf9ee178b 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/GuidGenerator/GuidGeneratorToolViewModel.cs@@ -52,7 +52,7 @@ namespace DevToys.ViewModels.Tools.GuidGeneratorisRoaming: true,defaultValue: 1);- private static readonly Random Random = new Random();+ private static readonly Random Random = new();private static readonly DateTimeOffset GregorianCalendarStart = new(1582, 10, 15, 0, 0, 0, TimeSpan.Zero);private const int VariantByte = 8;diff --git a/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/ImageCompressionWorkItem.cs b/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/ImageCompressionWorkItem.csindex 5be2c4f39..d17adfb03 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/ImageCompressionWorkItem.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/ImageCompressionWorkItem.cs@@ -185,8 +185,10 @@ namespace DevToys.ViewModels.Tools.PngJpgCompressor{string? fileExtension = Path.GetExtension(FilePath);- var savePicker = new FileSavePicker();- savePicker.SuggestedStartLocation = PickerLocationId.ComputerFolder;+ var savePicker = new FileSavePicker+ {+ SuggestedStartLocation = PickerLocationId.ComputerFolder+ };savePicker.FileTypeChoices.Add(fileExtension.Replace(".", string.Empty).ToUpperInvariant(),new List<string>() { fileExtension!.ToLowerInvariant() });diff --git a/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/PngJpgCompressorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/PngJpgCompressorToolViewModel.csindex aa42e37c8..add7189fe 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/PngJpgCompressorToolViewModel.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/PngJpgCompressor/PngJpgCompressorToolViewModel.cs@@ -219,8 +219,10 @@ namespace DevToys.ViewModels.Tools.PngJpgCompressorif (works.Any(work => work.IsDone)){- var folderPicker = new FolderPicker();- folderPicker.ViewMode = PickerViewMode.List;+ var folderPicker = new FolderPicker+ {+ ViewMode = PickerViewMode.List+ };StorageFolder? selectedFolder = await folderPicker.PickSingleFolderAsync();if (selectedFolder is not null){diff --git a/src/tests/DevToys.Tests/Core/Formatter/BaseNumberFormatterTests.cs b/src/tests/DevToys.Tests/Core/Formatter/BaseNumberFormatterTests.csindex e4ec486e6..a6fff9af5 100644--- a/src/tests/DevToys.Tests/Core/Formatter/BaseNumberFormatterTests.cs+++ b/src/tests/DevToys.Tests/Core/Formatter/BaseNumberFormatterTests.cs@@ -8,27 +8,27 @@ namespace DevToys.Tests.Core.Formatterpublic class BaseNumberFormatterTests{[DataTestMethod]- [DataRow("C6AEA155", 3333333333, false)]- [DataRow("C6AE A155", 3333333333, true)]- public void HexadecimalToDecimal(string input, long expectedResult, bool isFormatted)+ [DataRow("C6AEA155", 3333333333)]+ [DataRow("C6AE A155", 3333333333)]+ public void HexadecimalToDecimal(string input, long expectedResult){Assert.AreEqual(expectedResult, NumberBaseFormatter.StringToBase(input, NumberBaseFormat.Hexadecimal));}[DataTestMethod]- [DataRow("30653520525", 3333333333, false)]- [DataRow("30 653 520 525", 3333333333, true)]- public void OctalToDecimal(string input, long expectedResult, bool isFormatted)+ [DataRow("30653520525", 3333333333)]+ [DataRow("30 653 520 525", 3333333333)]+ public void OctalToDecimal(string input, long expectedResult){Assert.AreEqual(expectedResult, NumberBaseFormatter.StringToBase(input, NumberBaseFormat.Octal));}[DataTestMethod]- [DataRow("000101001101", 333, false)]- [DataRow("0001 0100 1101", 333, true)]- [DataRow("11000110101011101010000101010101", 3333333333, false)]- [DataRow("1100 0110 1010 1110 1010 0001 0101 0101", 3333333333, true)]- public void BinaryToDecimal(string input, long expectedResult, bool isFormatted)+ [DataRow("000101001101", 333)]+ [DataRow("0001 0100 1101", 333)]+ [DataRow("11000110101011101010000101010101", 3333333333)]+ [DataRow("1100 0110 1010 1110 1010 0001 0101 0101", 3333333333)]+ public void BinaryToDecimal(string input, long expectedResult){Assert.AreEqual(expectedResult, NumberBaseFormatter.StringToBase(input, NumberBaseFormat.Binary));}