Skip to content

Commit 63b925f

Browse files
committed
Be consistent with error suppression
Avoiding pragmas wherever possible.
1 parent 9b6a2eb commit 63b925f

File tree

16 files changed

+18
-39
lines changed

16 files changed

+18
-39
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ dotnet_diagnostic.CA1068.severity = error
5454
# CA1501: Avoid excessive inheritance
5555
dotnet_diagnostic.CA1501.severity = error
5656
# CA1502: Avoid excessive complexity
57-
dotnet_diagnostic.CA1502.severity = warning
57+
dotnet_diagnostic.CA1502.severity = silent
5858
# CA1505: Avoid unmaintainable code
5959
dotnet_diagnostic.CA1505.severity = error
6060
# CA1506: Avoid excessive class coupling
61-
dotnet_diagnostic.CA1506.severity = warning
61+
dotnet_diagnostic.CA1506.severity = silent
6262
# CA1507: Use nameof in place of string
6363
dotnet_diagnostic.CA1507.severity = error
6464
# CA1508: Avoid dead conditional code

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ protected override void BeginProcessing()
215215
}
216216
#pragma warning restore IDE0022
217217

218-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Uses ThrowTerminatingError() instead")]
218+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "We have to wait here, it's the whole program.")]
219219
protected override void EndProcessing()
220220
{
221221
_logger.Log(PsesLogLevel.Diagnostic, "Beginning EndProcessing block");
@@ -232,9 +232,7 @@ protected override void EndProcessing()
232232
using EditorServicesLoader psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, SessionDetailsPath, _loggerUnsubscribers);
233233
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
234234
// Synchronously start editor services and wait here until it shuts down.
235-
#pragma warning disable VSTHRD002
236235
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
237-
#pragma warning restore VSTHRD002
238236
}
239237
catch (Exception e)
240238
{

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,18 @@ private void ValidateConfiguration()
382382
}
383383
}
384384

385+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1825:Avoid zero-length array allocations", Justification = "Cannot use Array.Empty, since it must work in net452")]
385386
private static Version GetPSVersion()
386387
{
387388
// In order to read the $PSVersionTable variable,
388389
// we are forced to create a new runspace to avoid concurrency issues,
389390
// which is expensive.
390391
// Rather than do that, we instead go straight to the source,
391392
// which is a static property, internal in WinPS and public in PS 6+
392-
#pragma warning disable CA1825
393393
return typeof(PSObject).Assembly
394394
.GetType("System.Management.Automation.PSVersionInfo")
395395
.GetMethod("get_PSVersion", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
396-
.Invoke(null, new object[0] /* Cannot use Array.Empty, since it must work in net452 */) as Version;
397-
#pragma warning restore CA1825
396+
.Invoke(null, new object[0]) as Version;
398397
}
399398
}
400399
}

src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ private void WriteStartupBanner()
304304
_config.PSHost.UI.WriteLine(_config.StartupBanner);
305305
}
306306

307+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD110:Observe result of async calls", Justification = "Intentionally fire and forget.")]
307308
private void DebugServer_OnSessionEnded(object sender, EventArgs args)
308309
{
309310
_logger.Log(PsesLogLevel.Verbose, "Debug session ended, restarting debug service...");

src/PowerShellEditorServices/Extensions/EditorContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ public void SetSelection(
9292
/// Sets a selection in the host editor's active buffer.
9393
/// </summary>
9494
/// <param name="selectionRange">The range of the selection.</param>
95-
#pragma warning disable VSTHRD002
95+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Supporting synchronous API.")]
9696
public void SetSelection(FileRange selectionRange) => editorOperations.SetSelectionAsync(selectionRange.ToBufferRange()).Wait();
97-
#pragma warning restore VSTHRD002
9897

9998
#endregion
10099
}

src/PowerShellEditorServices/Extensions/EditorObject.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,12 @@ internal EditorObject(
115115
/// at the time this method is invoked.
116116
/// </summary>
117117
/// <returns>A instance of the EditorContext class.</returns>
118-
#pragma warning disable VSTHRD002, VSTHRD104
118+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Supporting synchronous API.")]
119119
public EditorContext GetEditorContext() => _editorOperations.GetEditorContextAsync().Result;
120-
#pragma warning restore VSTHRD002, VSTHRD104
121120

122121
internal void SetAsStaticInstance()
123122
{
124-
EditorObject.Instance = this;
123+
Instance = this;
125124
s_editorObjectReady.TrySetResult(true);
126125
}
127126
}

src/PowerShellEditorServices/Extensions/FileContext.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ public void InsertText(
208208
/// </summary>
209209
/// <param name="textToInsert">The text string to insert.</param>
210210
/// <param name="insertRange">The buffer range which will be replaced by the string.</param>
211-
#pragma warning disable VSTHRD002
211+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Supporting synchronous API.")]
212212
public void InsertText(string textToInsert, IFileRange insertRange)
213213
{
214214
editorOperations
215215
.InsertTextAsync(scriptFile.DocumentUri.ToString(), textToInsert, insertRange.ToBufferRange())
216216
.Wait();
217217
}
218-
#pragma warning restore VSTHRD002
219218

220219
#endregion
221220

@@ -233,7 +232,7 @@ public void InsertText(string textToInsert, IFileRange insertRange)
233232
/// the path where the file should be saved,
234233
/// including the file name with extension as the leaf
235234
/// </param>
236-
#pragma warning disable VSTHRD002
235+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Supporting synchronous API.")]
237236
public void SaveAs(string newFilePath)
238237
{
239238
// Do some validation here so that we can provide a helpful error if the path won't work
@@ -248,7 +247,6 @@ public void SaveAs(string newFilePath)
248247

249248
editorOperations.SaveFileAsync(scriptFile.FilePath, newFilePath).Wait();
250249
}
251-
#pragma warning restore VSTHRD002
252250

253251
#endregion
254252
}

src/PowerShellEditorServices/GlobalSuppressions.cs

-9
This file was deleted.

src/PowerShellEditorServices/IsExternalInit.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#pragma warning disable IDE0073
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
#if NET5_0_OR_GREATER
35
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.CompilerServices.IsExternalInit))]
46
#else

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public PsesLanguageServer(
7070
/// cref="PsesServiceCollectionExtensions.AddPsesLanguageServices"/>.
7171
/// </remarks>
7272
/// <returns>A task that completes when the server is ready and listening.</returns>
73-
#pragma warning disable CA1506 // Coupling complexity we don't care about
7473
public async Task StartAsync()
75-
#pragma warning restore CA1506
7674
{
7775
LanguageServer = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
7876
{

src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.PowerShell.EditorServices.Server
1717
{
1818
internal static class PsesServiceCollectionExtensions
1919
{
20+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD110:Observe result of async calls", Justification = "Using lazy initialization.")]
2021
public static IServiceCollection AddPsesLanguageServices(
2122
this IServiceCollection collection,
2223
HostStartupInfo hostStartupInfo)
@@ -48,9 +49,7 @@ public static IServiceCollection AddPsesLanguageServices(
4849
// is ready, it will be available. NOTE: We cannot await this because it
4950
// uses a lazy initialization to avoid a race with the dependency injection
5051
// framework, see the EditorObject class for that!
51-
#pragma warning disable VSTHRD110
5252
extensionService.InitializeAsync();
53-
#pragma warning restore VSTHRD110
5453
return extensionService;
5554
})
5655
.AddSingleton<AnalysisService>();

src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs

-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public LegacyReadLine(
3535
_onIdleAction = onIdleAction;
3636
}
3737

38-
#pragma warning disable CA1502 // Cyclomatic complexity we don't care about
3938
public override string ReadLine(CancellationToken cancellationToken)
40-
#pragma warning restore CA1502
4139
{
4240
string inputBeforeCompletion = null;
4341
string inputAfterCompletion = null;

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Host
2929
using Microsoft.PowerShell.EditorServices.Server;
3030
using OmniSharp.Extensions.DebugAdapter.Protocol.Server;
3131

32-
#pragma warning disable CA1506 // Coupling complexity we don't care about
3332
internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRunspaceContext, IInternalPowerShellExecutionService
34-
#pragma warning restore CA1506
3533
{
3634
internal const string DefaultPrompt = "> ";
3735

src/PowerShellEditorServices/Services/TextDocument/Handlers/DidChangeWatchedFilesHandler.cs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public DidChangeWatchedFilesHandler(
4141
public DidChangeWatchedFilesRegistrationOptions GetRegistrationOptions(
4242
DidChangeWatchedFilesCapability capability,
4343
ClientCapabilities clientCapabilities)
44+
#pragma warning disable CS8601 // Possible null reference assignment (it's from the library).
4445
=> new()
4546
{
4647
Watchers = new[]
@@ -52,6 +53,7 @@ public DidChangeWatchedFilesRegistrationOptions GetRegistrationOptions(
5253
},
5354
},
5455
};
56+
#pragma warning restore CS8601 // Possible null reference assignment.
5557

5658
public Task<Unit> Handle(DidChangeWatchedFilesParams request, CancellationToken cancellationToken)
5759
{

src/PowerShellEditorServices/Services/TextDocument/TokenOperations.cs

-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ internal static class TokenOperations
2525
/// <summary>
2626
/// Extracts all of the unique foldable regions in a script given the list tokens
2727
/// </summary>
28-
#pragma warning disable CA1502 // Cyclomatic complexity we don't care about
2928
internal static FoldingReferenceList FoldableReferences(Token[] tokens)
30-
#pragma warning restore CA1502
3129
{
3230
FoldingReferenceList refList = new();
3331

test/PowerShellEditorServices.Test.E2E/Processes/StdioServerProcess.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public class StdioServerProcess : ServerProcess
2323
/// <summary>
2424
/// The current server process (if any).
2525
/// </summary>
26-
#pragma warning disable CA2213
26+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "It is diposed but with a lock.")]
2727
private Process _serverProcess;
28-
#pragma warning restore CA2213
2928

3029
/// <summary>
3130
/// Create a new <see cref="StdioServerProcess"/>.

0 commit comments

Comments
 (0)