-
Notifications
You must be signed in to change notification settings - Fork 235
Use dotnet format
and roslynator fix
to automatically apply fixes
#1743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
669986b
to
1b4cd89
Compare
1b4cd89
to
589e625
Compare
With `--ignored-diagnostics CA1067 CS0659 VSTHRD002 VSTHRD100 VSTHRD103 VSTHRD114 VSTHRD200 xUnit1004`
589e625
to
15cdde3
Compare
Seems like a good time to do this ahead of the stable release for sure, hopefully stuff doesn't get too broken. |
@@ -260,7 +236,211 @@ internal class StreamLogger : IObserver<(PsesLogLevel logLevel, string message)> | |||
{ | |||
public static StreamLogger CreateWithNewFile(string path) | |||
{ | |||
var fileStream = new FileStream( | |||
|
|||
/* Unmerged change from project 'PowerShellEditorServices.Hosting(net461)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
return new DuplexNamedPipeTransportConfig(logger, NamedPipeUtils.GenerateValidNamedPipeName()); | ||
} | ||
|
||
/* Unmerged change from project 'PowerShellEditorServices.Hosting(net461)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
@@ -137,6 +137,7 @@ public static bool IsPipeNameValid(string pipeName) | |||
/// </summary> | |||
/// <param name="pipeName">The simple name of the named pipe.</param> | |||
/// <returns>The full path of the named pipe.</returns> | |||
#pragma warning disable IDE0022 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The #if CoreCLR
confused the formatter, so I disabled the rule.
@@ -408,10 +402,12 @@ private static object GetPSVersion() | |||
// which is expensive. | |||
// Rather than do that, we instead go straight to the source, | |||
// which is a static property, internal in WinPS and public in PS 6+ | |||
#pragma warning disable CA1825 | |||
return typeof(PSObject).Assembly | |||
.GetType("System.Management.Automation.PSVersionInfo") | |||
.GetMethod("get_PSVersion", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) | |||
.Invoke(null, new object[0] /* Cannot use Array.Empty, since it must work in net452 */); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is CA1825, hence the disabling.
@@ -59,7 +59,8 @@ protected override void BeginProcessing() | |||
.GetAwaiter() | |||
.GetResult(); | |||
|
|||
if (_showInColumn != null) { | |||
if (_showInColumn != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there's a rule to convert != null
to is not null
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd think https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0078 would do it.
@@ -136,7 +136,7 @@ public async Task StartAsync() | |||
{ | |||
// If RootUri isn't set, try to use the first WorkspaceFolder. | |||
// TODO: Support multi-workspace. | |||
foreach (var workspaceFolder in request.WorkspaceFolders) | |||
foreach (OmniSharp.Extensions.LanguageServer.Protocol.Models.WorkspaceFolder workspaceFolder in request.WorkspaceFolders) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly annoying that it defaulted to the full name like this, but we'll fix it some other time.
return markerLevel switch | ||
{ | ||
case ScriptFileMarkerLevel.Error: return DiagnosticSeverity.Error; | ||
case ScriptFileMarkerLevel.Warning: return DiagnosticSeverity.Warning; | ||
case ScriptFileMarkerLevel.Information: return DiagnosticSeverity.Information; | ||
default: return DiagnosticSeverity.Error; | ||
ScriptFileMarkerLevel.Error => DiagnosticSeverity.Error, | ||
ScriptFileMarkerLevel.Warning => DiagnosticSeverity.Warning, | ||
ScriptFileMarkerLevel.Information => DiagnosticSeverity.Information, | ||
_ => DiagnosticSeverity.Error, | ||
}; | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love that it auto converted these, damn!
foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile)) | ||
{ | ||
if (!(symbol is PesterSymbolReference pesterSymbol)) | ||
if (symbol is not PesterSymbolReference pesterSymbol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm so it does correct these...
@@ -224,7 +218,7 @@ public static ScriptBlock GetBreakpointActionScriptBlock(string condition, strin | |||
// Check for "advanced" condition syntax i.e. if the user has specified | |||
// a "break" or "continue" statement anywhere in their scriptblock, | |||
// pass their scriptblock through to the Action parameter as-is. | |||
if (parsed.Ast.Find(ast => ast is BreakStatementAst || ast is ContinueStatementAst, true) is not null) | |||
if (parsed.Ast.Find(ast => ast is BreakStatementAst or ContinueStatementAst, true) is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it does these...
@@ -133,26 +132,23 @@ private static bool GetIsExpandable(object valueObject) | |||
} | |||
|
|||
// If a PSObject, unwrap it | |||
var psobject = valueObject as PSObject; | |||
if (psobject != null) | |||
if (valueObject is PSObject psobject) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn it's funny that it can fix these but not == null
to is null
etc.
@@ -133,26 +132,23 @@ private static bool GetIsExpandable(object valueObject) | |||
} | |||
|
|||
// If a PSObject, unwrap it | |||
var psobject = valueObject as PSObject; | |||
if (psobject != null) | |||
if (valueObject is PSObject psobject) | |||
{ | |||
valueObject = psobject.BaseObject; | |||
} | |||
|
|||
Type valueType = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish it would auto-squash the lines.
@@ -1,5 +1,5 @@ | |||
// Copyright (c) Microsoft. All rights reserved. | |||
// Licensed under the MIT license. | |||
// Copyright (c) Microsoft Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, I love that these can be auto-fixed now! Because we did it semi-manually last time in #1580 and clearly missed some.
while (!WaitForKeyAvailable(cancellationToken)) | ||
{ | ||
; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm funny, but technically correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SeeminglyScience I'm good with this if you are! I enabled auto-merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Yeah the is null
thing makes sense unfortunately. Even if rare (and usually unintentional) it would need too much context to determine if there was a behavioral change.
It's not quite perfect, but it's automated! If everything passes then I suggest we merge this PR and keep running these tools manually until we can integrate them into CI (which is pending upstream package fixes for
dotnet format
). Annoyingly, I haven't figured out how to get either tool to auto-apply some fixes, such as RCS1036 and RCS1170, and I'm not sure there are automatic fixes for rules that remove unused code like IDE0005 and IDE0060. But this gets us a lot of the way there!