close
The Wayback Machine - https://web.archive.org/web/20200918101107/https://github.com/PowerShell/PSScriptAnalyzer/issues/1577
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

Invoke-Formatter not working correctly for small scriptblocks #1577

Open
PrzemyslawKlys opened this issue Aug 27, 2020 · 5 comments
Open

Invoke-Formatter not working correctly for small scriptblocks #1577

PrzemyslawKlys opened this issue Aug 27, 2020 · 5 comments

Comments

@PrzemyslawKlys
Copy link
Contributor

@PrzemyslawKlys PrzemyslawKlys commented Aug 27, 2020

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
@rjmholt
Copy link
Member

@rjmholt rjmholt commented Sep 1, 2020

(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?

@PrzemyslawKlys
Copy link
Contributor Author

@PrzemyslawKlys PrzemyslawKlys commented Sep 4, 2020

It doesn't matter

image

@rjmholt
Copy link
Member

@rjmholt rjmholt commented Sep 4, 2020

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

@PrzemyslawKlys
Copy link
Contributor Author

@PrzemyslawKlys PrzemyslawKlys commented Sep 4, 2020

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}
@rjmholt
Copy link
Member

@rjmholt rjmholt commented Sep 4, 2020

private bool IsPreviousTokenOnSameLine(LinkedListNode<Token> lparen)
{
return lparen.Previous.Value.Extent.EndLineNumber == lparen.Value.Extent.StartLineNumber;
}

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.