Psscriptanalyzer: Invoke-Formatter not working correctly for small scriptblocks

Created on 27 Aug 2020  路  7Comments  路  Source: PowerShell/PSScriptAnalyzer

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

Invoke-Formatter -ScriptDefinition '{ $_.Status.IsCompleted -eq $true }'
Invoke-Formatter -ScriptDefinition '{ $null -ne $_.Status }'

Expected behavior

No error.

Actual behavior

Error

Invoke-Formatter : Object reference not set to an instance of an object.
At line:1 char:1
+ Invoke-Formatter -ScriptDefinition '{ $null -ne $_.Status }; '
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
    + FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand

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                      5.1.19041.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.0
1.19.1
1.19.1
Area - Formatter Issue - Bug

All 7 comments

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

It looks like this might be using 1.19.0. Can you try verifying that this occurs in 1.19.1?

It doesn't matter

image

Can you share the full stack trace? Either from Get-Error or $error[0] | fl * -force

writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.NullReferenceException: Object reference not set to an instance of an object.
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.IsPreviousTokenOnSameLine(LinkedListNode`
                        1 lparen)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.<FindInnerBraceViolations>d__49.MoveNext(
                        )
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
                           at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.AnalyzeScript(Ast ast, String fileName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.<AnalyzeSyntaxTree>b__2()
TargetObject          :
CategoryInfo          : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}

Closing due to inactivity

Please reopen. It's still broken.

Was this page helpful?
0 / 5 - 0 ratings