-
Notifications
You must be signed in to change notification settings - Fork 384
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
Support SuggestedCorrections property on DiagnosticRecord for script based rules #1000
Support SuggestedCorrections property on DiagnosticRecord for script based rules #1000
Conversation
… for easier construction in PowerShell
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 looks great and really needed. My comment is not blocking as we can go back and change it later.
@@ -28,9 +28,12 @@ function Measure-RequiresRunAsAdministrator | |||
[System.Management.Automation.Language.ScriptBlockAst] | |||
$testAst | |||
) | |||
$dr = New-Object ` | |||
$l=(new-object System.Collections.ObjectModel.Collection["Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent"]) |
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.
in PowerShellCore tests, we're moving away from using new-object in favor of this:
$l = [System.Collections.ObjectModel.Collection[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]]::new()
$c = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]::new(1,2,3,4,'text','filePath','description')
$null = $l.Add($c)
$dr = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]::new(
"This is help",
$ast.Extent,$PSCmdlet.MyInvocation.InvocationName,
"Warning",
$null,
$null,
$l)
return $dr
which I think is much tidier. I know it's inconsistent, but that's ok - we can go back where we need to.
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.
@JamesWTruher I tried it at first but then had to revert this change because the [Type]::new()
constructor was only introduced in version 5, therefore it failed the WMF4 build and we should not document examples that do not work on supported PS versions. Will therefore 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.
yah - I thought about this again last night and realized this wouldn't work because of the downlevel requirements. We won't be able to support the modern constructor syntax until we drop support for ps v3/4
For information, these changes are a breaking change, because a priori the 'lookup algorithm' of Powershell does not know how to call the code that worked previously. |
@LaurentDardenne I am sorry for that, every release comes with minor breaking changes, which are usually for a better experience, which is to actually propagate the SuggestedCorrections to the end user (one can use them inside vscode now for example). Thank you for your continued and detailed feedback though :)
|
"every release comes with minor breaking changes," |
PR Summary
Closes #619
Populate property and make it public to keep construction of the object easy.
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets. Please mark anything not applicable to this PRNA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready