-
Notifications
You must be signed in to change notification settings - Fork 236
Add linting to PSES, with fixes for obvious cases #1155
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
src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Outdated
Show resolved
Hide resolved
…hellContextService.cs
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.
Looking good!
src/PowerShellEditorServices/Services/PowerShellContext/ExtensionService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs
Show resolved
Hide resolved
src/PowerShellEditorServices/Services/PowerShellContext/Utilities/CommandHelpers.cs
Outdated
Show resolved
Hide resolved
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! One optional
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Cmdlet parameters can be arrays", Scope = "module")] | ||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "PSES is not localized", Scope = "module")] | ||
|
||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "PSCmdlet.ThrowTerminatingError() is used instead", Scope = "member", Target = "~M:Microsoft.PowerShell.EditorServices.Commands.StartEditorServicesCommand.EndProcessing")] |
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.
Could these be placed inline? The ones that target a specific member that is.
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.
They can be. I've never liked those FxCop attributes that occur all over the code (especially when codebases stop using FxCop like in PowerShell), but will leave it up to others
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 can certainly see the pros of having the attribute inline, so you get the justification like a comment
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 personally agree with @SeeminglyScience about putting them inline so they're "self documenting"
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.
Yeah it's far from perfect. I hate seeing them too, but it makes it confusing why one thing warns and another doesn't. Most folks aren't going to know to look in that file.
I usually go with #pragma warning disable CA1031
and #pragma warning restore CA1031
since it's slightly less aggressive, but then you lose a lot of information. Probably not suitable.
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.
Went for the attribute where possible, just since it's got a field for Justification
. Some things required a pragma though
@@ -1569,7 +1581,7 @@ public async Task SetWorkingDirectoryAsync(string path) | |||
/// <param name="isPathAlreadyEscaped">Specify false to have the path escaped, otherwise specify true if the path has already been escaped.</param> | |||
public async Task SetWorkingDirectoryAsync(string path, bool isPathAlreadyEscaped) | |||
{ | |||
this.InitialWorkingDirectory = path; | |||
this.InitialWorkingDirectory = path ?? throw new ArgumentNullException(nameof(path)); |
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.
Use the Validate.IsNotNull
?
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.
Missed this initially, but how do we feel about these methods?
They kind of mess with the call stack a little bit. It's not a huge deal, but it does make debugging slightly more tedious since you need to pick the right frame. And it makes Exception.TargetSite
kinda useless.
Obviously I'm not expecting anything in this merged PR to change, just bringing it up in case any of y'all are also leaning that way. WTB macros 🙁
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 Util method or the SetWorkingDirectory?
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 Util methods for argument validation
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.
Yeah they do seem very unnecessary and even have drawbacks as you've pointed out.
I'd be fine with them being removed but also not a huge problem atm
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 besides the above comments
Issues
======
+ Solved 88
- Added 2
Clones added
============
- src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs 1
- src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentHighlightHandler.cs 3
- src/PowerShellEditorServices/Services/TextDocument/Handlers/DefinitionHandler.cs 1
- src/PowerShellEditorServices/Services/TextDocument/Handlers/DocumentSymbolHandler.cs 1
See the complete overview on Codacy |
@@ -1143,12 +1164,12 @@ public async Task LoadHostProfilesAsync() | |||
{ | |||
PSCommand command = new PSCommand(); | |||
command.AddCommand(profilePath, false); | |||
await this.ExecuteCommandAsync<object>(command, true, true); | |||
await this.ExecuteCommandAsync<object>(command, sendOutputToHost: true, sendErrorToHost: true).ConfigureAwait(false); |
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.
int initialPromptCol = await ConsoleProxy.GetCursorLeftAsync(cancellationToken); | ||
// TODO: Are these values used? | ||
int initialPromptRow = await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false); | ||
int initialPromptCol = await ConsoleProxy.GetCursorLeftAsync(cancellationToken).ConfigureAwait(false); |
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.
Issue found: Remove the unused local variable 'initialPromptCol'.
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
.ConfigureAwait(false)
to allawait
calls (and turns some intoTask<T>
pass throughs)readonly
where VS suggests