Skip to content

Commit b703dee

Browse files
Merge pull request #1757 from PowerShell/andschwa/format-check
Enable code analysis and formatting as errors on build
2 parents aa1c253 + 468f3ba commit b703dee

File tree

23 files changed

+140
-125
lines changed

23 files changed

+140
-125
lines changed

.editorconfig

+92-76
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ csharp_style_expression_bodied_indexers = true
2222
csharp_style_expression_bodied_accessors = true
2323
csharp_style_expression_bodied_lambdas = when_on_single_line
2424

25+
# TODO: Fix silenced and suggested rules!
26+
2527
# CS0168: The variable 'var' is declared but never used
2628
dotnet_diagnostic.CS0168.severity = error
2729
# CS0169: The private field 'class member' is never used
@@ -30,10 +32,37 @@ dotnet_diagnostic.CS0169.severity = error
3032
dotnet_diagnostic.CS0219.severity = error
3133
# CS0414: The private field 'field' is assigned but its value is never used
3234
dotnet_diagnostic.CS0414.severity = error
35+
# CS0618: A class member was marked with the Obsolete attribute
36+
dotnet_diagnostic.CS0618.severity = suggestion
37+
# CS0649: Uninitialized private or internal field declaration that is never assigned a value
38+
dotnet_diagnostic.CS0649.severity = error
39+
# CS1998: This async method lacks 'await' operators and will run synchronously
40+
dotnet_diagnostic.CS1998.severity = suggestion
41+
# CS4014: Consider applying the await operator to the result of the call
42+
dotnet_diagnostic.CS4014.severity = suggestion
43+
3344
# CA1067: Should override Equals because it implements IEquatable<T>
3445
dotnet_diagnostic.CA1067.severity = silent
3546
# CA1068: CancellationToken parameters must come last
3647
dotnet_diagnostic.CA1068.severity = error
48+
# CA1501: Avoid excessive inheritance
49+
dotnet_diagnostic.CA1501.severity = error
50+
# CA1502: Avoid excessive complexity
51+
dotnet_diagnostic.CA1502.severity = warning
52+
# CA1505: Avoid unmaintainable code
53+
dotnet_diagnostic.CA1505.severity = error
54+
# CA1506: Avoid excessive class coupling
55+
dotnet_diagnostic.CA1506.severity = warning
56+
# CA1507: Use nameof in place of string
57+
dotnet_diagnostic.CA1507.severity = error
58+
# CA1508: Avoid dead conditional code
59+
dotnet_diagnostic.CA1508.severity = error
60+
# CA1802: Use Literals Where Appropriate
61+
dotnet_diagnostic.CA1802.severity = error
62+
# CA1805: Do not initialize unnecessarily.
63+
dotnet_diagnostic.CA1805.severity = error
64+
# CA1820: Test for empty strings using string length
65+
dotnet_diagnostic.CA1820.severity = error
3766
# CA1822: Mark members as static
3867
dotnet_diagnostic.CA1822.severity = error
3968
# CA1823: Avoid unused private fields
@@ -42,40 +71,27 @@ dotnet_diagnostic.CA1823.severity = error
4271
dotnet_diagnostic.CA2007.severity = error
4372
# CA2016: Forward the CancellationToken parameter to methods that take one
4473
dotnet_diagnostic.CA2016.severity = error
74+
# CA2213: Disposable fields should be disposed
75+
dotnet_diagnostic.CA2213.severity = error
4576
# CA2254: The logging message template should not vary between calls to 'LoggerExtensions.*'
4677
dotnet_diagnostic.CA2254.severity = silent
4778

