Skip to content

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

Merged
merged 5 commits into from
Mar 16, 2022

Conversation

andyleejordan
Copy link
Member

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!

@andyleejordan andyleejordan added the Ignore Exclude from the changelog. label Mar 14, 2022
@andyleejordan andyleejordan force-pushed the andschwa/dotnet-format branch from 669986b to 1b4cd89 Compare March 14, 2022 22:23
@andyleejordan andyleejordan marked this pull request as ready for review March 14, 2022 22:26
@andyleejordan andyleejordan force-pushed the andschwa/dotnet-format branch from 1b4cd89 to 589e625 Compare March 14, 2022 22:49
With `--ignored-diagnostics CA1067 CS0659 VSTHRD002 VSTHRD100 VSTHRD103 VSTHRD114 VSTHRD200 xUnit1004`
@andyleejordan andyleejordan force-pushed the andschwa/dotnet-format branch from 589e625 to 15cdde3 Compare March 14, 2022 22:55
@JustinGrote
Copy link
Collaborator

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)'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF is this?

Copy link
Member Author

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)'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another.

Copy link
Member Author

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
Copy link
Member Author

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 */);
Copy link
Member Author

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)
Copy link
Member Author

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...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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)
Copy link
Member Author

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.

Comment on lines +449 to +456
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,
};
;
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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 =
Copy link
Member Author

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.
Copy link
Member Author

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.

Comment on lines +60 to +63
while (!WaitForKeyAvailable(cancellationToken))
{
;
}
Copy link
Member Author

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.

@andyleejordan andyleejordan enabled auto-merge March 15, 2022 21:05
Copy link
Member Author

@andyleejordan andyleejordan left a 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.

@andyleejordan andyleejordan merged commit 2c879ca into master Mar 16, 2022
Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a 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.

@andyleejordan andyleejordan deleted the andschwa/dotnet-format branch March 16, 2022 04:03
@andyleejordan andyleejordan mentioned this pull request Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ignore Exclude from the changelog.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants