Skip to content

Commit

Permalink
Enabled more analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
anpetroc committed Dec 25, 2023
1 parent 6457889 commit ea7fefa
Show file tree
Hide file tree
Showing 29 changed files with 108 additions and 95 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/PAModel/CanvasDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ internal HashSet<string> GetImportedComponents()
return set;
}

private FilePath GetAssetFilePathWithoutPrefix(string path)
private static FilePath GetAssetFilePathWithoutPrefix(string path)
{
return FilePath.FromMsAppPath(path.Substring(AssetFilePathPrefix.Length));
}
Expand Down
18 changes: 9 additions & 9 deletions src/PAModel/EditorState/CombinedTemplateState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> ExtensionData { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/EditorState/ControlState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/Entropy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/MergeTool/Deltas/ChangeComponentFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private class ChangeComponentFunctionVisitor : DefaultVisitor<ControlPath>
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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/MergeTool/Deltas/ChangeProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private class ChangePropertyVisitor : DefaultVisitor<ControlPath>
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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/MergeTool/Deltas/DocumentPropertiesChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/PAConvert/ErrorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/PAConvert/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/PAConvert/Yaml/YamlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static Dictionary<string, string> Read(TextReader reader, string filename
{
var properties = new Dictionary<string, string>(StringComparer.Ordinal);

var yaml = new YamlLexer(reader, filenameHint);
using var yaml = new YamlLexer(reader, filenameHint);

while (true)
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public static Dictionary<string, string> Read(TextReader reader, string filename

public static void Write(TextWriter writer, IDictionary<string, string> 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))
Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/PAConvert/Yaml/YamlLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/PAConvert/Yaml/YamlPocoSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/PAConvert/Yaml/YamlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
12 changes: 6 additions & 6 deletions src/PAModel/Schemas/adhoc/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> ExtensionData { get; set; }
Expand Down Expand Up @@ -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<string> 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; }
Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/Schemas/adhoc/DataSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> DataEntityMetadataJson { get; set; }
Expand Down Expand Up @@ -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.
/// </summary>
public IReadOnlyDictionary<string, LocalDatabaseReferenceDataSource> UnusedDataSources { get; set; } = null;
public IReadOnlyDictionary<string, LocalDatabaseReferenceDataSource> UnusedDataSources { get; set; }

[JsonExtensionData]
public Dictionary<string, JsonElement> ExtensionData { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/Schemas/adhoc/TemplateMetadataJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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; }
public bool? ComponentAllowCustomization { get; set; }

public CustomPropertyJson[] CustomProperties { get; set; }

public DataComponentDefinitionJson DataComponentDefinitionKey { get; set; } = null;
public DataComponentDefinitionJson DataComponentDefinitionKey { get; set; }

[JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/PAModel/Serializers/MsAppSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PAModel/Serializers/TransformResourceJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/SourceTransforms/AppTestTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _targets = new List<string>() { "TestCase" };
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/SourceTransforms/GroupControlTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void BeforeWrite(BlockNode control)
}
}

public List<BlockNode> GetGroupControlChildren(BlockNode parent)
public static List<BlockNode> GetGroupControlChildren(BlockNode parent)
{
var gcChildren = new List<BlockNode>();
foreach (var child in parent.Children)
Expand Down
2 changes: 1 addition & 1 deletion src/PAModel/Utility/FilePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/PAModelTests/AppTestsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PAModelTests/DataSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/PAModelTests/DefaultValuesTransformTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DynamicPropertyState>();
Expand All @@ -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 } };
Expand All @@ -86,7 +86,7 @@ private Theme getTheme()
}

// To Load the fluidGrid template defaults
private Dictionary<string, ControlTemplate> getTemplateStore()
private static Dictionary<string, ControlTemplate> getTemplateStore()
{
var parsedTemplates = new Dictionary<string, ControlTemplate>();
var fluidGridTemplatePath = Path.Combine(Environment.CurrentDirectory, "Templates", "fluidGrid_2.2.0.xml");
Expand Down
4 changes: 2 additions & 2 deletions src/PAModelTests/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PAModelTests/SmartMergeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit ea7fefa

Please sign in to comment.