48-
# TODO: Enable all maintainability issues (dead code etc.) and enforce
49-
# See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/maintainability-warnings
50-
dotnet_analyzer_diagnostic.category-Maintainability.severity = error
51-
52-
# TODO: Fix all of these issues and explicitly ignore the intentional ones!
53-
54-
# CA2016: Forward the CancellationToken parameter to methods that take one
55-
dotnet_diagnostic.CA2016.severity = error
56-
# CS0618: A class member was marked with the Obsolete attribute
57-
dotnet_diagnostic.CS0618.severity = suggestion
58-
# CS0649: Uninitialized private or internal field declaration that is never assigned a value
59-
dotnet_diagnostic.CS0649.severity = warning
60-
# CS1998: This async method lacks 'await' operators and will run synchronously
61-
dotnet_diagnostic.CS1998.severity = suggestion
62-
# CS4014: Consider applying the await operator to the result of the call
63-
dotnet_diagnostic.CS4014.severity = suggestion
64-
79+
# RCS1049: Simplify boolean comparison
80+
dotnet_diagnostic.RCS1049.severity = error
6581
# RCS1102: Make class static
66-
dotnet_diagnostic.RCS1102.severity = warning
82+
dotnet_diagnostic.RCS1102.severity = error
6783
# RCS1139: Add summary element to documentation comment
6884
dotnet_diagnostic.RCS1139.severity = silent
6985
# RCS1194: Implement exception constructors
7086
dotnet_diagnostic.RCS1194.severity = suggestion
7187
# RCS1210: Return completed task instead of returning null
72-
dotnet_diagnostic.RCS1210.severity = suggestion
88+
dotnet_diagnostic.RCS1210.severity = error
7389
# RCS1036: Remove unnecessary blank line
74-
dotnet_diagnostic.RCS1036.severity = warning
90+
dotnet_diagnostic.RCS1036.severity = error
7591
# RCS1075: Avoid empty catch clause that catches System.Exception
7692
dotnet_diagnostic.RCS1075.severity = suggestion
7793
# RCS1170: Use read-only auto-implemented property
78-
dotnet_diagnostic.RCS1170.severity = warning
94+
dotnet_diagnostic.RCS1170.severity = error
7995

8096
# VSTHRD002: Avoid problematic synchronous waits
8197
dotnet_diagnostic.VSTHRD002.severity = suggestion
@@ -90,123 +106,123 @@ dotnet_diagnostic.VSTHRD103.severity = suggestion
90106
# VSTHRD110: Observe result of async calls
91107
dotnet_diagnostic.VSTHRD110.severity = suggestion
92108
# VSTHRD114: Avoid returning a null Task
93-
dotnet_diagnostic.VSTHRD114.severity = suggestion
109+
dotnet_diagnostic.VSTHRD114.severity = error
94110
# VSTHRD200: Use "Async" suffix for awaitable methods
95111
dotnet_diagnostic.VSTHRD200.severity = silent
96112

97113
# xUnit2013: Do not use equality check to check for collection size
98-
dotnet_diagnostic.xUnit2013.severity = warning
114+
dotnet_diagnostic.xUnit2013.severity = error
99115
# xUnit1004: Test methods should not be skipped
100116
dotnet_diagnostic.xUnit1004.severity = suggestion
101117

