Skip to content

Commit 2c879ca

Browse files
Merge pull request #1743 from PowerShell/andschwa/dotnet-format
Use `dotnet format` and `roslynator fix` to automatically apply fixes
2 parents 027ff4e + 21b1f35 commit 2c879ca

File tree

169 files changed

+1645
-2294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+1645
-2294
lines changed

.editorconfig

+131-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ insert_final_newline = true
1010
[*.{cs}]
1111
indent_size = 4
1212
trim_trailing_whitespace = true
13+
file_header_template = Copyright (c) Microsoft Corporation.\nLicensed under the MIT License.
1314
csharp_space_before_open_square_brackets = true
1415
csharp_space_after_keywords_in_control_flow_statements = true
1516
csharp_space_before_open_square_brackets = false
17+
csharp_style_expression_bodied_constructors = when_on_single_line
18+
csharp_style_expression_bodied_methods = when_on_single_line
19+
csharp_style_expression_bodied_operators = when_on_single_line
20+
csharp_style_expression_bodied_properties = true
21+
csharp_style_expression_bodied_indexers = true
22+
csharp_style_expression_bodied_accessors = true
23+
csharp_style_expression_bodied_lambdas = when_on_single_line
1624

1725
# CS0168: The variable 'var' is declared but never used
1826
dotnet_diagnostic.CS0168.severity = error
@@ -22,6 +30,8 @@ dotnet_diagnostic.CS0169.severity = error
2230
dotnet_diagnostic.CS0219.severity = error
2331
# CS0414: The private field 'field' is assigned but its value is never used
2432
dotnet_diagnostic.CS0414.severity = error
33+
# CA1067: Should override Equals because it implements IEquatable<T>
34+
dotnet_diagnostic.CA1067.severity = silent
2535
# CA1068: CancellationToken parameters must come last
2636
dotnet_diagnostic.CA1068.severity = error
2737
# CA1822: Mark members as static
@@ -32,6 +42,8 @@ dotnet_diagnostic.CA1823.severity = error
3242
dotnet_diagnostic.CA2007.severity = error
3343
# CA2016: Forward the CancellationToken parameter to methods that take one
3444
dotnet_diagnostic.CA2016.severity = error
45+
# CA2254: The logging message template should not vary between calls to 'LoggerExtensions.*'
46+
dotnet_diagnostic.CA2254.severity = silent
3547

3648
# TODO: Enable all maintainability issues (dead code etc.) and enforce
3749
# See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/maintainability-warnings
@@ -40,26 +52,30 @@ dotnet_analyzer_diagnostic.category-Maintainability.severity = error
4052
# TODO: Fix all of these issues and explicitly ignore the intentional ones!
4153

4254
# CA2016: Forward the CancellationToken parameter to methods that take one
43-
dotnet_diagnostic.CA2016.severity = suggestion
55+
dotnet_diagnostic.CA2016.severity = error
4456
# CS0618: A class member was marked with the Obsolete attribute
4557
dotnet_diagnostic.CS0618.severity = suggestion
4658
# CS0649: Uninitialized private or internal field declaration that is never assigned a value
47-
dotnet_diagnostic.CS0649.severity = suggestion
59+
dotnet_diagnostic.CS0649.severity = warning
4860
# CS1998: This async method lacks 'await' operators and will run synchronously
4961
dotnet_diagnostic.CS1998.severity = suggestion
5062
# CS4014: Consider applying the await operator to the result of the call
5163
dotnet_diagnostic.CS4014.severity = suggestion
5264

5365
# RCS1102: Make class static
54-
dotnet_diagnostic.RCS1102.severity = suggestion
66+
dotnet_diagnostic.RCS1102.severity = warning
5567
# RCS1139: Add summary element to documentation comment
5668
dotnet_diagnostic.RCS1139.severity = suggestion
5769
# RCS1194: Implement exception constructors
5870
dotnet_diagnostic.RCS1194.severity = suggestion
5971
# RCS1210: Return completed task instead of returning null
6072
dotnet_diagnostic.RCS1210.severity = suggestion
73+
# RCS1036: Remove unnecessary blank line
74+
dotnet_diagnostic.RCS1036.severity = warning
6175
# RCS1075: Avoid empty catch clause that catches System.Exception
6276
dotnet_diagnostic.RCS1075.severity = suggestion
77+
# RCS1170: Use read-only auto-implemented property
78+
dotnet_diagnostic.RCS1170.severity = warning
6379

