Skip to content

Invoke-ScriptAnalyzer throws error #828

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
chriskuech opened this issue Nov 3, 2017 · 7 comments · Fixed by #838
Closed

Invoke-ScriptAnalyzer throws error #828

chriskuech opened this issue Nov 3, 2017 · 7 comments · Fixed by #838

Comments

@chriskuech
Copy link

PSScriptAnalyzer throws an error "Object reference not set to an instance of an object" when analyzing the hash literal in the following line.

$MyObj | % { @{$_.Name = $_.Value} }

@bergmeister
Copy link
Collaborator

bergmeister commented Dec 2, 2017

Does not repro for me using the latest version 1.16.1 on PowerShell 5.1 for Invoke-ScriptAnalyzer -ScriptDefinition '$MyObj | % { @{$_.Name = $_.Value} }' and the same if I put your line into a ps1 file.
Please provide more details.

@chriskuech
Copy link
Author

No longer repros for me either

@bergmeister
Copy link
Collaborator

Ok. Thanks. Could you otherwise try it on the file in which it was originally? I would be happy to look into it even if it's quite a long script since I recently opened a new PR that allows me to attach the Debugger in VS to it very easily.

@chriskuech chriskuech reopened this Dec 3, 2017
@chriskuech
Copy link
Author

I just tried to repro this issue more intensively.

I ran combinations of

  • Invoke-ScriptAnalyzer . -Recurse vs Invoke-ScriptAnalyzer -ScriptDefinition $snippet
  • Absense vs present of $snippet in a file
  • Absence vs presence of .\PSScriptAnalyzerSettings.psd1

The error case is only when PSScriptAnalyzerSettings.psd1 is defined and the snippet is in a file. The associated PSScriptAnalyzerSettings.psd1 is here

@bergmeister
Copy link
Collaborator

Sorry, it still does not repro for me using your settings file
with script.ps1 having the content $MyObj | % { @{$_.Name = $_.Value} }

Invoke-ScriptAnalyzer -Path .\script.ps1 -Settings (get-content .\PSScriptAnalyzerSettings.psd1)

I have tried with and without -Recurse

@chriskuech
Copy link
Author

Can you try explicitly testing Invoke-ScriptAnalyzer . -Recurse with the correct file system setup?

@bergmeister
Copy link
Collaborator

Aha. I found that I can reproduce now with Invoke-ScriptAnalyzer . but only if the PSScriptAnalyzerSettings.psd1 is in the current directory. So my guess is that this is where it comes from (PSScriptAnalyzer also analyses manifest files by default). Thanks for your persistence. I can now finally look into it.

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