Skip to content

Diagnostic ScriptName and ScriptPath properties are identical with a Powershell script rule #618

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 · 3 comments
Assignees
Milestone

Comments

@LaurentDardenne
Copy link

When I run a custom rule :

$Result=Invoke-ScriptAnalyzer -path $pwd\test -CustomRulePath $pwd\OptimizationRules.psd1 -ExcludeRule $n -verbose

VERBOSE: Checking module 'G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\OptimizationRules.psd1' ...
VERBOSE: Analyzing file: G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\test\BinaryExpressionAst.ps1
VERBOSE: Running OptimizationRules\Measure-OptimizeForStatement rule.
...
VERBOSE: Analyzing file: G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\test\MemberExpressionAst.ps1
VERBOSE: Analyzing file: G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\test\ParenExpressionAst.ps1
VERBOSE: Analyzing file: G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\test\ParenExpressionAst2.ps1
VERBOSE: Analyzing file: G:\PS\PSScriptAnalyzerRules\Modules\OptimizationRules\test\ParenExpressionAst3.ps1

The ScriptName and ScriptPath properties are identical :

$Result|select scriptname,scriptpath|fl *
ScriptName : BinaryExpressionAst.ps1
ScriptPath : BinaryExpressionAst.ps1

ScriptName : MemberExpressionAst.ps1
ScriptPath : MemberExpressionAst.ps1

ScriptName : ParenExpressionAst.ps1
ScriptPath : ParenExpressionAst.ps1

ScriptName : ParenExpressionAst2.ps1
ScriptPath : ParenExpressionAst2.ps1
@kapilmb
Copy link

kapilmb commented Sep 23, 2016

This is what I observe:

PS> Invoke-ScriptAnalyzer C:\tmp\test1.ps1 | Format-List ScriptName,ScriptPath


ScriptName : test1.ps1
ScriptPath : C:\tmp\test1.ps1

In your Measure-OptimizeForStatement, when you create an instance of DiagnosticRecord, does the ScriptPath property point to file path or name?

@LaurentDardenne
Copy link
Author

does the ScriptPath property point to file path or name?
Yes, this property is filled :

Function NewDiagnosticRecord{
 param ($Message,$Severity,$Ast)

 $Extent=$Ast.Extent
 $Correction=[Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]::new(
    #Informations d’emplacement
  $Extent.StartLineNumber, 
  $Extent.EndLineNumber,
  $Extent.StartColumnNumber,
  $Extent.EndColumnNumber, 
   #Texte de la correction lié à la régle
  "Texte de la correction lié à la régle", 
    #Nom du fichier concerné
  $Extent.File,                
    #Description de la correction
  'Description de la correction'
 )
 [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.DiagnosticRecord]::new(
    $Message,
    $Extent,
    $PSCmdlet.MyInvocation.InvocationName,
    $Severity,
    $Extent.File, 
    $null,
    $Correction
 )
}

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

bug_scriptpath

@kapilmb
Copy link

kapilmb commented Sep 26, 2016

The underlying issue here is the same as in #619. The Engine loses some information while converting PSObject to DiagnosticRecord.

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

No branches or pull requests

2 participants