Skip to content
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

IScriptExtent.File Property is null in VS Code #5038

Open
tablackburn opened this issue Aug 28, 2024 · 0 comments
Open

IScriptExtent.File Property is null in VS Code #5038

tablackburn opened this issue Aug 28, 2024 · 0 comments

Comments

@tablackburn
Copy link

tablackburn commented Aug 28, 2024

When attempting to write a custom PSScriptAnalyzer rule, the IScriptExtent.File property is null in the Problems pane of VS Code, but is not null not outside of the VS Code Problems pane.

Steps to reproduce

git clone https://github.com/bergmeister/PSScriptAnalyzer-VSCodeIntegration.git
(Get-Content .\PSScriptAnalyzer-VSCodeIntegration\CustomPSScriptAnalyzerRules.psm1) -replace 'Message\s+=.+$', 'Message = "`$ast.Extent.File = $($ast.Extent.File)"' | Set-Content .\PSScriptAnalyzer-VSCodeIntegration\CustomPSScriptAnalyzerRules.psm1
Set-Location PSScriptAnalyzer-VSCodeIntegration
Invoke-ScriptAnalyzer -Path .\scriptWithViolations.ps1 -CustomRulePath .\CustomPSScriptAnalyzerRules.psm1 -IncludeRule Warning*
code .

In VS Code, open scriptWithViolations.ps1, then open the Problems pane (Ctrl + Shift + M).

Expected behavior

$ast.Extent.File is populated with the absolute path of the script file scriptWithViolations.ps1, the same as the output from Invoke-ScriptAnalyzer

Actual behavior

Invoke-ScriptAnalyzer returns:

PS C:\Users\<redacted>\PSScriptAnalyzer-VSCodeIntegration> Invoke-ScriptAnalyzer -Path .\scriptWithViolations.ps1 -CustomRulePath .\CustomPSScriptAnalyzerRules.psm1 -IncludeRule WarningAboutDoSomething

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
CustomPSScriptAnalyzerRules\Warning Warning      scriptWith 1     $ast.Extent.File = C:\Users\<redacted>\PSScriptAnaly
AboutDoSomething                                 Violations       zer-VSCodeIntegration\scriptWithViolations.ps1
                                                 .ps1
CustomPSScriptAnalyzerRules\Warning Warning      scriptWith 1     $ast.Extent.File = C:\Users\<redacted>\PSScriptAnaly
AboutDoSomething                                 Violations       zer-VSCodeIntegration\scriptWithViolations.ps1
                                                 .ps1

while VS Code's Problems pane shows $ast.Extent.File as $null

$ast.Extent.File = 

image

If an unexpected error was thrown, then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

1.22.0
1.22.0
@SydneyhSmith SydneyhSmith transferred this issue from PowerShell/PSScriptAnalyzer Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant