diff --git a/.editorconfig b/.editorconfig
index e0f9bbf3f..b4753066b 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -13,6 +13,33 @@ trim_trailing_whitespace = true
csharp_space_before_open_square_brackets = true
csharp_space_after_keywords_in_control_flow_statements = true
+# CS0168: The variable 'var' is declared but never used
+dotnet_diagnostic.CS0168.severity = error
+# CS0169: The private field 'class member' is never used
+dotnet_diagnostic.CS0169.severity = error
+# CS0219: The variable 'variable' is assigned but its value is never used
+dotnet_diagnostic.CS0219.severity = error
+# CS0414: The private field 'field' is assigned but its value is never used
+dotnet_diagnostic.CS0414.severity = error
+# CA1068: CancellationToken parameters must come last
+dotnet_diagnostic.CA1068.severity = error
+# CA1822: Mark members as static
+dotnet_diagnostic.CA1822.severity = error
+# CA1823: Avoid unused private fields
+dotnet_diagnostic.CA1823.severity = error
+# CA2007: Do not directly await a Task
+dotnet_diagnostic.CA2007.severity = error
+# CA2016: Forward the CancellationToken parameter to methods that take one
+dotnet_diagnostic.CA2016.severity = error
+# All maintainability issues (dead code etc.)
+# See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/maintainability-warnings
+dotnet_analyzer_diagnostic.category-Maintainability.severity = error
+# VSTHRD002: Synchronously waiting on tasks or awaiters may cause deadlocks
+# TODO: Fix all of these issues and explicitly ignore the intentional ones.
+dotnet_diagnostic.VSTHRD002.severity = silent
+# VSTHRD200: Use "Async" suffix for awaitable methods
+dotnet_diagnostic.VSTHRD200.severity = silent
+
[*.{json}]
indent_size = 2
trim_trailing_whitespace = true
diff --git a/PowerShellEditorServices.Common.props b/PowerShellEditorServices.Common.props
index ea41c7b43..59da7d55c 100644
--- a/PowerShellEditorServices.Common.props
+++ b/PowerShellEditorServices.Common.props
@@ -11,5 +11,8 @@
git
https://github.com/PowerShell/PowerShellEditorServices
portable
+
+ true
+
diff --git a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
index e41042396..10b7281af 100644
--- a/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
+++ b/src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs
@@ -226,7 +226,7 @@ public void Dispose()
// This is not high priority, since the PSES process shouldn't be reused
}
- private void LoadEditorServices()
+ private static void LoadEditorServices()
{
// This must be in its own method, since the actual load happens when the calling method is called
// The call within this method is therefore a total no-op
@@ -317,7 +317,7 @@ private void LogHostInformation()
LogOperatingSystemDetails();
}
- private string GetPSOutputEncoding()
+ private static string GetPSOutputEncoding()
{
using (var pwsh = SMA.PowerShell.Create())
{
@@ -346,7 +346,7 @@ private void LogOperatingSystemDetails()
");
}
- private string GetOSArchitecture()
+ private static string GetOSArchitecture()
{
#if CoreCLR
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
diff --git a/src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj b/src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj
index 16ab98595..58d4fa85c 100644
--- a/src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj
+++ b/src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj
@@ -31,10 +31,6 @@
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs
index af154d105..b0cc81605 100644
--- a/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs
+++ b/src/PowerShellEditorServices.VSCode/CustomViews/CustomViewBase.cs
@@ -28,40 +28,31 @@ public CustomViewBase(
this.languageServer = languageServer;
}
- internal async Task CreateAsync()
- {
- await languageServer.SendRequestAsync(
+ internal Task CreateAsync() =>
+ languageServer.SendRequestAsync(
NewCustomViewRequest.Method,
new NewCustomViewRequest
{
Id = this.Id,
Title = this.Title,
ViewType = this.ViewType,
- }
- );
- }
+ });
- public async Task Show(ViewColumn viewColumn)
- {
- await languageServer.SendRequestAsync(
+ public Task Show(ViewColumn viewColumn) =>
+ languageServer.SendRequestAsync(
ShowCustomViewRequest.Method,
new ShowCustomViewRequest
{
Id = this.Id,
ViewColumn = viewColumn
- }
- );
- }
+ });
- public async Task Close()
- {
- await languageServer.SendRequestAsync(
+ public Task Close() =>
+ languageServer.SendRequestAsync(
CloseCustomViewRequest.Method,
new CloseCustomViewRequest
{
Id = this.Id,
- }
- );
- }
+ });
}
}
diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs
index dcac2ba44..ca3e53ad6 100644
--- a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs
+++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs
@@ -21,9 +21,8 @@ public HtmlContentView(
{
}
- public async Task SetContentAsync(string htmlBodyContent)
- {
- await languageServer.SendRequestAsync(
+ public Task SetContentAsync(string htmlBodyContent) =>
+ languageServer.SendRequestAsync(
SetHtmlContentViewRequest.Method,
new SetHtmlContentViewRequest
{
@@ -31,31 +30,24 @@ await languageServer.SendRequestAsync(
HtmlContent = new HtmlContent { BodyContent = htmlBodyContent }
}
);
- }
-
- public async Task SetContentAsync(HtmlContent htmlContent)
- {
- HtmlContent validatedContent =
- new HtmlContent()
- {
- BodyContent = htmlContent.BodyContent,
- JavaScriptPaths = this.GetUriPaths(htmlContent.JavaScriptPaths),
- StyleSheetPaths = this.GetUriPaths(htmlContent.StyleSheetPaths)
- };
- await languageServer.SendRequestAsync(
+ public Task SetContentAsync(HtmlContent htmlContent) =>
+ languageServer.SendRequestAsync(
SetHtmlContentViewRequest.Method,
new SetHtmlContentViewRequest
{
Id = this.Id,
- HtmlContent = validatedContent
+ HtmlContent = new HtmlContent()
+ {
+ BodyContent = htmlContent.BodyContent,
+ JavaScriptPaths = HtmlContentView.GetUriPaths(htmlContent.JavaScriptPaths),
+ StyleSheetPaths = HtmlContentView.GetUriPaths(htmlContent.StyleSheetPaths)
+ }
}
);
- }
- public async Task AppendContentAsync(string appendedHtmlBodyContent)
- {
- await languageServer.SendRequestAsync(
+ public Task AppendContentAsync(string appendedHtmlBodyContent) =>
+ languageServer.SendRequestAsync(
AppendHtmlContentViewRequest.Method,
new AppendHtmlContentViewRequest
{
@@ -63,9 +55,8 @@ await languageServer.SendRequestAsync(
AppendedHtmlBodyContent = appendedHtmlBodyContent
}
);
- }
- private string[] GetUriPaths(string[] filePaths)
+ private static string[] GetUriPaths(string[] filePaths)
{
return
filePaths?
diff --git a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs
index df8ac001d..dfdf5e3cb 100644
--- a/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs
+++ b/src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentViewsFeature.cs
@@ -21,7 +21,7 @@ public async Task CreateHtmlContentViewAsync(string viewTitle)
viewTitle,
languageServer);
- await htmlView.CreateAsync();
+ await htmlView.CreateAsync().ConfigureAwait(false);
this.AddView(htmlView);
return htmlView;
diff --git a/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs b/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs
index 661797f1d..8d25db01d 100644
--- a/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs
+++ b/src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs
@@ -156,7 +156,7 @@ public object GetService(Type serviceType)
/// In .NET Framework, this returns null.
///
/// The assembly load context used for loading PSES, or null in .NET Framework.
- public object GetPsesAssemblyLoadContext()
+ public static object GetPsesAssemblyLoadContext()
{
if (!VersionUtils.IsNetCore)
{
@@ -172,7 +172,7 @@ public object GetPsesAssemblyLoadContext()
///
/// The absolute path of the assembly to load.
/// The loaded assembly object.
- public Assembly LoadAssemblyInPsesLoadContext(string assemblyPath)
+ public static Assembly LoadAssemblyInPsesLoadContext(string assemblyPath)
{
if (!VersionUtils.IsNetCore)
{
diff --git a/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs b/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs
index 0ab4fe497..f83dd7d20 100644
--- a/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs
+++ b/src/PowerShellEditorServices/Extensions/Api/EditorUIService.cs
@@ -116,7 +116,7 @@ public async Task PromptInputAsync(string message)
new ShowInputPromptRequest
{
Name = message,
- }).Returning(CancellationToken.None);
+ }).Returning(CancellationToken.None).ConfigureAwait(false);
if (response.PromptCancelled)
{
@@ -142,7 +142,7 @@ public async Task> PromptMultipleSelectionAsync(string mes
Message = message,
Choices = choiceDetails,
DefaultChoices = defaultChoiceIndexes?.ToArray(),
- }).Returning(CancellationToken.None);
+ }).Returning(CancellationToken.None).ConfigureAwait(false);
if (response.PromptCancelled)
{
@@ -168,7 +168,7 @@ public async Task PromptSelectionAsync(string message, IReadOnlyList -1 ? new[] { defaultChoiceIndex } : null,
- }).Returning(CancellationToken.None);
+ }).Returning(CancellationToken.None).ConfigureAwait(false);
if (response.PromptCancelled)
{
diff --git a/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs b/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs
index 3d2dabf7f..98eb9f06e 100644
--- a/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs
+++ b/src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs
@@ -147,7 +147,7 @@ public IReadOnlyList GetOpenedFiles()
return files.AsReadOnly();
}
- private IEditorScriptFile GetEditorFileFromScriptFile(ScriptFile file)
+ private static IEditorScriptFile GetEditorFileFromScriptFile(ScriptFile file)
{
return new EditorScriptFile(file);
}
diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj
index 5c5a7c928..562239ded 100644
--- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj
+++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj
@@ -1,5 +1,4 @@
-
diff --git a/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs b/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs
index b842193c7..70b671e54 100644
--- a/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs
+++ b/src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs
@@ -362,7 +362,7 @@ private PowerShellResult InvokePowerShell(PSCommand command)
///
/// The PowerShell instance to execute.
/// The output of PowerShell execution.
- private Collection InvokePowerShellWithModulePathPreservation(System.Management.Automation.PowerShell powershell)
+ private static Collection InvokePowerShellWithModulePathPreservation(System.Management.Automation.PowerShell powershell)
{
using (PSModulePathPreserver.Take())
{
diff --git a/src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs b/src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs
index e7d0217c9..dd0ef0d1b 100644
--- a/src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs
+++ b/src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs
@@ -42,7 +42,7 @@ public PesterCodeLensProvider(ConfigurationService configurationService)
/// The Pester symbol to get CodeLenses for.
/// The script file the Pester symbol comes from.
/// All CodeLenses for the given Pester symbol.
- private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile scriptFile)
+ private static CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile scriptFile)
{
string word = pesterSymbol.Command == PesterCommandType.It ? "test" : "tests";
var codeLensResults = new CodeLens[]
diff --git a/src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs b/src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs
index 2964770d6..84119ee81 100644
--- a/src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs
+++ b/src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs
@@ -86,7 +86,7 @@ public CodeLens ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile)
ScriptFile[] references = _workspaceService.ExpandScriptReferences(
scriptFile);
- SymbolReference foundSymbol = _symbolsService.FindFunctionDefinitionAtLocation(
+ SymbolReference foundSymbol = SymbolsService.FindFunctionDefinitionAtLocation(
scriptFile,
codeLens.Range.Start.Line + 1,
codeLens.Range.Start.Character + 1);
diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs
index 3f6bf2bf8..ab49bd21a 100644
--- a/src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs
+++ b/src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs
@@ -47,7 +47,7 @@ public async Task> GetBreakpointsAsync()
// Legacy behavior
PSCommand psCommand = new PSCommand();
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
- IEnumerable breakpoints = await _powerShellContextService.ExecuteCommandAsync(psCommand);
+ IEnumerable breakpoints = await _powerShellContextService.ExecuteCommandAsync(psCommand).ConfigureAwait(false);
return breakpoints.ToList();
}
@@ -133,7 +133,7 @@ public async Task> SetBreakpointsAsync(string esc
if (psCommand != null)
{
IEnumerable setBreakpoints =
- await _powerShellContextService.ExecuteCommandAsync(psCommand);
+ await _powerShellContextService.ExecuteCommandAsync(psCommand).ConfigureAwait(false);
configuredBreakpoints.AddRange(
setBreakpoints.Select(BreakpointDetails.Create));
}
@@ -210,7 +210,7 @@ public async Task> SetCommandBreakpoints(I
if (psCommand != null)
{
IEnumerable setBreakpoints =
- await _powerShellContextService.ExecuteCommandAsync(psCommand);
+ await _powerShellContextService.ExecuteCommandAsync(psCommand).ConfigureAwait(false);
configuredBreakpoints.AddRange(
setBreakpoints.Select(CommandBreakpointDetails.Create));
}
@@ -301,7 +301,7 @@ public async Task RemoveBreakpointsAsync(IEnumerable breakpoints)
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");
psCommand.AddParameter("Id", breakpoints.Select(b => b.Id).ToArray());
- await _powerShellContextService.ExecuteCommandAsync