From b1904acd2e1c43bb8686e1be17c10934996158de Mon Sep 17 00:00:00 2001 From: Stian Kroknes Date: Sun, 18 Dec 2022 08:07:35 +0100 Subject: [PATCH] Add analyzers (#22) --- Directory.Build.props | 2 +- .../VisNetwork.Blazor.Sample.csproj | 4 +- .../JSModules/JSModule.Base.cs | 36 +++++++++--------- .../Models/ConfigureOptions.cs | 4 +- src/VisNetwork.Blazor/Models/Edge.cs | 3 +- src/VisNetwork.Blazor/Models/EdgeOptions.cs | 21 ++++++++--- .../Models/ManipulationOptions.cs | 1 + .../Models/NetworkOptions.cs | 3 ++ src/VisNetwork.Blazor/Models/Node.cs | 3 +- src/VisNetwork.Blazor/Models/NodeOptions.cs | 5 ++- src/VisNetwork.Blazor/Network.razor.cs | 37 +++++++++++-------- .../VisNetwork.Blazor.csproj | 18 ++++----- 12 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 7409461..3794211 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -16,7 +16,7 @@ All Recommended true - + true true $(WarningsNotAsErrors);CS1591 diff --git a/sample/VisNetwork.Blazor.Sample/VisNetwork.Blazor.Sample.csproj b/sample/VisNetwork.Blazor.Sample/VisNetwork.Blazor.Sample.csproj index a96b695..c8b263c 100644 --- a/sample/VisNetwork.Blazor.Sample/VisNetwork.Blazor.Sample.csproj +++ b/sample/VisNetwork.Blazor.Sample/VisNetwork.Blazor.Sample.csproj @@ -5,8 +5,8 @@ - - + + diff --git a/src/VisNetwork.Blazor/JSModules/JSModule.Base.cs b/src/VisNetwork.Blazor/JSModules/JSModule.Base.cs index 6dc7d6c..53a6868 100644 --- a/src/VisNetwork.Blazor/JSModules/JSModule.Base.cs +++ b/src/VisNetwork.Blazor/JSModules/JSModule.Base.cs @@ -37,6 +37,7 @@ private async ValueTask InvokeVoidAsync(string identifier, params object[] args) } catch (Exception exception) when (exception is JSDisconnectedException or ObjectDisposedException or TaskCanceledException) { + // ignored } } @@ -59,7 +60,7 @@ private async ValueTask InvokeAsync(string identifier, params ob } } - public async ValueTask DisposeAsync() => await DisposeAsync(true); + public ValueTask DisposeAsync() => DisposeAsync(true); private async ValueTask DisposeAsync(bool disposing) { @@ -69,26 +70,25 @@ private async ValueTask DisposeAsync(bool disposing) { isAsyncDisposed = true; - if (disposing) + if (disposing && moduleTask != null) { - if (moduleTask != null) + var moduleInstance = await moduleTask; + var disposableTask = moduleInstance.DisposeAsync(); + + try + { + await disposableTask; + } + catch when (disposableTask.IsCanceled) { - var moduleInstance = await moduleTask; - var disposableTask = moduleInstance.DisposeAsync(); - - try - { - await disposableTask; - } - catch when (disposableTask.IsCanceled) - { - } - catch (JSDisconnectedException) - { - } - - moduleTask = null; + // Ignore } + catch (JSDisconnectedException) + { + // Ignore + } + + moduleTask = null; } } } diff --git a/src/VisNetwork.Blazor/Models/ConfigureOptions.cs b/src/VisNetwork.Blazor/Models/ConfigureOptions.cs index 91e8fcb..2ee3ef9 100644 --- a/src/VisNetwork.Blazor/Models/ConfigureOptions.cs +++ b/src/VisNetwork.Blazor/Models/ConfigureOptions.cs @@ -18,12 +18,14 @@ public class ConfigureOptions /// public string? Filter { get; set; } +#pragma warning disable S125 // Sections of code should not be commented out /// /// This allows you to put the configure list in another HTML container than below the network. /// //public ElementReference Container {get;set;} +#pragma warning restore S125 // Sections of code should not be commented out - /// + /// /// Show the generate options button at the bottom of the configurator. /// The default is true. /// diff --git a/src/VisNetwork.Blazor/Models/Edge.cs b/src/VisNetwork.Blazor/Models/Edge.cs index 6cb367e..c9497c6 100644 --- a/src/VisNetwork.Blazor/Models/Edge.cs +++ b/src/VisNetwork.Blazor/Models/Edge.cs @@ -2,6 +2,7 @@ namespace VisNetwork.Blazor.Models; +[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4035:Classes implementing \"IEquatable\" should be sealed", Justification = "")] public class Edge : EdgeOption, IEquatable { public Edge() { } @@ -38,5 +39,5 @@ public Edge(string from, string to, string? title = null) public override bool Equals(object? obj) => obj is Edge other && Equals(other); - public bool Equals(Edge? other) => other is object && other != null && other.From == From && other.To == To; + public bool Equals(Edge? other) => other is object && other.From == From && other.To == To; } \ No newline at end of file diff --git a/src/VisNetwork.Blazor/Models/EdgeOptions.cs b/src/VisNetwork.Blazor/Models/EdgeOptions.cs index 675182f..a82e8f1 100644 --- a/src/VisNetwork.Blazor/Models/EdgeOptions.cs +++ b/src/VisNetwork.Blazor/Models/EdgeOptions.cs @@ -1,8 +1,4 @@ -using System; -using System.Drawing; -using System.Xml.Linq; - -namespace VisNetwork.Blazor.Models; +namespace VisNetwork.Blazor.Models; public class EdgeOption { @@ -93,7 +89,20 @@ public class EdgeOption /// public int? SelectionWidth { get; set; } - // public int? Width { get; set; } + /// + /// The width of the edge. If is set, this is not used. + /// + public int? Width { get; set; } + + /// + /// If a number is specified, the maximum width of the edge's label is set to the value. The edge's label's lines will be broken on spaces to stay below the maximum. + /// + public int? WidthConstraint { get; set; } + + /// + /// When a value is set, the edges' width will be scaled using the options in the scaling object defined above. + /// + public int? Value { get; set; } /// /// Option for circle drawn when to and from nodes are the same. diff --git a/src/VisNetwork.Blazor/Models/ManipulationOptions.cs b/src/VisNetwork.Blazor/Models/ManipulationOptions.cs index f150993..13dbed6 100644 --- a/src/VisNetwork.Blazor/Models/ManipulationOptions.cs +++ b/src/VisNetwork.Blazor/Models/ManipulationOptions.cs @@ -4,6 +4,7 @@ /// The options for the manipulation module. /// The manipulation module acts as the camera that looks on the canvas. Does the animation, zooming and focusing. /// +[System.Diagnostics.CodeAnalysis.SuppressMessage("Info Code Smell", "S1135:Track uses of \"TODO\" tags", Justification = "")] public class ManipulationOptions { public bool? Enabled { get; set; } diff --git a/src/VisNetwork.Blazor/Models/NetworkOptions.cs b/src/VisNetwork.Blazor/Models/NetworkOptions.cs index e89183d..45e7c62 100644 --- a/src/VisNetwork.Blazor/Models/NetworkOptions.cs +++ b/src/VisNetwork.Blazor/Models/NetworkOptions.cs @@ -53,7 +53,10 @@ public class NetworkOptions /// public NodeOption? Nodes { get; set; } + +#pragma warning disable S1135 // Track uses of "TODO" tags // TODO groups, can add group:'myGroup' to node, and define styling for groups here +#pragma warning restore S1135 // Track uses of "TODO" tags /// /// Options for the layout module. diff --git a/src/VisNetwork.Blazor/Models/Node.cs b/src/VisNetwork.Blazor/Models/Node.cs index cafd7f1..d9b7fff 100644 --- a/src/VisNetwork.Blazor/Models/Node.cs +++ b/src/VisNetwork.Blazor/Models/Node.cs @@ -2,6 +2,7 @@ namespace VisNetwork.Blazor.Models; +[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4035:Classes implementing \"IEquatable\" should be sealed", Justification = "")] public class Node : NodeOption, IEquatable { /// @@ -22,7 +23,7 @@ public Node(string id, string label, int level, string shape, string? title = nu } public override bool Equals(object? obj) => obj is Node other && Equals(other); - public bool Equals(Node? other) => other is not null && other != null && other.Id == Id; + public bool Equals(Node? other) => other is not null && other.Id == Id; public override int GetHashCode() => Id?.GetHashCode() ?? 0; } diff --git a/src/VisNetwork.Blazor/Models/NodeOptions.cs b/src/VisNetwork.Blazor/Models/NodeOptions.cs index 583c17c..88d2ffc 100644 --- a/src/VisNetwork.Blazor/Models/NodeOptions.cs +++ b/src/VisNetwork.Blazor/Models/NodeOptions.cs @@ -141,8 +141,9 @@ public class NodeOption /// public string? Shape { get; set; } - +#pragma warning disable S125 // Sections of code should not be commented out //public NodeShapePropertiesOption? ShapeProperties { get; set; } +#pragma warning restore S125 // Sections of code should not be commented out /// /// The size is used to determine the size of node shapes that do not have the label inside of them. @@ -403,4 +404,4 @@ public class NodeScalingOptions /// Note: JS lib supports Object or Boolean. /// public bool? Label { get; set; } -} \ No newline at end of file +} diff --git a/src/VisNetwork.Blazor/Network.razor.cs b/src/VisNetwork.Blazor/Network.razor.cs index aa672aa..b6106d0 100644 --- a/src/VisNetwork.Blazor/Network.razor.cs +++ b/src/VisNetwork.Blazor/Network.razor.cs @@ -98,6 +98,7 @@ public partial class Network : IAsyncDisposable [Parameter] public EventCallback OnHidePopup { get; set; } +#pragma warning disable S1135 // Track uses of "TODO" tags // Events triggered the physics simulation. Can be used to trigger GUI updates. // TODO @@ -107,14 +108,18 @@ public partial class Network : IAsyncDisposable // Events triggered by the rendering module. Can be used to draw custom elements on the canvas. // TOOD +#pragma warning restore S1135 // Track uses of "TODO" tags + [Parameter] public EventCallback OnBeforeDrawing { get; set; } [Parameter] public EventCallback OnAfterDrawing { get; set; } +#pragma warning disable S1135 // Track uses of "TODO" tags // Event triggered by the view module. // TODO // Event triggered by the configuration module. // TODO +#pragma warning restore S1135 // Track uses of "TODO" tags /// /// This event is fired when the network has been setup through interop and @@ -142,12 +147,13 @@ async ValueTask IAsyncDisposable.DisposeAsync() } catch when (task.IsCanceled) { + // ignored } catch (JSDisconnectedException) { + // ignored } } - // TOdO } protected override async Task OnParametersSetAsync() @@ -187,66 +193,67 @@ internal async Task SetEventListeners() { if (OnClick.HasDelegate) { - await JS.SetEventListener(element, thisReference, "click"); ; + await JS.SetEventListener(element, thisReference, "click"); } if (OnDoubleClick.HasDelegate) { - await JS.SetEventListener(element, thisReference, "doubleClick"); ; + await JS.SetEventListener(element, thisReference, "doubleClick"); } if (OnContext.HasDelegate) { - await JS.SetEventListener(element, thisReference, "oncontext"); ; + await JS.SetEventListener(element, thisReference, "oncontext"); } if (OnHold.HasDelegate) { - await JS.SetEventListener(element, thisReference, "hold"); ; + await JS.SetEventListener(element, thisReference, "hold"); } if (OnRelease.HasDelegate) { - await JS.SetEventListener(element, thisReference, "release"); ; + await JS.SetEventListener(element, thisReference, "release"); } if (OnSelect.HasDelegate) { - await JS.SetEventListener(element, thisReference, "select"); ; + await JS.SetEventListener(element, thisReference, "select"); } if (OnSelectNode.HasDelegate) { - await JS.SetEventListener(element, thisReference, "selectNode"); ; + await JS.SetEventListener(element, thisReference, "selectNode"); } if (OnDeselectNode.HasDelegate) { - await JS.SetEventListener(element, thisReference, "deselectNode"); ; + await JS.SetEventListener(element, thisReference, "deselectNode"); } if (OnSelectEdge.HasDelegate) { - await JS.SetEventListener(element, thisReference, "selectEdge"); ; + await JS.SetEventListener(element, thisReference, "selectEdge"); } if (OnDeselectEdge.HasDelegate) { - await JS.SetEventListener(element, thisReference, "deselectEdge"); ; + await JS.SetEventListener(element, thisReference, "deselectEdge"); } if (OnShowPopup.HasDelegate) { - await JS.SetEventListener(element, thisReference, "showPopup"); ; + await JS.SetEventListener(element, thisReference, "showPopup"); } if (OnHidePopup.HasDelegate) { - await JS.SetEventListener(element, thisReference, "hidePopup"); ; + await JS.SetEventListener(element, thisReference, "hidePopup"); } // Rendering if (OnBeforeDrawing.HasDelegate) { - await JS.SetEventListener(element, thisReference, "beforeDrawing"); ; + await JS.SetEventListener(element, thisReference, "beforeDrawing"); } if (OnAfterDrawing.HasDelegate) { - await JS.SetEventListener(element, thisReference, "afterDrawing"); ; + await JS.SetEventListener(element, thisReference, "afterDrawing"); } } [JSInvokable] + [System.Diagnostics.CodeAnalysis.SuppressMessage("AsyncUsage", "AsyncFixer01:Unnecessary async/await usage", Justification = "")] public async Task EventCallback(string eventName, string eventJson) { var jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; diff --git a/src/VisNetwork.Blazor/VisNetwork.Blazor.csproj b/src/VisNetwork.Blazor/VisNetwork.Blazor.csproj index 93eef44..0a2430c 100644 --- a/src/VisNetwork.Blazor/VisNetwork.Blazor.csproj +++ b/src/VisNetwork.Blazor/VisNetwork.Blazor.csproj @@ -30,14 +30,6 @@ 7.0 - - - - - - - - @@ -55,8 +47,16 @@ --> + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - +