From ea7fefa3a164190208badc493792772fbe4553fc Mon Sep 17 00:00:00 2001 From: "Andrew Petrochuk (from Dev Box)" Date: Mon, 25 Dec 2023 09:44:18 -0800 Subject: [PATCH] Enabled more analyzers --- .editorconfig | 9 ++ src/PAModel/CanvasDocument.cs | 2 +- .../EditorState/CombinedTemplateState.cs | 18 ++-- src/PAModel/EditorState/ControlState.cs | 2 +- src/PAModel/Entropy.cs | 4 +- .../Deltas/ChangeComponentFunction.cs | 2 +- .../MergeTool/Deltas/ChangeProperty.cs | 2 +- .../Deltas/DocumentPropertiesChange.cs | 2 +- src/PAModel/PAConvert/ErrorContainer.cs | 2 +- src/PAModel/PAConvert/Parser/Parser.cs | 2 +- src/PAModel/PAConvert/Yaml/YamlConverter.cs | 4 +- src/PAModel/PAConvert/Yaml/YamlLexer.cs | 4 +- .../PAConvert/Yaml/YamlPocoSerializer.cs | 2 +- src/PAModel/PAConvert/Yaml/YamlWriter.cs | 2 +- src/PAModel/Schemas/adhoc/Control.cs | 12 +-- src/PAModel/Schemas/adhoc/DataSources.cs | 4 +- .../Schemas/adhoc/TemplateMetadataJson.cs | 4 +- src/PAModel/Serializers/MsAppSerializer.cs | 2 + .../Serializers/TransformResourceJson.cs | 4 +- .../SourceTransforms/AppTestTransform.cs | 2 +- .../SourceTransforms/GroupControlTransform.cs | 2 +- src/PAModel/Utility/FilePath.cs | 2 +- src/PAModelTests/AppTestsTest.cs | 3 +- src/PAModelTests/DataSourceTests.cs | 2 +- .../DefaultValuesTransformTests.cs | 6 +- src/PAModelTests/ErrorTests.cs | 4 +- src/PAModelTests/SmartMergeTests.cs | 2 +- .../YamlSerializerTests.cs | 9 +- src/PAModelTests/YamlTest.cs | 88 +++++++++---------- 29 files changed, 108 insertions(+), 95 deletions(-) diff --git a/.editorconfig b/.editorconfig index 558809cd..b922094c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -522,6 +522,14 @@ dotnet_diagnostic.CA1708.severity = error dotnet_diagnostic.CA1712.severity = error dotnet_diagnostic.CA1710.severity = error dotnet_diagnostic.CA1720.severity = error +dotnet_diagnostic.CA1810.severity = error +dotnet_diagnostic.CA1821.severity = error +dotnet_diagnostic.CA1822.severity = error +dotnet_diagnostic.CA1823.severity = error +dotnet_diagnostic.CA1827.severity = error +dotnet_diagnostic.CA1826.severity = error +dotnet_diagnostic.CA1849.severity = error +dotnet_diagnostic.CA2000.severity = error [*.cs] csharp_indent_labels = one_less_than_current @@ -578,3 +586,4 @@ csharp_style_pattern_matching_over_as_with_null_check = true:suggestion csharp_style_prefer_not_pattern = true:suggestion csharp_style_prefer_extended_property_pattern = true:suggestion dotnet_diagnostic.CA1802.severity = error +dotnet_diagnostic.CA1805.severity = error diff --git a/src/PAModel/CanvasDocument.cs b/src/PAModel/CanvasDocument.cs index 625c6c08..ca63003a 100644 --- a/src/PAModel/CanvasDocument.cs +++ b/src/PAModel/CanvasDocument.cs @@ -515,7 +515,7 @@ internal HashSet GetImportedComponents() return set; } - private FilePath GetAssetFilePathWithoutPrefix(string path) + private static FilePath GetAssetFilePathWithoutPrefix(string path) { return FilePath.FromMsAppPath(path.Substring(AssetFilePathPrefix.Length)); } diff --git a/src/PAModel/EditorState/CombinedTemplateState.cs b/src/PAModel/EditorState/CombinedTemplateState.cs index eba0e629..704f5b6a 100644 --- a/src/PAModel/EditorState/CombinedTemplateState.cs +++ b/src/PAModel/EditorState/CombinedTemplateState.cs @@ -22,25 +22,25 @@ internal class CombinedTemplateState // Used with templates. public bool? IsComponentTemplate { get; set; } public bool? FirstParty { get; set; } - public ComponentDefinitionInfoJson ComponentDefinitionInfo { get; set; } = null; + public ComponentDefinitionInfoJson ComponentDefinitionInfo { get; set; } // Present for component templates with functions public CustomPropertyJson[] CustomProperties { get; set; } - public bool? IsComponentLocked { get; set; } = null; - public bool? ComponentChangedSinceFileImport { get; set; } = null; - public bool? ComponentAllowCustomization { get; set; } = null; - public string TemplateOriginalName { get; set; } = null; - public ComponentType? ComponentType { get; set; } = null; + public bool? IsComponentLocked { get; set; } + public bool? ComponentChangedSinceFileImport { get; set; } + public bool? ComponentAllowCustomization { get; set; } + public string TemplateOriginalName { get; set; } + public ComponentType? ComponentType { get; set; } // Present on PCF - public string TemplateDisplayName { get; set; } = null; + public string TemplateDisplayName { get; set; } public string DynamicControlDefinitionJson { get; set; } - public ComponentManifest ComponentManifest { get; set; } = null; + public ComponentManifest ComponentManifest { get; set; } // Present on Legacy DataTable columns - public string CustomControlDefinitionJson { get; set; } = null; + public string CustomControlDefinitionJson { get; set; } [JsonExtensionData] public Dictionary ExtensionData { get; set; } diff --git a/src/PAModel/EditorState/ControlState.cs b/src/PAModel/EditorState/ControlState.cs index 96558d74..46b4fdc7 100644 --- a/src/PAModel/EditorState/ControlState.cs +++ b/src/PAModel/EditorState/ControlState.cs @@ -44,7 +44,7 @@ internal class ControlState // For galleries, we need to persist the galleryTemplate control name as a child of this // to properly pair up the studio state for roundtripping // This isn't needed otherwise, if we weren't worried about exact round-tripping we could recreate the control with a different name - public string GalleryTemplateChildName { get; set; } = null; + public string GalleryTemplateChildName { get; set; } public bool? IsComponentDefinition { get; set; } diff --git a/src/PAModel/Entropy.cs b/src/PAModel/Entropy.cs index 9a5a1d3a..1ee09790 100644 --- a/src/PAModel/Entropy.cs +++ b/src/PAModel/Entropy.cs @@ -182,14 +182,14 @@ public void Add(ResourceJson resource, int order) } // Using the name of the resource combined with the content kind as a key to avoid collisions across different resource types. - public string GetResourcesJsonIndicesKey(ResourceJson resource) + public static string GetResourcesJsonIndicesKey(ResourceJson resource) { return resource.Content + "-" + resource.Name; } // The key is of the format ContentKind-ResourceName. eg. Image-close. // Removing the 'ContentKind-' gives the resource name - public string GetResourceNameFromKey(string key) + public static string GetResourceNameFromKey(string key) { var prefix = key.Split(new char[] { '-' }).First(); return key.Substring(prefix.Length + 1); diff --git a/src/PAModel/MergeTool/Deltas/ChangeComponentFunction.cs b/src/PAModel/MergeTool/Deltas/ChangeComponentFunction.cs index e223158e..1b169a18 100644 --- a/src/PAModel/MergeTool/Deltas/ChangeComponentFunction.cs +++ b/src/PAModel/MergeTool/Deltas/ChangeComponentFunction.cs @@ -74,7 +74,7 @@ private class ChangeComponentFunctionVisitor : DefaultVisitor private readonly string _property; private readonly FunctionNode _func; private readonly bool _wasRemoved; - private bool _success = false; + private bool _success; public static bool ApplyChange(BlockNode block, ControlPath path, string property, FunctionNode func, bool wasRemoved) { diff --git a/src/PAModel/MergeTool/Deltas/ChangeProperty.cs b/src/PAModel/MergeTool/Deltas/ChangeProperty.cs index 5ffa1bab..9646a791 100644 --- a/src/PAModel/MergeTool/Deltas/ChangeProperty.cs +++ b/src/PAModel/MergeTool/Deltas/ChangeProperty.cs @@ -74,7 +74,7 @@ private class ChangePropertyVisitor : DefaultVisitor private readonly string _property; private readonly string _expression; private readonly bool _wasRemoved; - private bool _success = false; + private bool _success; public static bool ApplyChange(BlockNode block, ControlPath path, string property, string expression, bool wasRemoved) { diff --git a/src/PAModel/MergeTool/Deltas/DocumentPropertiesChange.cs b/src/PAModel/MergeTool/Deltas/DocumentPropertiesChange.cs index a469fd78..453b8890 100644 --- a/src/PAModel/MergeTool/Deltas/DocumentPropertiesChange.cs +++ b/src/PAModel/MergeTool/Deltas/DocumentPropertiesChange.cs @@ -12,7 +12,7 @@ internal class DocumentPropertiesChange : IDelta private readonly object _propertyValue; private readonly JsonElement _extensionDataValue; private readonly bool _isExtensionData; - private readonly bool _wasRemoved = false; + private readonly bool _wasRemoved; public DocumentPropertiesChange(string name, object value) { diff --git a/src/PAModel/PAConvert/ErrorContainer.cs b/src/PAModel/PAConvert/ErrorContainer.cs index 4cc6dc57..40c7fcd6 100644 --- a/src/PAModel/PAConvert/ErrorContainer.cs +++ b/src/PAModel/PAConvert/ErrorContainer.cs @@ -66,7 +66,7 @@ public void Write(TextWriter output) public override string ToString() { - var s = new StringWriter(); + using var s = new StringWriter(); Write(s); return s.ToString(); } diff --git a/src/PAModel/PAConvert/Parser/Parser.cs b/src/PAModel/PAConvert/Parser/Parser.cs index b1c9dc81..9a9e64b9 100644 --- a/src/PAModel/PAConvert/Parser/Parser.cs +++ b/src/PAModel/PAConvert/Parser/Parser.cs @@ -338,7 +338,7 @@ private ArgMetadataBlockNode ParseArgMetadataBlock(YamlToken p) } } - private bool IsControlStart(string line) + private static bool IsControlStart(string line) { if (!TryParseIdent(line, out _, out var length)) return false; diff --git a/src/PAModel/PAConvert/Yaml/YamlConverter.cs b/src/PAModel/PAConvert/Yaml/YamlConverter.cs index 68969aa2..fdd0e4a7 100644 --- a/src/PAModel/PAConvert/Yaml/YamlConverter.cs +++ b/src/PAModel/PAConvert/Yaml/YamlConverter.cs @@ -15,7 +15,7 @@ public static Dictionary Read(TextReader reader, string filename { var properties = new Dictionary(StringComparer.Ordinal); - var yaml = new YamlLexer(reader, filenameHint); + using var yaml = new YamlLexer(reader, filenameHint); while (true) { @@ -44,7 +44,7 @@ public static Dictionary Read(TextReader reader, string filename public static void Write(TextWriter writer, IDictionary properties) { - var yaml = new YamlWriter(writer); + using var yaml = new YamlWriter(writer); // Sort by keys to enforce canonical format. foreach (var kv in properties.OrderBy(x => x.Key)) diff --git a/src/PAModel/PAConvert/Yaml/YamlLexer.cs b/src/PAModel/PAConvert/Yaml/YamlLexer.cs index 7889482c..d0e7903e 100644 --- a/src/PAModel/PAConvert/Yaml/YamlLexer.cs +++ b/src/PAModel/PAConvert/Yaml/YamlLexer.cs @@ -31,11 +31,11 @@ internal class YamlLexer : IDisposable // for error handling private readonly string _currentFileName; - private string _currentLineContents = null; + private string _currentLineContents; // Per https://github.com/microsoft/PowerApps-Language-Tooling/issues/115, // We allow comments, but don't round-trip them. Issue a warning. - public SourceLocation? _commentStrippedWarning = null; + public SourceLocation? _commentStrippedWarning; private bool _isDisposed; public const string MissingSingleQuoteFunctionNode = "Missing closing \' in Function Node"; public const string MissingSingleQuoteComponent = "Missing closing \' in Component"; diff --git a/src/PAModel/PAConvert/Yaml/YamlPocoSerializer.cs b/src/PAModel/PAConvert/Yaml/YamlPocoSerializer.cs index fcfe1065..d4bb96e5 100644 --- a/src/PAModel/PAConvert/Yaml/YamlPocoSerializer.cs +++ b/src/PAModel/PAConvert/Yaml/YamlPocoSerializer.cs @@ -56,7 +56,7 @@ public static void CanonicalWrite(TextWriter writer, object obj) _ = writer ?? throw new ArgumentNullException(nameof(writer)); _ = obj ?? throw new ArgumentNullException(nameof(obj)); - var yaml = new YamlWriter(writer); + using var yaml = new YamlWriter(writer); WriteObject(yaml, obj); } diff --git a/src/PAModel/PAConvert/Yaml/YamlWriter.cs b/src/PAModel/PAConvert/Yaml/YamlWriter.cs index d28aff11..a7509873 100644 --- a/src/PAModel/PAConvert/Yaml/YamlWriter.cs +++ b/src/PAModel/PAConvert/Yaml/YamlWriter.cs @@ -191,7 +191,7 @@ private void WriteIndent() } } - private string NormalizeNewlines(string x) + private static string NormalizeNewlines(string x) { return x.Replace("\r\n", "\n").Replace("\r", "\n"); } diff --git a/src/PAModel/Schemas/adhoc/Control.cs b/src/PAModel/Schemas/adhoc/Control.cs index 7f612c31..2b467a93 100644 --- a/src/PAModel/Schemas/adhoc/Control.cs +++ b/src/PAModel/Schemas/adhoc/Control.cs @@ -49,15 +49,15 @@ public class Template // Present for component templates with functions public CustomPropertyJson[] CustomProperties { get; set; } - public ComponentType? ComponentType { get; set; } = null; + public ComponentType? ComponentType { get; set; } // Present on PCF - public string TemplateDisplayName { get; set; } = null; + public string TemplateDisplayName { get; set; } public bool? FirstParty { get; set; } public string DynamicControlDefinitionJson { get; set; } // Present on Legacy DataTable columns - public string CustomControlDefinitionJson { get; set; } = null; + public string CustomControlDefinitionJson { get; set; } [JsonExtensionData] public Dictionary ExtensionData { get; set; } @@ -120,16 +120,16 @@ public class Item public Template Template { get; set; } public RuleEntry[] Rules { get; set; } public Item[] Children { get; set; } - public double Index { get; set; } = 0.0; + public double Index { get; set; } // For matching up within a Theme. public string StyleName { get; set; } public List GroupedControlsKey { get; set; } - public bool IsGroupControl { get; set; } = false; + public bool IsGroupControl { get; set; } // Present on children of AutoLayout controls - public DynamicPropertyJson[] DynamicProperties { get; set; } = null; + public DynamicPropertyJson[] DynamicProperties { get; set; } // Present on children of AutoLayout controls public bool? HasDynamicProperties { get; set; } diff --git a/src/PAModel/Schemas/adhoc/DataSources.cs b/src/PAModel/Schemas/adhoc/DataSources.cs index b267f78e..3c801af2 100644 --- a/src/PAModel/Schemas/adhoc/DataSources.cs +++ b/src/PAModel/Schemas/adhoc/DataSources.cs @@ -54,7 +54,7 @@ public string GetUniqueName() // Was the environment guid removed from the view name? // This allows for switching environments to just switch the pkg folder - public bool? TrimmedViewName { get; set; } = null; + public bool? TrimmedViewName { get; set; } // Key is guid, value is Json-encoded metadata. public IDictionary DataEntityMetadataJson { get; set; } @@ -90,7 +90,7 @@ internal class DataSourceDefinition /// This is done to avoid copying which could be expensive. /// Read Only makes the shared instance virtually immutable. /// - public IReadOnlyDictionary UnusedDataSources { get; set; } = null; + public IReadOnlyDictionary UnusedDataSources { get; set; } [JsonExtensionData] public Dictionary ExtensionData { get; set; } diff --git a/src/PAModel/Schemas/adhoc/TemplateMetadataJson.cs b/src/PAModel/Schemas/adhoc/TemplateMetadataJson.cs index 729edf04..fa1fe02f 100644 --- a/src/PAModel/Schemas/adhoc/TemplateMetadataJson.cs +++ b/src/PAModel/Schemas/adhoc/TemplateMetadataJson.cs @@ -15,7 +15,7 @@ internal class TemplateMetadataJson // Ok to be null. // Will default to: DateTime.Now.ToUniversalTime().Ticks.ToString(); public string Version { get; set; } - public ComponentType? ComponentType { get; set; } = null; + public ComponentType? ComponentType { get; set; } public bool? IsComponentLocked { get; set; } public bool? ComponentChangedSinceFileImport { get; set; } @@ -23,7 +23,7 @@ internal class TemplateMetadataJson public CustomPropertyJson[] CustomProperties { get; set; } - public DataComponentDefinitionJson DataComponentDefinitionKey { get; set; } = null; + public DataComponentDefinitionJson DataComponentDefinitionKey { get; set; } [JsonExtensionData] public Dictionary ExtensionData { get; set; } diff --git a/src/PAModel/Serializers/MsAppSerializer.cs b/src/PAModel/Serializers/MsAppSerializer.cs index 99ac9728..a0f04653 100644 --- a/src/PAModel/Serializers/MsAppSerializer.cs +++ b/src/PAModel/Serializers/MsAppSerializer.cs @@ -72,7 +72,9 @@ public static CanvasDocument Load(Stream streamToMsapp, ErrorContainer errors) ZipArchive zipOpen; try { +#pragma warning disable CA2000 // Dispose objects before losing scope zipOpen = new ZipArchive(streamToMsapp, ZipArchiveMode.Read); +#pragma warning restore CA2000 // Dispose objects before losing scope } catch (Exception e) { diff --git a/src/PAModel/Serializers/TransformResourceJson.cs b/src/PAModel/Serializers/TransformResourceJson.cs index 246bb242..c02eaf14 100644 --- a/src/PAModel/Serializers/TransformResourceJson.cs +++ b/src/PAModel/Serializers/TransformResourceJson.cs @@ -63,13 +63,13 @@ public static void AddLocalAssetEntriesToResourceJson(this CanvasDocument app) var orderedIndices = app._entropy.ResourcesJsonIndices.OrderBy(x => x.Value); foreach (var kvp in orderedIndices) { - var resourceName = app._entropy.GetResourceNameFromKey(kvp.Key); + var resourceName = Entropy.GetResourceNameFromKey(kvp.Key); var resource = app._resourcesJson.Resources.Where(x => x.Name == resourceName); orderedResourcesList.Add(resource.SingleOrDefault()); } // Handle the cases when some new files were added to the asset folder offline. The entries for the new assets would go at the end, after all the ordered resources have been added. - orderedResourcesList.AddRange(app._resourcesJson.Resources.Where(x => !app._entropy.ResourcesJsonIndices.ContainsKey(app._entropy.GetResourcesJsonIndicesKey(x)))); + orderedResourcesList.AddRange(app._resourcesJson.Resources.Where(x => !app._entropy.ResourcesJsonIndices.ContainsKey(Entropy.GetResourcesJsonIndicesKey(x)))); app._resourcesJson.Resources = orderedResourcesList.ToArray(); } } diff --git a/src/PAModel/SourceTransforms/AppTestTransform.cs b/src/PAModel/SourceTransforms/AppTestTransform.cs index 6acbb32e..faf6ae49 100644 --- a/src/PAModel/SourceTransforms/AppTestTransform.cs +++ b/src/PAModel/SourceTransforms/AppTestTransform.cs @@ -14,7 +14,7 @@ private class TestStepsMetadataJson { public string Description { get; set; } public string Rule { get; set; } - public string ScreenId { get; set; } = null; + public string ScreenId { get; set; } } private static readonly IEnumerable _targets = new List() { "TestCase" }; diff --git a/src/PAModel/SourceTransforms/GroupControlTransform.cs b/src/PAModel/SourceTransforms/GroupControlTransform.cs index b6b8f3bd..3796ee97 100644 --- a/src/PAModel/SourceTransforms/GroupControlTransform.cs +++ b/src/PAModel/SourceTransforms/GroupControlTransform.cs @@ -107,7 +107,7 @@ public void BeforeWrite(BlockNode control) } } - public List GetGroupControlChildren(BlockNode parent) + public static List GetGroupControlChildren(BlockNode parent) { var gcChildren = new List(); foreach (var child in parent.Children) diff --git a/src/PAModel/Utility/FilePath.cs b/src/PAModel/Utility/FilePath.cs index f9290021..4ac0e0ed 100644 --- a/src/PAModel/Utility/FilePath.cs +++ b/src/PAModel/Utility/FilePath.cs @@ -149,7 +149,7 @@ public string HandleFileNameCollisions(string path) return path; } - private string GetCustomExtension(string fileName) + private static string GetCustomExtension(string fileName) { var extension = fileName.EndsWith(yamlExtension, StringComparison.OrdinalIgnoreCase) ? yamlExtension diff --git a/src/PAModelTests/AppTestsTest.cs b/src/PAModelTests/AppTestsTest.cs index 597753a1..4ec4dea3 100644 --- a/src/PAModelTests/AppTestsTest.cs +++ b/src/PAModelTests/AppTestsTest.cs @@ -82,7 +82,8 @@ public void TestPackWhenEntropyIsDeleted(string appName) // re-unpack should succeed (var msapp1, var errors1) = CanvasDocument.LoadFromMsapp(tempFile.FullPath); - msapp1.SaveToSources(new TempDir().Dir); + using var tempSaveDir = new TempDir(); + msapp1.SaveToSources(tempSaveDir.Dir); } } } diff --git a/src/PAModelTests/DataSourceTests.cs b/src/PAModelTests/DataSourceTests.cs index b02360b1..cff8cfce 100644 --- a/src/PAModelTests/DataSourceTests.cs +++ b/src/PAModelTests/DataSourceTests.cs @@ -53,7 +53,7 @@ public void TestTableDefinitionsAreLastEntriesWhenEntropyDeleted(string appName) using (var stream = new FileStream(tempFile.FullPath, FileMode.Open)) { // Read the msapp file - var zipOpen = new ZipArchive(stream, ZipArchiveMode.Read); + using var zipOpen = new ZipArchive(stream, ZipArchiveMode.Read); foreach (var entry in zipOpen.Entries) { diff --git a/src/PAModelTests/DefaultValuesTransformTests.cs b/src/PAModelTests/DefaultValuesTransformTests.cs index 534d5364..9bc2e018 100644 --- a/src/PAModelTests/DefaultValuesTransformTests.cs +++ b/src/PAModelTests/DefaultValuesTransformTests.cs @@ -51,7 +51,7 @@ public void TestCaseWithNullDynamicProperties() Assert.IsTrue(nodeProperties.Count == 1); } - private EditorStateStore getEditorStateStore() + private static EditorStateStore getEditorStateStore() { // creating dynamic properties with Property value null, but with PropertyName var dynPropStates = new List(); @@ -77,7 +77,7 @@ private EditorStateStore getEditorStateStore() return editorStateStore; } - private Theme getTheme() + private static Theme getTheme() { var CustomTheme = new CustomThemeJson() { name = "SomeCustomTheme" }; var themeJson = new ThemesJson() { CurrentTheme = "SomeTheme", CustomThemes = new[] { CustomTheme } }; @@ -86,7 +86,7 @@ private Theme getTheme() } // To Load the fluidGrid template defaults - private Dictionary getTemplateStore() + private static Dictionary getTemplateStore() { var parsedTemplates = new Dictionary(); var fluidGridTemplatePath = Path.Combine(Environment.CurrentDirectory, "Templates", "fluidGrid_2.2.0.xml"); diff --git a/src/PAModelTests/ErrorTests.cs b/src/PAModelTests/ErrorTests.cs index 3eb11cd3..d82d0945 100644 --- a/src/PAModelTests/ErrorTests.cs +++ b/src/PAModelTests/ErrorTests.cs @@ -13,13 +13,13 @@ public class ErrorTests public static string PathToValidMsapp = Path.Combine(Environment.CurrentDirectory, "Apps", "MyWeather.msapp"); public static string PathMissingMsapp = Path.Combine(Environment.CurrentDirectory, "Missing", "Missing.msapp"); public static string PathMissingDir = Path.Combine(Environment.CurrentDirectory, "MissingDirectory"); - public static int counter = 0; + public static int counter; [Fact] public void OpenCorruptedMsApp() { // Empty stream is invalid document, should generate a Read error. - var ms = new MemoryStream(); + using var ms = new MemoryStream(); (var doc, var errors) = CanvasDocument.LoadFromMsapp(ms); Assert.True(errors.HasErrors); diff --git a/src/PAModelTests/SmartMergeTests.cs b/src/PAModelTests/SmartMergeTests.cs index 2767f82b..2448d420 100644 --- a/src/PAModelTests/SmartMergeTests.cs +++ b/src/PAModelTests/SmartMergeTests.cs @@ -17,7 +17,7 @@ public class SmartMergeTests private delegate void BranchChange(CanvasDocument canvasDoc); private delegate void ResultValidator(CanvasDocument canvasDoc); - private void MergeTester(CanvasDocument baseDoc, BranchChange branchAChange, BranchChange branchBChange, ResultValidator resultValidator) + private static void MergeTester(CanvasDocument baseDoc, BranchChange branchAChange, BranchChange branchBChange, ResultValidator resultValidator) { var branchADoc = new CanvasDocument(baseDoc); var branchBDoc = new CanvasDocument(baseDoc); diff --git a/src/PAModelTests/YamlSerializerTests/YamlSerializerTests.cs b/src/PAModelTests/YamlSerializerTests/YamlSerializerTests.cs index 291f8544..6d677aed 100644 --- a/src/PAModelTests/YamlSerializerTests/YamlSerializerTests.cs +++ b/src/PAModelTests/YamlSerializerTests/YamlSerializerTests.cs @@ -30,7 +30,8 @@ public void RoundtripSimpleObject(string objectNameOverride, string firstName, s }; var writer = new StringWriter(); - var serializer = new YamlPocoSerializer(new YamlWriter(writer)); + using var yamlWriter = new YamlWriter(writer); + using var serializer = new YamlPocoSerializer(yamlWriter); // Act serializer.Serialize(simpleObjectIn, objectNameOverride); @@ -47,7 +48,7 @@ public void RoundtripSimpleObject(string objectNameOverride, string firstName, s writer.ToString().Should().Be(expectedYaml); // Arrange - var deserializer = new YamlPocoDeserializer(new StringReader(expectedYaml)) + using var deserializer = new YamlPocoDeserializer(new StringReader(expectedYaml)) { Options = YamlLexerOptions.None }; @@ -72,7 +73,7 @@ public void RoundtripSimpleObject(string objectNameOverride, string firstName, s public void InvalidYaml(string invalidYaml, int errorLine) { // Arrange - var deserializer = new YamlPocoDeserializer(new StringReader(invalidYaml)) + using var deserializer = new YamlPocoDeserializer(new StringReader(invalidYaml)) { Options = YamlLexerOptions.None }; @@ -92,7 +93,7 @@ public void InvalidYaml(string invalidYaml, int errorLine) public void InvalidObjectWithDuplicateNames(string invalidYaml, int errorLine) { // Arrange - var deserializer = new YamlPocoDeserializer(new StringReader(invalidYaml)) + using var deserializer = new YamlPocoDeserializer(new StringReader(invalidYaml)) { Options = YamlLexerOptions.None }; diff --git a/src/PAModelTests/YamlTest.cs b/src/PAModelTests/YamlTest.cs index 9b6be1f7..5f60200a 100644 --- a/src/PAModelTests/YamlTest.cs +++ b/src/PAModelTests/YamlTest.cs @@ -15,7 +15,7 @@ public class YamlTest public void Write1() { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("P0", "abc"); yw.WriteStartObject("Obj1"); yw.WriteProperty("P1a", "A#B"); // induced multiline, |- since no trailing \n @@ -47,7 +47,7 @@ public void Write1() public void WriteEscapes(string value) { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("Foo", value); @@ -86,7 +86,7 @@ public void WriteEscapes(string value) public void NewLinesRoundtrip(string value) { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("Foo", value); var text = sw.ToString(); @@ -98,8 +98,8 @@ public void NewLinesRoundtrip(string value) Assert.AreEqual(normalizedValue, NormNewlines(valueFromYaml)); // Validate it passes our subset. - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); var p = y.ReadNext(); Assert.AreEqual(YamlTokenKind.Property, p.Kind); Assert.AreEqual("Foo", p.Property); @@ -114,7 +114,7 @@ public void NewLinesRoundtrip(string value) public void WriteBool(bool value) { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("P0", value); var t = sw.ToString(); @@ -127,7 +127,7 @@ public void WriteBool(bool value) public void WriteInt() { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("P0", 12); var t = sw.ToString(); @@ -140,7 +140,7 @@ public void WriteInt() public void WriteDouble() { var sw = new StringWriter(); - var yw = new YamlWriter(sw); + using var yw = new YamlWriter(sw); yw.WriteProperty("P0", 1.2); var t = sw.ToString(); @@ -167,8 +167,8 @@ private static string NormNewlines(string x) [DataRow("---")] // multi docs not supported public void ExpectedError(string expr) { - var sr = new StringReader(expr); - var y = new YamlLexer(sr); + using var sr = new StringReader(expr); + using var y = new YamlLexer(sr); AssertLexError(y); } @@ -178,8 +178,8 @@ public void ExpectedError(string expr) [DataRow("Foo:\r\n val\r\n")] // Must have escape if there's a newline public void ExpectedError2(string expr) { - var sr = new StringReader(expr); - var y = new YamlLexer(sr); + using var sr = new StringReader(expr); + using var y = new YamlLexer(sr); var tokenOk = y.ReadNext(); Assert.AreNotEqual(YamlTokenKind.Error, tokenOk.Kind); @@ -200,8 +200,8 @@ public void ErrorOnDuplicate() P2: =456 P1: =duplicate! "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P1=123", y); AssertLex("Obj1:", y); @@ -220,8 +220,8 @@ public void ReadBasic() @"P1: =123 P2: =456 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P1=123", y); AssertLex("P2=456", y); @@ -238,8 +238,8 @@ public void ReadBasicSpans() Obj2: "; - var sr = new StringReader(text); - var y = new YamlLexer(sr, "test.yaml"); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr, "test.yaml"); AssertLex("Obj1:", y, "test.yaml:1,1-1,6"); AssertLex("P1=456", y, "test.yaml:2,4-2,12"); @@ -260,8 +260,8 @@ public void ReadBasicMultiline() def P1: =123 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("M1=abc\r\ndef\r\n", y); AssertLex("P1=123", y); @@ -279,8 +279,8 @@ public void ReadBasicMultiline2() def P1: =123 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("M1=abc\r\n def\r\n", y); AssertLex("P1=123", y); @@ -300,8 +300,8 @@ public void ReadClosing() P2: =2 P3: =3 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P0=1", y); AssertLex("Obj1:", y); @@ -325,8 +325,8 @@ public void ReadEmptyObjects2() Obj1b: Obj2: "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P0=1", y); AssertLex("Obj1:", y); @@ -352,8 +352,8 @@ public void ReadEmptyObjects() Obj3: Obj4: "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P0=1", y); AssertLex("Obj1:", y); @@ -377,8 +377,8 @@ public void ReadEmptyObjectsError() Obj2: ErrorObj3: "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P0=1", y); AssertLex("Obj1:", y); @@ -403,8 +403,8 @@ public void ReadObject() P4a: =X P1b: =DEF "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("P0=123", y); AssertLex("Obj1:", y); @@ -434,8 +434,8 @@ public void ReadComments() P1: =123 # comment2 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLex("Obj1:", y); AssertLex("P1=123", y); @@ -456,7 +456,7 @@ public void ReadComments() [TestMethod] public void ReadDict() { - var reader = new StringReader(expectedYaml); + using var reader = new StringReader(expectedYaml); var props = YamlConverter.Read(reader); Assert.AreEqual(props.Count, 2); @@ -479,7 +479,7 @@ public void ReadDictError() [TestMethod] public void WriteDict() { - var writer = new StringWriter(); + using var writer = new StringWriter(); var d = new Dictionary { @@ -551,8 +551,8 @@ public void MissingClosingQuoteComponentError() Y: =0 ZIndex: =1 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr) + using var sr = new StringReader(text); + using var y = new YamlLexer(sr) { IsComponent = true }; @@ -578,8 +578,8 @@ public void MissingClosingQuoteFunctionNodeError() Y: =0 ZIndex: =1 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr) + using var sr = new StringReader(text); + using var y = new YamlLexer(sr) { IsComponent = true }; @@ -600,8 +600,8 @@ public void MissingClosingQuoteTypeNodeError() Y: =0 ZIndex: =1 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLexErrorMessage(y, YamlLexer.MissingSingleQuoteTypeNode); } @@ -619,8 +619,8 @@ public void MissingClosingQuotePropertyError() Y: =0 ZIndex: =1 "; - var sr = new StringReader(text); - var y = new YamlLexer(sr); + using var sr = new StringReader(text); + using var y = new YamlLexer(sr); AssertLexErrorMessage(y, YamlLexer.MissingSingleQuoteProperty); }