Skip to content

Commit 9c86505

Browse files
committed
Enable, fix, and enforce recommended .NET analyzers
1 parent ac3941b commit 9c86505

9 files changed

+45
-35
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
using System.Linq;
88
using System.Reflection;
99
using System.Text;
10-
using NStack;
10+
1111
using OutGridView.Models;
12+
1213
using Terminal.Gui;
1314

1415
namespace OutGridView.Cmdlet
1516
{
16-
internal class ConsoleGui : IDisposable
17+
internal sealed class ConsoleGui : IDisposable
1718
{
1819
private const string FILTER_LABEL = "Filter";
1920
// This adjusts the left margin of all controls
@@ -154,7 +155,7 @@ private void ListViewSource_MarkChanged(object s, GridViewDataSource.RowMarkedEv
154155
_inputSource.GridViewRowList[a.Row.OriginalIndex].IsMarked = a.Row.IsMarked;
155156
}
156157

157-
private void Accept()
158+
private static void Accept()
158159
{
159160
Application.RequestStop();
160161
}

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System;
55
using System.Collections;
66
using System.Collections.Generic;
7+
78
using NStack;
9+
810
using Terminal.Gui;
911

1012
namespace OutGridView.Cmdlet
1113
{
12-
internal class GridViewDataSource : IListDataSource
14+
internal sealed class GridViewDataSource : IListDataSource
1315
{
1416
public List<GridViewRow> GridViewRowList { get; set; }
1517

@@ -42,7 +44,7 @@ public void SetMark(int item, bool value)
4244
MarkChanged?.Invoke(this, args);
4345
}
4446

45-
public class RowMarkedEventArgs : EventArgs
47+
public sealed class RowMarkedEventArgs : EventArgs
4648
{
4749
public GridViewRow Row { get; set; }
4850
public bool OldValue { get; set; }
@@ -57,7 +59,7 @@ public IList ToList()
5759
}
5860

5961
// A slightly adapted method from gui.cs: https://github.com/migueldeicaza/gui.cs/blob/fc1faba7452ccbdf49028ac49f0c9f0f42bbae91/Terminal.Gui/Views/ListView.cs#L433-L461
60-
private void RenderUstr(ConsoleDriver driver, ustring ustr, int col, int line, int width)
62+
private static void RenderUstr(ConsoleDriver driver, ustring ustr, int col, int line, int width)
6163
{
6264
int used = 0;
6365
int index = 0;

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace OutGridView.Cmdlet
55
{
6-
internal class GridViewDetails
6+
internal sealed class GridViewDetails
77
{
88
// Contains the width of each column in the grid view.
99
public int[] ListViewColumnWidths { get; set; }

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewHelpers.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using System;
54
using System.Collections.Generic;
65
using System.Linq;
76
using System.Text;
87
using System.Text.RegularExpressions;
9-
using NStack;
10-
using OutGridView.Models;
11-
using Terminal.Gui;
128

139
namespace OutGridView.Cmdlet
1410
{
15-
internal class GridViewHelpers
11+
internal sealed class GridViewHelpers
1612
{
1713
// Add all items already selected plus any that match the filter
1814
// The selected items should be at the top of the list, in their original order

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,10 @@
2727
<ItemGroup>
2828
<None Update="Microsoft.PowerShell.ConsoleGuiTools.psd1" CopyToOutputDirectory="PreserveNewest" />
2929
</ItemGroup>
30+
31+
<PropertyGroup>
32+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
33+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
34+
<AnalysisMode>Recommended</AnalysisMode>
35+
</PropertyGroup>
3036
</Project>

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Management.Automation;
88
using System.Management.Automation.Internal;
9+
910
using OutGridView.Models;
1011

1112
namespace OutGridView.Cmdlet
@@ -180,6 +181,7 @@ protected override void EndProcessing()
180181
public void Dispose()
181182
{
182183
_consoleGui.Dispose();
184+
GC.SuppressFinalize(this);
183185
}
184186
}
185187
}

src/Microsoft.PowerShell.ConsoleGuiTools/ShowObjectTreeCmdletCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Management.Automation;
88
using System.Management.Automation.Internal;
9+
910
using OutGridView.Models;
1011

1112
namespace OutGridView.Cmdlet
@@ -149,7 +150,7 @@ protected override void EndProcessing()
149150

150151
public void Dispose()
151152
{
152-
153+
GC.SuppressFinalize(this);
153154
}
154155
}
155156
}

src/Microsoft.PowerShell.ConsoleGuiTools/ShowObjectView.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections;
56
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Management.Automation;
611
using System.Reflection;
12+
using System.Text.RegularExpressions;
13+
14+
using OutGridView.Models;
15+
716
using Terminal.Gui;
817
using Terminal.Gui.Trees;
9-
using System.Management.Automation;
10-
using System.Management.Automation.Internal;
11-
using System.Linq;
12-
using System.Diagnostics;
13-
using System.Collections;
14-
using OutGridView.Models;
15-
using System.Text.RegularExpressions;
16-
using System.IO;
1718

1819
namespace OutGridView.Cmdlet
1920
{
20-
internal class ShowObjectView : Window, ITreeBuilder<object>
21+
internal sealed class ShowObjectView : Window, ITreeBuilder<object>
2122
{
2223
private readonly TreeView<object> tree;
2324
private readonly RegexTreeViewTextFilter filter;
@@ -133,7 +134,7 @@ public ShowObjectView(List<object> rootObjects, ApplicationData applicationData)
133134
}
134135
private void SetRegexError(string error)
135136
{
136-
if (string.Equals(error, filterErrorLabel.Text.ToString()))
137+
if (string.Equals(error, filterErrorLabel.Text.ToString(), StringComparison.Ordinal))
137138
{
138139
return;
139140
}
@@ -197,7 +198,7 @@ public bool CanExpand(object toExpand)
197198
return IsBasicType(toExpand);
198199
}
199200

200-
private bool IsBasicType(object value)
201+
private static bool IsBasicType(object value)
201202
{
202203
return value != null && value is not string && !value.GetType().IsValueType;
203204
}
@@ -245,7 +246,7 @@ public IEnumerable<object> GetChildren(object forObject)
245246
return children;
246247
}
247248

248-
private IEnumerable<object> GetExtraChildren(object forObject)
249+
private static IEnumerable<object> GetExtraChildren(object forObject)
249250
{
250251
if (forObject is DirectoryInfo dir)
251252
{
@@ -277,7 +278,7 @@ internal static void Run(List<PSObject> objects, ApplicationData applicationData
277278
}
278279
}
279280

280-
class CachedMemberResultElement
281+
sealed class CachedMemberResultElement
281282
{
282283
public int Index;
283284
public object Value;
@@ -304,7 +305,7 @@ public override string ToString()
304305
}
305306
}
306307

307-
class CachedMemberResult
308+
sealed class CachedMemberResult
308309
{
309310
public MemberInfo Member;
310311
public object Value;
@@ -402,7 +403,7 @@ public override string ToString()
402403
return Member.Name + ": " + representation;
403404
}
404405
}
405-
private class RegexTreeViewTextFilter : ITreeViewFilter<object>
406+
private sealed class RegexTreeViewTextFilter : ITreeViewFilter<object>
406407
{
407408
private readonly ShowObjectView parent;
408409
readonly TreeView<object> _forTree;

src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Collections.Generic;
6+
using System.Globalization;
7+
using System.Linq;
58
using System.Management.Automation;
69
using System.Management.Automation.Internal;
7-
using System.Linq;
8-
using System.Globalization;
9-
using System.Collections.Generic;
10+
1011
using Microsoft.PowerShell.Commands;
12+
1113
using OutGridView.Models;
12-
using System.Text.RegularExpressions;
1314

1415
namespace OutGridView.Cmdlet
1516
{
@@ -44,7 +45,7 @@ public FormatViewDefinition GetFormatViewDefinitionForObject(PSObject obj)
4445
return extendedTypeDefinition.FormatViewDefinition[0];
4546
}
4647

47-
public DataTableRow CastObjectToDataTableRow(PSObject ps, List<DataTableColumn> dataColumns, int objectIndex)
48+
public static DataTableRow CastObjectToDataTableRow(PSObject ps, List<DataTableColumn> dataColumns, int objectIndex)
4849
{
4950
Dictionary<string, IValue> valuePairs = new Dictionary<string, IValue>();
5051

@@ -72,7 +73,7 @@ public DataTableRow CastObjectToDataTableRow(PSObject ps, List<DataTableColumn>
7273
return new DataTableRow(valuePairs, objectIndex);
7374
}
7475

75-
private void SetTypesOnDataColumns(List<DataTableRow> dataTableRows, List<DataTableColumn> dataTableColumns)
76+
private static void SetTypesOnDataColumns(List<DataTableRow> dataTableRows, List<DataTableColumn> dataTableColumns)
7677
{
7778
var dataRows = dataTableRows.Select(x => x.Values);
7879

@@ -187,7 +188,7 @@ public DataTable CastObjectsToTableView(List<PSObject> psObjects)
187188
"System.Security.SecureString",
188189
"System.Numerics.BigInteger"
189190
};
190-
private bool PSObjectIsPrimitive(PSObject ps)
191+
private static bool PSObjectIsPrimitive(PSObject ps)
191192
{
192193
var psBaseType = ps.BaseObject.GetType();
193194

0 commit comments

Comments
 (0)