6480
# VSTHRD002: Avoid problematic synchronous waits
6581
dotnet_diagnostic.VSTHRD002.severity = suggestion
@@ -79,9 +95,118 @@ dotnet_diagnostic.VSTHRD114.severity = suggestion
7995
dotnet_diagnostic.VSTHRD200.severity = suggestion
8096

8197
# xUnit2013: Do not use equality check to check for collection size
82-
dotnet_diagnostic.xUnit2013.severity = suggestion
83-
# IDE0003: this and Me preferences
84-
dotnet_diagnostic.IDE0003.severity = suggestion
98+
dotnet_diagnostic.xUnit2013.severity = warning
99+
# xUnit1004: Test methods should not be skipped
100+
dotnet_diagnostic.xUnit1004.severity = suggestion
101+
102+
# IDE0001: Simplify name
103+
dotnet_diagnostic.IDE0001.severity = warning
104+
# IDE0002: Simplify member access
105+
dotnet_diagnostic.IDE0001.severity = warning
106+
# IDE0003: Remove this or Me qualification
107+
dotnet_diagnostic.IDE0003.severity = warning
108+
# IDE0004: Remove unnecessary cast
109+
dotnet_diagnostic.IDE0004.severity = warning
110+
# IDE0005: Remove unnecessary import
111+
dotnet_diagnostic.IDE0005.severity = suggestion
112+
# IDE0008: Use explicit type instead of var
113+
dotnet_diagnostic.IDE0008.severity = warning
114+
# IDE0011: Add braces
115+
dotnet_diagnostic.IDE0011.severity = warning
116+
# IDE0016: Use throw expression
117+
dotnet_diagnostic.IDE0016.severity = warning
118+
# IDE0017: Use object initializers
119+
dotnet_diagnostic.IDE0017.severity = warning
120+
# IDE0018: Inline variable declaration
121+
dotnet_diagnostic.IDE0018.severity = warning
122+
# IDE0019: Use pattern matching to avoid 'as' followed by a 'null' check
123+
dotnet_diagnostic.IDE0019.severity = warning
124+
# IDE0020: Use pattern matching to avoid 'is' check followed by a cast (with variable)
125+
dotnet_diagnostic.IDE0020.severity = warning
126+
# IDE0021: Use expression body for constructors
127+
dotnet_diagnostic.IDE0021.severity = warning
128+
# IDE0022: Use expression body for methods
129+
dotnet_diagnostic.IDE0022.severity = warning
130+
# IDE0023: Use expression body for conversion operators
131+
dotnet_diagnostic.IDE0023.severity = warning
132+
# IDE0024: Use expression body for operators
133+
dotnet_diagnostic.IDE0024.severity = warning
134+
# IDE0025: Use expression body for properties
135+
dotnet_diagnostic.IDE0025.severity = warning
136+
# IDE0026: Use expression body for indexers
137+
dotnet_diagnostic.IDE0026.severity = warning
138+
# IDE0027: Use expression body for accessors
139+
dotnet_diagnostic.IDE0027.severity = warning
140+
# IDE0028: Use collection initializers
141+
dotnet_diagnostic.IDE0028.severity = warning
142+
# IDE0029: Use coalesce expression (non-nullable types)
143+
dotnet_diagnostic.IDE0029.severity = warning
144+
# IDE0030: Use coalesce expression (nullable types)
145+
dotnet_diagnostic.IDE0030.severity = warning
146+
# IDE0031: Use null propagation
147+
dotnet_diagnostic.IDE0031.severity = warning
148+
# IDE0032: Use auto property
149+
dotnet_diagnostic.IDE0032.severity = warning
150+
# IDE0033: Use explicitly provided tuple name
151+
dotnet_diagnostic.IDE0033.severity = warning
152+
# IDE0034: Simplify 'default' expression
153+
dotnet_diagnostic.IDE0034.severity = warning
154+
# IDE0035: Remove unreachable code
155+
dotnet_diagnostic.IDE0035.severity = warning
156+
# IDE0036: Order modifiers
157+
dotnet_diagnostic.IDE0036.severity = warning
158+
# IDE0037: Use inferred member name
159+
dotnet_diagnostic.IDE0037.severity = warning
160+
# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
161+
dotnet_diagnostic.IDE0038.severity = suggestion
162+
# IDE0040: Add accessibility modifiers
163+
dotnet_diagnostic.IDE0040.severity = warning
164+
# IDE0041: Use is null check
165+
dotnet_diagnostic.IDE0041.severity = warning
166+
# IDE0042: Deconstruct variable declaration
167+
dotnet_diagnostic.IDE0042.severity = warning
168+
# IDE0044: Add readonly modifier
169+
dotnet_diagnostic.IDE0044.severity = warning
170+
# IDE0045: Use conditional expression for assignment
171+
dotnet_diagnostic.IDE0045.severity = warning
172+
# IDE0046: Use conditional expression for return
173+
dotnet_diagnostic.IDE0046.severity = silent
174+
# IDE0047: Remove unnecessary parentheses
175+
dotnet_diagnostic.IDE0047.severity = warning
176+
# IDE0049: Use language keywords instead of framework type names for type references
177+
dotnet_diagnostic.IDE0049.severity = warning
178+
# IDE0051: Remove unused private member
179+
dotnet_diagnostic.IDE0051.severity = warning
180+
# IDE0052: Remove unread private member
181+
dotnet_diagnostic.IDE0052.severity = suggestion
182+
# IDE0053: Use expression body for lambdas
183+
dotnet_diagnostic.IDE0053.severity = warning
184+
# IDE0054: Use compound assignment
185+
dotnet_diagnostic.IDE0054.severity = warning
186+
# IDE0063: Use simple 'using' statement
187+
dotnet_diagnostic.IDE0063.severity = warning
188+
# IDE0066: Use switch expression
189+
dotnet_diagnostic.IDE0066.severity = warning
190+
# IDE0071: Simplify interpolation
191+
dotnet_diagnostic.IDE0071.severity = warning
192+
# IDE0073: Require file header
193+
dotnet_diagnostic.IDE0073.severity = warning
194+
# IDE0075: Simplify conditional expression
195+
dotnet_diagnostic.IDE0075.severity = warning
196+
# IDE0078: Use pattern matching
197+
dotnet_diagnostic.IDE0078.severity = warning
198+
# IDE0082: Convert typeof to nameof
199+
dotnet_diagnostic.IDE0082.severity = warning
200+
# IDE0083: Use pattern matching (not operator)
201+
dotnet_diagnostic.IDE0083.severity = warning
202+
# IDE0090: Simplify new expression
203+
dotnet_diagnostic.IDE0090.severity = warning
204+
# IDE0100: Remove unnecessary equality operator
205+
dotnet_diagnostic.IDE0100.severity = warning
206+
# IDE0110: Remove unnecessary discard
207+
dotnet_diagnostic.IDE0110.severity = warning
208+
# IDE1005: Use conditional delegate call
209+
dotnet_diagnostic.IDE1005.severity = warning
85210

86211
[*.{json}]
87212
indent_size = 2

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+26-30
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace Microsoft.PowerShell.EditorServices.Commands
3636
public sealed class StartEditorServicesCommand : PSCmdlet
3737
{
3838
// TODO: Remove this when we drop support for PS6.
39-
private readonly static bool s_isWindows =
39+
private static readonly bool s_isWindows =
4040
#if CoreCLR
4141
RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
4242
#else
@@ -237,15 +237,13 @@ protected override void EndProcessing()
237237
// Create the configuration from parameters
238238
EditorServicesConfig editorServicesConfig = CreateConfigObject();
239239

240-
var sessionFileWriter = new SessionFileWriter(_logger, SessionDetailsPath);
240+
SessionFileWriter sessionFileWriter = new(_logger, SessionDetailsPath);
241241
_logger.Log(PsesLogLevel.Diagnostic, "Session file writer created");
242242

243-
using (var psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers))
244-
{
245-
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
246-
// Start editor services and wait here until it shuts down
247-
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
248-
}
243+
using EditorServicesLoader psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers);
244+
_logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
245+
// Start editor services and wait here until it shuts down
246+
psesLoader.LoadAndRunEditorServicesAsync().GetAwaiter().GetResult();
249247
}
250248
catch (Exception e)
251249
{
@@ -277,7 +275,7 @@ private void StartLogging()
277275
// if it's being used as a protocol transport
278276
if (!Stdio)
279277
{
280-
var hostLogger = new PSHostLogger(Host.UI);
278+
PSHostLogger hostLogger = new(Host.UI);
281279
_loggerUnsubscribers.Add(_logger.Subscribe(hostLogger));
282280
}
283281

@@ -292,7 +290,7 @@ private void StartLogging()
292290
logPath = Path.Combine(logDirPath, $"StartEditorServices-temp{randomInt.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}.log");
293291
}
294292

