Skip to content

Commit

Permalink
Add analyzers (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
stiankroknes committed Dec 18, 2022
1 parent 6640ed8 commit b1904ac
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AnalysisModeSecurity>All</AnalysisModeSecurity>
<AnalysisModePerformance>Recommended</AnalysisModePerformance>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>

<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!-- Don't make missing XML docs a fatal build error, but still surface so we have visibility into undocumented APIs. -->
<WarningsNotAsErrors>$(WarningsNotAsErrors);CS1591</WarningsNotAsErrors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
</ItemGroup>

Expand Down
36 changes: 18 additions & 18 deletions src/VisNetwork.Blazor/JSModules/JSModule.Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -59,7 +60,7 @@ private async ValueTask<TValue> InvokeAsync<TValue>(string identifier, params ob
}
}

public async ValueTask DisposeAsync() => await DisposeAsync(true);
public ValueTask DisposeAsync() => DisposeAsync(true);

private async ValueTask DisposeAsync(bool disposing)
{
Expand All @@ -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;
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/VisNetwork.Blazor/Models/ConfigureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class ConfigureOptions
/// </summary>
public string? Filter { get; set; }

#pragma warning disable S125 // Sections of code should not be commented out
/// <summary>
/// This allows you to put the configure list in another HTML container than below the network.
/// </summary>
//public ElementReference Container {get;set;}
#pragma warning restore S125 // Sections of code should not be commented out

/// <summary>
/// <summary>
/// Show the generate options button at the bottom of the configurator.
/// The default is true.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/VisNetwork.Blazor/Models/Edge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace VisNetwork.Blazor.Models;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4035:Classes implementing \"IEquatable<T>\" should be sealed", Justification = "<Pending>")]
public class Edge : EdgeOption, IEquatable<Edge>
{
public Edge() { }
Expand Down Expand Up @@ -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;
}
21 changes: 15 additions & 6 deletions src/VisNetwork.Blazor/Models/EdgeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Drawing;
using System.Xml.Linq;

namespace VisNetwork.Blazor.Models;
namespace VisNetwork.Blazor.Models;

public class EdgeOption
{
Expand Down Expand Up @@ -93,7 +89,20 @@ public class EdgeOption
/// </summary>
public int? SelectionWidth { get; set; }

// public int? Width { get; set; }
/// <summary>
/// The width of the edge. If <see cref="Value"/> is set, this is not used.
/// </summary>
public int? Width { get; set; }

/// <summary>
/// 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.
/// </summary>
public int? WidthConstraint { get; set; }

/// <summary>
/// When a value is set, the edges' width will be scaled using the options in the scaling object defined above.
/// </summary>
public int? Value { get; set; }

/// <summary>
/// Option for circle drawn when to and from nodes are the same.
Expand Down
1 change: 1 addition & 0 deletions src/VisNetwork.Blazor/Models/ManipulationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Info Code Smell", "S1135:Track uses of \"TODO\" tags", Justification = "<Pending>")]
public class ManipulationOptions
{
public bool? Enabled { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions src/VisNetwork.Blazor/Models/NetworkOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public class NetworkOptions
/// <value></value>
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

/// <summary>
/// Options for the layout module.
Expand Down
3 changes: 2 additions & 1 deletion src/VisNetwork.Blazor/Models/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace VisNetwork.Blazor.Models;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4035:Classes implementing \"IEquatable<T>\" should be sealed", Justification = "<Pending>")]
public class Node : NodeOption, IEquatable<Node>
{
/// <summary>
Expand All @@ -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;
}
5 changes: 3 additions & 2 deletions src/VisNetwork.Blazor/Models/NodeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ public class NodeOption
/// </summary>
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

/// <summary>
/// The size is used to determine the size of node shapes that do not have the label inside of them.
Expand Down Expand Up @@ -403,4 +404,4 @@ public class NodeScalingOptions
/// Note: JS lib supports Object or Boolean.
/// </summary>
public bool? Label { get; set; }
}
}
37 changes: 22 additions & 15 deletions src/VisNetwork.Blazor/Network.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public partial class Network : IAsyncDisposable

[Parameter] public EventCallback<string> 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

Expand All @@ -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<DrawingEvent> OnBeforeDrawing { get; set; }
[Parameter] public EventCallback<DrawingEvent> 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

/// <summary>
/// This event is fired when the network has been setup through interop and
Expand Down Expand Up @@ -142,12 +147,13 @@ async ValueTask IAsyncDisposable.DisposeAsync()
}
catch when (task.IsCanceled)
{
// ignored
}
catch (JSDisconnectedException)
{
// ignored
}
}
// TOdO
}

protected override async Task OnParametersSetAsync()
Expand Down Expand Up @@ -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 = "<Pending>")]
public async Task EventCallback(string eventName, string eventJson)
{
var jsonOptions = new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
Expand Down
18 changes: 9 additions & 9 deletions src/VisNetwork.Blazor/VisNetwork.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@
<RazorLangVersion>7.0</RazorLangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="JSModule.Methods.cs" />
</ItemGroup>

<ItemGroup>
<None Include="JSModules\JSModule.Base.cs" />
</ItemGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
<Content Update="StaticAssets\*" Pack="false" />
Expand All @@ -55,8 +47,16 @@
</Target>-->

<ItemGroup>
<PackageReference Include="AsyncFixer" Version="1.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.50.0.58025">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.1.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.2.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down

0 comments on commit b1904ac

Please sign in to comment.