102118
# IDE0001: Simplify name
103-
dotnet_diagnostic.IDE0001.severity = warning
119+
dotnet_diagnostic.IDE0001.severity = error
104120
# IDE0002: Simplify member access
105-
dotnet_diagnostic.IDE0001.severity = warning
121+
dotnet_diagnostic.IDE0001.severity = error
106122
# IDE0003: Remove this or Me qualification
107-
dotnet_diagnostic.IDE0003.severity = warning
123+
dotnet_diagnostic.IDE0003.severity = error
108124
# IDE0004: Remove unnecessary cast
109-
dotnet_diagnostic.IDE0004.severity = warning
125+
dotnet_diagnostic.IDE0004.severity = error
110126
# IDE0005: Remove unnecessary import
111-
dotnet_diagnostic.IDE0005.severity = suggestion
127+
dotnet_diagnostic.IDE0005.severity = error
112128
# IDE0008: Use explicit type instead of var
113-
dotnet_diagnostic.IDE0008.severity = warning
129+
dotnet_diagnostic.IDE0008.severity = error
114130
# IDE0011: Add braces
115-
dotnet_diagnostic.IDE0011.severity = warning
131+
dotnet_diagnostic.IDE0011.severity = error
116132
# IDE0016: Use throw expression
117-
dotnet_diagnostic.IDE0016.severity = warning
133+
dotnet_diagnostic.IDE0016.severity = error
118134
# IDE0017: Use object initializers
119-
dotnet_diagnostic.IDE0017.severity = warning
135+
dotnet_diagnostic.IDE0017.severity = error
120136
# IDE0018: Inline variable declaration
121-
dotnet_diagnostic.IDE0018.severity = warning
137+
dotnet_diagnostic.IDE0018.severity = error
122138
# IDE0019: Use pattern matching to avoid 'as' followed by a 'null' check
123-
dotnet_diagnostic.IDE0019.severity = warning
139+
dotnet_diagnostic.IDE0019.severity = error
124140
# IDE0020: Use pattern matching to avoid 'is' check followed by a cast (with variable)
125-
dotnet_diagnostic.IDE0020.severity = warning
141+
dotnet_diagnostic.IDE0020.severity = error
126142
# IDE0021: Use expression body for constructors
127-
dotnet_diagnostic.IDE0021.severity = warning
143+
dotnet_diagnostic.IDE0021.severity = error
128144
# IDE0022: Use expression body for methods
129-
dotnet_diagnostic.IDE0022.severity = warning
145+
dotnet_diagnostic.IDE0022.severity = error
130146
# IDE0023: Use expression body for conversion operators
131-
dotnet_diagnostic.IDE0023.severity = warning
147+
dotnet_diagnostic.IDE0023.severity = error
132148
# IDE0024: Use expression body for operators
133-
dotnet_diagnostic.IDE0024.severity = warning
149+
dotnet_diagnostic.IDE0024.severity = error
134150
# IDE0025: Use expression body for properties
135-
dotnet_diagnostic.IDE0025.severity = warning
151+
dotnet_diagnostic.IDE0025.severity = error
136152
# IDE0026: Use expression body for indexers
137-
dotnet_diagnostic.IDE0026.severity = warning
153+
dotnet_diagnostic.IDE0026.severity = error
138154
# IDE0027: Use expression body for accessors
139-
dotnet_diagnostic.IDE0027.severity = warning
155+
dotnet_diagnostic.IDE0027.severity = error
140156
# IDE0028: Use collection initializers
141-
dotnet_diagnostic.IDE0028.severity = warning
157+
dotnet_diagnostic.IDE0028.severity = error
142158
# IDE0029: Use coalesce expression (non-nullable types)
143-
dotnet_diagnostic.IDE0029.severity = warning
159+
dotnet_diagnostic.IDE0029.severity = error
144160
# IDE0030: Use coalesce expression (nullable types)
145-
dotnet_diagnostic.IDE0030.severity = warning
161+
dotnet_diagnostic.IDE0030.severity = error
146162
# IDE0031: Use null propagation
147-
dotnet_diagnostic.IDE0031.severity = warning
163+
dotnet_diagnostic.IDE0031.severity = error
148164
# IDE0032: Use auto property
149-
dotnet_diagnostic.IDE0032.severity = warning
165+
dotnet_diagnostic.IDE0032.severity = error
150166
# IDE0033: Use explicitly provided tuple name
151-
dotnet_diagnostic.IDE0033.severity = warning
167+
dotnet_diagnostic.IDE0033.severity = error
152168
# IDE0034: Simplify 'default' expression
153-
dotnet_diagnostic.IDE0034.severity = warning
169+
dotnet_diagnostic.IDE0034.severity = error
154170
# IDE0035: Remove unreachable code
155-
dotnet_diagnostic.IDE0035.severity = warning
171+
dotnet_diagnostic.IDE0035.severity = error
156172
# IDE0036: Order modifiers
157-
dotnet_diagnostic.IDE0036.severity = warning
173+
dotnet_diagnostic.IDE0036.severity = error
158174
# IDE0037: Use inferred member name
159-
dotnet_diagnostic.IDE0037.severity = warning
175+
dotnet_diagnostic.IDE0037.severity = error
160176
# IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
161-
dotnet_diagnostic.IDE0038.severity = suggestion
177+
dotnet_diagnostic.IDE0038.severity = error
162178
# IDE0040: Add accessibility modifiers
163-
dotnet_diagnostic.IDE0040.severity = warning
179+
dotnet_diagnostic.IDE0040.severity = error
164180
# IDE0041: Use is null check
165-
dotnet_diagnostic.IDE0041.severity = warning
181+
dotnet_diagnostic.IDE0041.severity = error
166182
# IDE0042: Deconstruct variable declaration
167-
dotnet_diagnostic.IDE0042.severity = warning
183+
dotnet_diagnostic.IDE0042.severity = error
168184
# IDE0044: Add readonly modifier
169-
dotnet_diagnostic.IDE0044.severity = warning
185+
dotnet_diagnostic.IDE0044.severity = error
170186
# IDE0045: Use conditional expression for assignment
171-
dotnet_diagnostic.IDE0045.severity = warning
187+
dotnet_diagnostic.IDE0045.severity = error
172188
# IDE0046: Use conditional expression for return
173189
dotnet_diagnostic.IDE0046.severity = silent
174190
# IDE0047: Remove unnecessary parentheses
175-
dotnet_diagnostic.IDE0047.severity = warning
191+
dotnet_diagnostic.IDE0047.severity = error
176192
# IDE0049: Use language keywords instead of framework type names for type references
177-
dotnet_diagnostic.IDE0049.severity = warning
193+
dotnet_diagnostic.IDE0049.severity = error
178194
# IDE0051: Remove unused private member
179-
dotnet_diagnostic.IDE0051.severity = warning
195+
dotnet_diagnostic.IDE0051.severity = error
180196
# IDE0052: Remove unread private member
181-
dotnet_diagnostic.IDE0052.severity = suggestion
197+
dotnet_diagnostic.IDE0052.severity = error
182198
# IDE0053: Use expression body for lambdas
183-
dotnet_diagnostic.IDE0053.severity = warning
199+
dotnet_diagnostic.IDE0053.severity = error
184200
# IDE0054: Use compound assignment
185-
dotnet_diagnostic.IDE0054.severity = warning
201+
dotnet_diagnostic.IDE0054.severity = error
186202
# IDE0063: Use simple 'using' statement
187-
dotnet_diagnostic.IDE0063.severity = warning
203+
dotnet_diagnostic.IDE0063.severity = error
188204
# IDE0066: Use switch expression
189-
dotnet_diagnostic.IDE0066.severity = warning
205+
dotnet_diagnostic.IDE0066.severity = error
190206
# IDE0071: Simplify interpolation
191-
dotnet_diagnostic.IDE0071.severity = warning
207+
dotnet_diagnostic.IDE0071.severity = error
192208
# IDE0073: Require file header
193-
dotnet_diagnostic.IDE0073.severity = warning
209+
dotnet_diagnostic.IDE0073.severity = error
194210
# IDE0075: Simplify conditional expression
195-
dotnet_diagnostic.IDE0075.severity = warning
211+
dotnet_diagnostic.IDE0075.severity = error
196212
# IDE0078: Use pattern matching
197-
dotnet_diagnostic.IDE0078.severity = warning
213+
dotnet_diagnostic.IDE0078.severity = error
198214
# IDE0082: Convert typeof to nameof
199-
dotnet_diagnostic.IDE0082.severity = warning
215+
dotnet_diagnostic.IDE0082.severity = error
200216
# IDE0083: Use pattern matching (not operator)
201-
dotnet_diagnostic.IDE0083.severity = warning
217+
dotnet_diagnostic.IDE0083.severity = error
202218
# IDE0090: Simplify new expression
203-
dotnet_diagnostic.IDE0090.severity = warning
219+
dotnet_diagnostic.IDE0090.severity = error
204220
# IDE0100: Remove unnecessary equality operator
205-
dotnet_diagnostic.IDE0100.severity = warning
221+
dotnet_diagnostic.IDE0100.severity = error
206222
# IDE0110: Remove unnecessary discard
207-
dotnet_diagnostic.IDE0110.severity = warning
223+
dotnet_diagnostic.IDE0110.severity = error
208224
# IDE1005: Use conditional delegate call
209-
dotnet_diagnostic.IDE1005.severity = warning
225+
dotnet_diagnostic.IDE1005.severity = error
210226

211227
[*.{json}]
212228
indent_size = 2

PowerShellEditorServices.Common.props

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<!-- See: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview -->
1515
<EnableNETAnalyzers>true</EnableNETAnalyzers>
1616
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
17+
<!-- TODO: Enable <AnalysisMode>All</AnalysisMode> -->
1718
<!-- See: https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/6.0/implicit-namespaces -->
1819
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
1920
</PropertyGroup>

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public StartEditorServicesCommand()
191191
[Parameter]
192192
public string StartupBanner { get; set; }
193193

194+
#pragma warning disable IDE0022
194195
protected override void BeginProcessing()
195196
{
196197
#if DEBUG
@@ -203,10 +204,10 @@ protected override void BeginProcessing()
203204
}
204205
}
205206
#endif
206-
207207
// Set up logging now for use throughout startup
208208
StartLogging();
209209
}
210+
#pragma warning restore IDE0022
210211

211212
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Uses ThrowTerminatingError() instead")]
212213
protected override void EndProcessing()

src/PowerShellEditorServices.Hosting/Configuration/EditorServicesConfig.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public EditorServicesConfig(
7676
/// <summary>
7777
/// Names of or paths to any additional modules to load on startup.
7878
/// </summary>
79-
public IReadOnlyList<string> AdditionalModules { get; set; } = null;
79+
public IReadOnlyList<string> AdditionalModules { get; set; }
8080

8181
/// <summary>
8282
/// Flags of features to enable on startup.
8383
/// </summary>
84-
public IReadOnlyList<string> FeatureFlags { get; set; } = null;
84+
public IReadOnlyList<string> FeatureFlags { get; set; }
8585

8686
/// <summary>
8787
/// The console REPL experience to use in the integrated console
@@ -97,12 +97,12 @@ public EditorServicesConfig(
9797
/// <summary>
9898
/// Configuration for the language server protocol transport to use.
9999
/// </summary>
100-
public ITransportConfig LanguageServiceTransport { get; set; } = null;
100+
public ITransportConfig LanguageServiceTransport { get; set; }
101101

102102
/// <summary>
103103
/// Configuration for the debug adapter protocol transport to use.
104104
/// </summary>
105-
public ITransportConfig DebugServiceTransport { get; set; } = null;
105+
public ITransportConfig DebugServiceTransport { get; set; }
106106

107107
/// <summary>
108108
/// PowerShell profile locations for Editor Services to use for its profiles.

src/PowerShellEditorServices.Hosting/Configuration/TransportConfig.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public sealed class StdioTransportConfig : ITransportConfig
4949

5050
public string SessionFileTransportName => "Stdio";
5151

52-
public IReadOnlyDictionary<string, object> SessionFileEntries { get; } = null;
52+
public IReadOnlyDictionary<string, object> SessionFileEntries { get; }
5353

5454
public Task<(Stream inStream, Stream outStream)> ConnectStreamsAsync()
5555
{

src/PowerShellEditorServices.Hosting/Internal/NamedPipeUtils.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.IO.Pipes;
7-
using System.Runtime.InteropServices;
87

98
#if !CoreCLR
109
using System.Security.Principal;
1110
using System.Security.AccessControl;
11+
#else
12+
using System.Runtime.InteropServices;
1213
#endif
1314

1415
namespace Microsoft.PowerShell.EditorServices.Hosting

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public static EditorServicesServerFactory Create(string logPath, int minimumLogL
5858
SelfLog.Enable(msg => Debug.WriteLine(msg));
5959
#endif
6060

61-
ILoggerFactory loggerFactory = new LoggerFactory().AddSerilog();
61+
LoggerFactory loggerFactory = new();
62+
loggerFactory.AddSerilog();
6263

6364
// Hook up logging from the host so that its recorded in the log file
6465
hostLogger.Subscribe(new HostLoggerAdapter(loggerFactory));

src/PowerShellEditorServices/Server/PsesDebugServer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void Dispose()
124124
_debugAdapterServer.Dispose();
125125
_inputStream.Dispose();
126126
_outputStream.Dispose();
127+
_loggerFactory.Dispose();
127128
_serverStopped.SetResult(true);
128129
// TODO: If the debugger has stopped, should we clear the breakpoints?
129130
}

0 commit comments

Comments
 (0)