295-
var fileLogger = StreamLogger.CreateWithNewFile(logPath);
293+
StreamLogger fileLogger = StreamLogger.CreateWithNewFile(logPath);
296294
_disposableResources.Add(fileLogger);
297295
IDisposable fileLoggerUnsubscriber = _logger.Subscribe(fileLogger);
298296
fileLogger.AddUnsubscriber(fileLoggerUnsubscriber);
@@ -316,23 +314,21 @@ private string GetLogDirPath()
316314
private void RemovePSReadLineForStartup()
317315
{
318316
_logger.Log(PsesLogLevel.Verbose, "Removing PSReadLine");
319-
using (var pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace))
320-
{
321-
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
322-
.AddParameter("Name", "PSReadLine")
323-
.Invoke()
324-
.Any();
317+
using SMA.PowerShell pwsh = SMA.PowerShell.Create(RunspaceMode.CurrentRunspace);
318+
bool hasPSReadLine = pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Get-Module", typeof(GetModuleCommand)))
319+
.AddParameter("Name", "PSReadLine")
320+
.Invoke()
321+
.Any();
325322

326-
if (hasPSReadLine)
327-
{
328-
pwsh.Commands.Clear();
323+
if (hasPSReadLine)
324+
{
325+
pwsh.Commands.Clear();
329326

330-
pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Remove-Module", typeof(RemoveModuleCommand)))
331-
.AddParameter("Name", "PSReadLine")
332-
.AddParameter("ErrorAction", "SilentlyContinue");
327+
pwsh.AddCommand(new CmdletInfo("Microsoft.PowerShell.Core\\Remove-Module", typeof(RemoveModuleCommand)))
328+
.AddParameter("Name", "PSReadLine")
329+
.AddParameter("ErrorAction", "SilentlyContinue");
333330

334-
_logger.Log(PsesLogLevel.Verbose, "Removed PSReadLine");
335-
}
331+
_logger.Log(PsesLogLevel.Verbose, "Removed PSReadLine");
336332
}
337333
}
338334

@@ -352,14 +348,14 @@ private EditorServicesConfig CreateConfigObject()
352348
bundledModulesPath));
353349
}
354350

355-
var profile = (PSObject)GetVariableValue("profile");
351+
PSObject profile = (PSObject)GetVariableValue("profile");
356352

357-
var hostInfo = new HostInfo(HostName, HostProfileId, HostVersion);
353+
HostInfo hostInfo = new(HostName, HostProfileId, HostVersion);
358354

359-
var initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
355+
InitialSessionState initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
360356
initialSessionState.LanguageMode = Runspace.DefaultRunspace.SessionStateProxy.LanguageMode;
361357

362-
var editorServicesConfig = new EditorServicesConfig(
358+
EditorServicesConfig editorServicesConfig = new(
363359
hostInfo,
364360
Host,
365361
SessionDetailsPath,
@@ -425,9 +421,9 @@ private ConsoleReplKind GetReplKind()
425421
}
426422

427423
// TODO: Remove this when we drop support for PS6.
428-
var psVersionTable = (Hashtable) this.SessionState.PSVariable.GetValue("PSVersionTable");
424+
Hashtable psVersionTable = (Hashtable)SessionState.PSVariable.GetValue("PSVersionTable");
429425
dynamic version = psVersionTable["PSVersion"];
430-
var majorVersion = (int) version.Major;
426+
int majorVersion = (int)version.Major;
431427

432428
if (UseLegacyReadLine || (!s_isWindows && majorVersion == 6))
433429
{

0 commit comments

Comments
 (0)