Skip to content

Add the possibilty to manage suggestedCorrections property with a script rule #619

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

Closed
LaurentDardenne opened this issue Sep 23, 2016 · 12 comments · Fixed by #1000
Closed
Assignees
Milestone

Comments

@LaurentDardenne
Copy link

In the file ScriptRuleDocumentation.md, it is says :

# DiagnosticRecord should have four properties: Message, Extent, RuleName and Severity

$result = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord[]]@{
    "Message"  = "This is a sample rule"
    "Extent"   = $ast.Extent
    "RuleName" = $PSCmdlet.MyInvocation.InvocationName
    "Severity" = "Warning"
}

It is possible to assign the suggestedCorrections property in a script, but the C# code do not assign this property.

@kapilmb
Copy link

kapilmb commented Sep 23, 2016

Yes, you can add SuggestedCorrections property.

$correctionExtent = New-Object `
-TypeName 'Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent' `
-ArgumentList $startLineNumber,$endLineNumber,$startColumnNumber,$endColumnNumber,$replacementText,$filepath,$description

$result = New-Object -TypeName ` 
'Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord' `
-ArgumentList "This is sample rule",$violationExtent,'rulename','warning','c:\tmp',$null,$correctionExtent

As of now you cannot initialize DiagnosticRecord with SuggestedCorrection property using a dictionary literal.

If it helps, you can find a relevant C# example here

@LaurentDardenne
Copy link
Author

Yes, you can add SuggestedCorrections property.
This problem is similar this one

When i use the function outside PSscriptAnalyzer, this property is correctly assigned, but when PSscriptAnalyzer use my function this property is no more correctly assigned :
bug_suggestedcorrection

May be this C# code is incorrect...

@kapilmb
Copy link

kapilmb commented Sep 26, 2016

@LaurentDardenne Thanks for the explanation! I now understand the issue. Yes, looks like something is lost while converting from PSObject to DiagnosticRecord in the Engine.

@ajansveld
Copy link

Is this still on the radar? Seems like it would be fairly easy to fix and it would be great to provide custom formatting in vscode.

Thanks!

@bergmeister
Copy link
Collaborator

@LaurentDardenne Do I understand correctly that we can close this now because the root cause was fixed in #618?

@LaurentDardenne
Copy link
Author

@bergmeister
if you want, I have not tested again for 1 year.
I'm trying to check if it works.

@LaurentDardenne
Copy link
Author

The issue 618 is fixed, but not this one.

When i use the function outside PSscriptAnalyzer, this property is correctly assigned, but when PSscriptAnalyzer use my function this property is no more correctly assigned .

@LaurentDardenne
Copy link
Author

Maybe this code is involved.
if necessary I can join a test module.

@Mcgurk125
Copy link

Has this ever been fixed!?

@bergmeister
Copy link
Collaborator

bergmeister commented May 10, 2018

@Mcgurk125
As per this comment 2 months ago, it does not seems so (I have not verified it myself, but there was definitely no code change in this area in the last 2 months). I can take a brief look at it in the next days but also feel free to grab the issue and submit a PR for it.

@bergmeister bergmeister modified the milestones: 1612, Backlog May 11, 2018
@bergmeister
Copy link
Collaborator

bergmeister commented May 14, 2018

@LaurentDardenne @Mcgurk125 I have a fix for this in my branch ready here and I will also make the property public to keep the construction of the DiagnosticRecord object easy as it is. PR with the fix is below:

@LaurentDardenne
Copy link
Author

Thank you for the work done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants