Skip to content

Commit 468f3ba

Browse files
committed
Selectively enable and fix a few more rules
1 parent 416b58a commit 468f3ba

File tree

18 files changed

+45
-30
lines changed

18 files changed

+45
-30
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ dotnet_diagnostic.CA1506.severity = warning
5757
dotnet_diagnostic.CA1507.severity = error
5858
# CA1508: Avoid dead conditional code
5959
dotnet_diagnostic.CA1508.severity = error
60+
# CA1802: Use Literals Where Appropriate
61+
dotnet_diagnostic.CA1802.severity = error
62+
# CA1805: Do not initialize unnecessarily.
63+
dotnet_diagnostic.CA1805.severity = error
64+
# CA1820: Test for empty strings using string length
65+
dotnet_diagnostic.CA1820.severity = error
6066
# CA1822: Mark members as static
6167
dotnet_diagnostic.CA1822.severity = error
6268
# CA1823: Avoid unused private fields
@@ -65,9 +71,13 @@ dotnet_diagnostic.CA1823.severity = error
6571
dotnet_diagnostic.CA2007.severity = error
6672
# CA2016: Forward the CancellationToken parameter to methods that take one
6773
dotnet_diagnostic.CA2016.severity = error
74+
# CA2213: Disposable fields should be disposed
75+
dotnet_diagnostic.CA2213.severity = error
6876
# CA2254: The logging message template should not vary between calls to 'LoggerExtensions.*'
6977
dotnet_diagnostic.CA2254.severity = silent
7078

79+
# RCS1049: Simplify boolean comparison
80+
dotnet_diagnostic.RCS1049.severity = error
7181
# RCS1102: Make class static
7282
dotnet_diagnostic.RCS1102.severity = error
7383
# RCS1139: Add summary element to documentation comment

PowerShellEditorServices.Common.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<!-- See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview -->
1515
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1616
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
17+
<!-- TODO: Enable <AnalysisMode>All</AnalysisMode> -->
1718
<!-- See: https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/implicit-namespaces -->
1819
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
1920
</PropertyGroup>

src/PowerShellEditorServices.Hosting/Configuration/EditorServicesConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public EditorServicesConfig(
7676
/// <summary>
7777
/// Names of or paths to any additional modules to load on startup.
7878
/// </summary>
79-
public IReadOnlyList<string> AdditionalModules { get; set; } = null;
79+
public IReadOnlyList<string> AdditionalModules { get; set; }
8080

8181
/// <summary>
8282
/// Flags of features to enable on startup.
8383
/// </summary>
84-
public IReadOnlyList<string> FeatureFlags { get; set; } = null;
84+
public IReadOnlyList<string> FeatureFlags { get; set; }
8585

8686
/// <summary>
8787
/// The console REPL experience to use in the integrated console
@@ -97,12 +97,12 @@ public EditorServicesConfig(
9797
/// <summary>
9898
/// Configuration for the language server protocol transport to use.
9999
/// </summary>
100-
public ITransportConfig LanguageServiceTransport { get; set; } = null;
100+
public ITransportConfig LanguageServiceTransport { get; set; }
101101

102102
/// <summary>
103103
/// Configuration for the debug adapter protocol transport to use.
104104
/// </summary>
105-
public ITransportConfig DebugServiceTransport { get; set; } = null;
105+
public ITransportConfig DebugServiceTransport { get; set; }
106106

107107
/// <summary>
108108
/// PowerShell profile locations for Editor Services to use for its profiles.

src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public sealed class StdioTransportConfig : ITransportConfig
4949

5050
public string SessionFileTransportName => "Stdio";
5151

52-
public IReadOnlyDictionary<string, object> SessionFileEntries { get; } = null;
52+
public IReadOnlyDictionary<string, object> SessionFileEntries { get; }
5353

5454
public Task<(Stream inStream, Stream outStream)> ConnectStreamsAsync()
5555
{

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static EditorServicesServerFactory Create(string logPath, int minimumLogL
5858
SelfLog.Enable(msg => Debug.WriteLine(msg));
5959
#endif
6060

61-
ILoggerFactory loggerFactory = new LoggerFactory().AddSerilog();
61+
LoggerFactory loggerFactory = new();
62+
loggerFactory.AddSerilog();
6263

6364
// Hook up logging from the host so that its recorded in the log file
6465
hostLogger.Subscribe(new HostLoggerAdapter(loggerFactory));

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void Dispose()
124124
_debugAdapterServer.Dispose();
125125
_inputStream.Dispose();
126126
_outputStream.Dispose();
127+
_loggerFactory.Dispose();
127128
_serverStopped.SetResult(true);
128129
// TODO: If the debugger has stopped, should we clear the breakpoints?
129130
}

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public AnalysisService(
136136
public void StartScriptDiagnostics(
137137
ScriptFile[] filesToAnalyze)
138138
{
139-
if (_configurationService.CurrentSettings.ScriptAnalysis.Enable == false)
139+
if (!_configurationService.CurrentSettings.ScriptAnalysis.Enable)
140140
{
141141
return;
142142
}
@@ -468,7 +468,7 @@ private static Hashtable GetCommentHelpRuleSettings(string helpLocation, bool fo
468468
}
469469

470470
#region IDisposable Support
471-
private bool disposedValue = false; // To detect redundant calls
471+
private bool disposedValue; // To detect redundant calls
472472

473473
protected virtual void Dispose(bool disposing)
474474
{

src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public Task<ScriptFileMarker[]> AnalyzeScriptAsync(string scriptContent, Hashtab
258258
public PssaCmdletAnalysisEngine RecreateWithRules(string[] rules) => new(_logger, _analysisRunspacePool, _pssaModuleInfo, rules);
259259

260260
#region IDisposable Support
261-
private bool disposedValue = false; // To detect redundant calls
261+
private bool disposedValue; // To detect redundant calls
262262

263263
protected virtual void Dispose(bool disposing)
264264
{

src/PowerShellEditorServices/Services/PowerShell/Utility/ErrorRecordExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility
1212
{
1313
internal static class ErrorRecordExtensions
1414
{
15-
private static readonly Action<PSObject> s_setWriteStreamProperty = null;
15+
private static readonly Action<PSObject> s_setWriteStreamProperty;
1616

1717
[SuppressMessage("Performance", "CA1810:Initialize reference type static fields inline", Justification = "cctor needed for version specific initialization")]
1818
static ErrorRecordExtensions()

src/PowerShellEditorServices/Services/TextDocument/FoldingReference.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class FoldingReference : IComparable<FoldingReference>, IEquatable<Fold
2020
/// <summary>
2121
/// The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line.
2222
/// </summary>
23-
public int StartCharacter { get; set; } = 0;
23+
public int StartCharacter { get; set; }
2424

2525
/// <summary>
2626
/// The zero-based line number where the folded range ends.
@@ -30,7 +30,7 @@ internal class FoldingReference : IComparable<FoldingReference>, IEquatable<Fold
3030
/// <summary>
3131
/// The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line.
3232
/// </summary>
33-
public int EndCharacter { get; set; } = 0;
33+
public int EndCharacter { get; set; }
3434

3535
/// <summary>
3636
/// Describes the kind of the folding range such as `comment' or 'region'.

0 commit comments

Comments
 (0)