Skip to content

Commit 1f6211f

Browse files
committed
Apply Roslynator fixups via CLI tool
It's far from perfect.
1 parent 2ef44e8 commit 1f6211f

File tree

6 files changed

+20
-36
lines changed

6 files changed

+20
-36
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Linq;
99
using System.Management.Automation;
1010
using System.Reflection;
11-
using SMA = System.Management.Automation;
1211
using System.Management.Automation.Runspaces;
1312
using Microsoft.PowerShell.EditorServices.Hosting;
1413
using System.Globalization;
@@ -316,7 +315,7 @@ private string GetLogDirPath()
316315
private void RemovePSReadLineForStartup()
317316
{
318317
_logger.Log(PsesLogLevel.Verbose, "Removing PSReadLine");
319-
using (var pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace))
318+
using (var pwsh = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
320319
{
321320
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
322321
.AddParameter("Name", "PSReadLine")

src/PowerShellEditorServices/Extensions/EditorFileRanges.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static FileScriptPosition FromOffset(FileContext file, int offset)
3737

3838
if (offset >= fileText.Length)
3939
{
40-
throw new ArgumentException(nameof(offset), "Offset greater than file length");
40+
throw new ArgumentException("Offset greater than file length", nameof(offset));
4141
}
4242

4343
int lastLineOffset = -1;

src/PowerShellEditorServices/Logging/PsesTelemetryEvent.cs

+4-16
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,14 @@ internal class PsesTelemetryEvent : Dictionary<string, object>
1414
{
1515
public string EventName
1616
{
17-
get
18-
{
19-
return this["EventName"].ToString() ?? "PsesEvent";
20-
}
21-
set
22-
{
23-
this["EventName"] = value;
24-
}
17+
get => this["EventName"].ToString() ?? "PsesEvent";
18+
set => this["EventName"] = value;
2519
}
2620

2721
public JObject Data
2822
{
29-
get
30-
{
31-
return this["Data"] as JObject ?? new JObject();
32-
}
33-
set
34-
{
35-
this["Data"] = value;
36-
}
23+
get => this["Data"] as JObject ?? new JObject();
24+
set => this["Data"] = value;
3725
}
3826
}
3927
}

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

+11-14
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ internal static string GetUniqueIdFromDiagnostic(Diagnostic diagnostic)
3939

4040
var sb = new StringBuilder(256)
4141
.Append(diagnostic.Source ?? "?")
42-
.Append("_")
42+
.Append('_')
4343
.Append(diagnostic.Code?.IsString ?? true ? diagnostic.Code?.String : diagnostic.Code?.Long.ToString())
44-
.Append("_")
44+
.Append('_')
4545
.Append(diagnostic.Severity?.ToString() ?? "?")
46-
.Append("_")
46+
.Append('_')
4747
.Append(start.Line)
48-
.Append(":")
48+
.Append(':')
4949
.Append(start.Character)
50-
.Append("-")
50+
.Append('-')
5151
.Append(end.Line)
52-
.Append(":")
52+
.Append(':')
5353
.Append(end.Character);
5454

5555
var id = sb.ToString();
@@ -208,14 +208,11 @@ public async Task<string> GetCommentHelpText(string functionText, string helpLoc
208208

209209
ScriptFileMarker[] analysisResults = await AnalysisEngine.AnalyzeScriptAsync(functionText, commentHelpSettings).ConfigureAwait(false);
210210

211-
if (analysisResults.Length == 0
212-
|| analysisResults[0]?.Correction?.Edits == null
213-
|| analysisResults[0].Correction.Edits.Count() == 0)
214-
{
215-
return null;
216-
}
217-
218-
return analysisResults[0].Correction.Edits[0].Text;
211+
return analysisResults.Length is 0
212+
|| analysisResults[0]?.Correction?.Edits is null
213+
|| analysisResults[0].Correction.Edits.Length is 0
214+
? null
215+
: analysisResults[0].Correction.Edits[0].Text;
219216
}
220217

221218
/// <summary>

src/PowerShellEditorServices/Services/Template/TemplateService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task<bool> ImportPlasterIfInstalledAsync()
7272

7373
this._logger.LogTrace("Checking if Plaster is installed...");
7474

75-
PSObject moduleObject = (await _executionService.ExecutePSCommandAsync<PSObject>(psCommand, CancellationToken.None).ConfigureAwait(false)).First();
75+
PSObject moduleObject = (await _executionService.ExecutePSCommandAsync<PSObject>(psCommand, CancellationToken.None).ConfigureAwait(false))[0];
7676

7777
this.isPlasterInstalled = moduleObject != null;
7878
string installedQualifier =
@@ -135,7 +135,7 @@ public async Task<TemplateDetails[]> GetAvailableTemplatesAsync(
135135
psCommand,
136136
CancellationToken.None).ConfigureAwait(false);
137137

138-
this._logger.LogTrace($"Found {templateObjects.Count()} Plaster templates");
138+
this._logger.LogTrace($"Found {templateObjects.Count} Plaster templates");
139139

140140
return
141141
templateObjects

test/PowerShellEditorServices.Test/Session/WorkspaceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void CanRecurseDirectoryTreeWithLimit()
128128
ignoreReparsePoints: s_defaultIgnoreReparsePoints
129129
);
130130

131-
Assert.Equal(1, fileList.Count);
131+
Assert.Single(fileList);
132132
Assert.Equal(Path.Combine(workspace.WorkspacePath, "rootfile.ps1"), fileList[0]);
133133
}
134134

0 commit comments

Comments
 (0)