Skip to content

Commit b27d21a

Browse files
committed
Treat members that could be static but aren't as errors (and fix)
1 parent ec4bc2f commit b27d21a

29 files changed

+80
-78
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ csharp_space_after_keywords_in_control_flow_statements = true
1515

1616
# CA2007: Do not directly await a Task
1717
dotnet_diagnostic.CA2007.severity = error
18+
# CA1822: Mark members as static
19+
dotnet_diagnostic.CA1822.severity = error
1820

1921
[*.{json}]
2022
indent_size = 2

src/PowerShellEditorServices.Hosting/EditorServicesLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void Dispose()
226226
// This is not high priority, since the PSES process shouldn't be reused
227227
}
228228

229-
private void LoadEditorServices()
229+
private static void LoadEditorServices()
230230
{
231231
// This must be in its own method, since the actual load happens when the calling method is called
232232
// The call within this method is therefore a total no-op
@@ -317,7 +317,7 @@ private void LogHostInformation()
317317
LogOperatingSystemDetails();
318318
}
319319

320-
private string GetPSOutputEncoding()
320+
private static string GetPSOutputEncoding()
321321
{
322322
using (var pwsh = SMA.PowerShell.Create())
323323
{
@@ -346,7 +346,7 @@ private void LogOperatingSystemDetails()
346346
");
347347
}
348348

349-
private string GetOSArchitecture()
349+
private static string GetOSArchitecture()
350350
{
351351
#if CoreCLR
352352
if (Environment.OSVersion.Platform != PlatformID.Win32NT)

src/PowerShellEditorServices.VSCode/CustomViews/HtmlContentView.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public Task SetContentAsync(HtmlContent htmlContent) =>
4040
HtmlContent = new HtmlContent()
4141
{
4242
BodyContent = htmlContent.BodyContent,
43-
JavaScriptPaths = this.GetUriPaths(htmlContent.JavaScriptPaths),
44-
StyleSheetPaths = this.GetUriPaths(htmlContent.StyleSheetPaths)
43+
JavaScriptPaths = HtmlContentView.GetUriPaths(htmlContent.JavaScriptPaths),
44+
StyleSheetPaths = HtmlContentView.GetUriPaths(htmlContent.StyleSheetPaths)
4545
}
4646
}
4747
);
@@ -56,7 +56,7 @@ public Task AppendContentAsync(string appendedHtmlBodyContent) =>
5656
}
5757
);
5858

59-
private string[] GetUriPaths(string[] filePaths)
59+
private static string[] GetUriPaths(string[] filePaths)
6060
{
6161
return
6262
filePaths?

src/PowerShellEditorServices/Extensions/Api/EditorExtensionServiceProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public object GetService(Type serviceType)
156156
/// In .NET Framework, this returns null.
157157
/// </summary>
158158
/// <returns>The assembly load context used for loading PSES, or null in .NET Framework.</returns>
159-
public object GetPsesAssemblyLoadContext()
159+
public static object GetPsesAssemblyLoadContext()
160160
{
161161
if (!VersionUtils.IsNetCore)
162162
{
@@ -172,7 +172,7 @@ public object GetPsesAssemblyLoadContext()
172172
/// </summary>
173173
/// <param name="assemblyPath">The absolute path of the assembly to load.</param>
174174
/// <returns>The loaded assembly object.</returns>
175-
public Assembly LoadAssemblyInPsesLoadContext(string assemblyPath)
175+
public static Assembly LoadAssemblyInPsesLoadContext(string assemblyPath)
176176
{
177177
if (!VersionUtils.IsNetCore)
178178
{

src/PowerShellEditorServices/Extensions/Api/WorkspaceService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public IReadOnlyList<IEditorScriptFile> GetOpenedFiles()
147147
return files.AsReadOnly();
148148
}
149149

150-
private IEditorScriptFile GetEditorFileFromScriptFile(ScriptFile file)
150+
private static IEditorScriptFile GetEditorFileFromScriptFile(ScriptFile file)
151151
{
152152
return new EditorScriptFile(file);
153153
}

src/PowerShellEditorServices/Services/Analysis/PssaCmdletAnalysisEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ private PowerShellResult InvokePowerShell(PSCommand command)
362362
/// </summary>
363363
/// <param name="powershell">The PowerShell instance to execute.</param>
364364
/// <returns>The output of PowerShell execution.</returns>
365-
private Collection<PSObject> InvokePowerShellWithModulePathPreservation(System.Management.Automation.PowerShell powershell)
365+
private static Collection<PSObject> InvokePowerShellWithModulePathPreservation(System.Management.Automation.PowerShell powershell)
366366
{
367367
using (PSModulePathPreserver.Take())
368368
{

src/PowerShellEditorServices/Services/CodeLens/PesterCodeLensProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public PesterCodeLensProvider(ConfigurationService configurationService)
4242
/// <param name="pesterSymbol">The Pester symbol to get CodeLenses for.</param>
4343
/// <param name="scriptFile">The script file the Pester symbol comes from.</param>
4444
/// <returns>All CodeLenses for the given Pester symbol.</returns>
45-
private CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile scriptFile)
45+
private static CodeLens[] GetPesterLens(PesterSymbolReference pesterSymbol, ScriptFile scriptFile)
4646
{
4747
string word = pesterSymbol.Command == PesterCommandType.It ? "test" : "tests";
4848
var codeLensResults = new CodeLens[]

src/PowerShellEditorServices/Services/CodeLens/ReferencesCodeLensProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public CodeLens ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile)
8686
ScriptFile[] references = _workspaceService.ExpandScriptReferences(
8787
scriptFile);
8888

89-
SymbolReference foundSymbol = _symbolsService.FindFunctionDefinitionAtLocation(
89+
SymbolReference foundSymbol = SymbolsService.FindFunctionDefinitionAtLocation(
9090
scriptFile,
9191
codeLens.Range.Start.Line + 1,
9292
codeLens.Range.Start.Character + 1);

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ private async Task FetchStackFramesAsync(string scriptNameOverride)
856856
}
857857
}
858858

859-
private string TrimScriptListingLine(PSObject scriptLineObj, ref int prefixLength)
859+
private static string TrimScriptListingLine(PSObject scriptLineObj, ref int prefixLength)
860860
{
861861
string scriptLine = scriptLineObj.ToString();
862862

@@ -908,7 +908,7 @@ await this.powerShellContext.ExecuteCommandAsync<PSObject>(
908908
string.Join(
909909
Environment.NewLine,
910910
scriptListingLines
911-
.Select(o => this.TrimScriptListingLine(o, ref linePrefixLength))
911+
.Select(o => DebugService.TrimScriptListingLine(o, ref linePrefixLength))
912912
.Where(s => s != null));
913913

914914
this.temporaryScriptListingPath =

src/PowerShellEditorServices/Services/PowerShellContext/Console/ChoicePromptHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Task<int> PromptForChoiceAsync(
144144
throw new TaskCanceledException(task);
145145
}
146146

147-
return this.GetSingleResult(task.GetAwaiter().GetResult());
147+
return ChoicePromptHandler.GetSingleResult(task.GetAwaiter().GetResult());
148148
}));
149149
}
150150

@@ -335,7 +335,7 @@ protected override void OnPromptCancelled()
335335

336336
#region Private Methods
337337

338-
private int GetSingleResult(int[] choiceArray)
338+
private static int GetSingleResult(int[] choiceArray)
339339
{
340340
return
341341
choiceArray != null

0 commit comments

Comments
 (0)