Skip to content

Invoke-ScriptAnalyzer -EnableExit sets exit code based on the last evaluated file with piped input #2054

@MatejKafka

Description

@MatejKafka

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

$null = mkdir analyzer
cd .\analyzer\
$PSNativeCommandUseErrorActionPreference = $false

'function fn() {ls}' >1.psm1
'function fn() {}' >2.psm1

# exits with code 0, because the last evaluated file (2.psm1) does not have any violations
pwsh -noprofile {gi .\1.psm1, .\2.psm1 | Invoke-ScriptAnalyzer -EnableExit}
$LastExitCode

# exits with code 1
pwsh -noprofile {gi .\2.psm1, .\1.psm1 | Invoke-ScriptAnalyzer -EnableExit}
$LastExitCode

Expected behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      1.psm1     1     'ls' is an alias of 'Get-ChildItem'. Alias can introduce
                                                                  possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.

1

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      1.psm1     1     'ls' is an alias of 'Get-ChildItem'. Alias can introduce
                                                                  possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.

1

Actual behavior

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      1.psm1     1     'ls' is an alias of 'Get-ChildItem'. Alias can introduce
                                                                  possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.

0

RuleName                            Severity     ScriptName Line  Message
--------                            --------     ---------- ----  -------
PSAvoidUsingCmdletAliases           Warning      1.psm1     1     'ls' is an alias of 'Get-ChildItem'. Alias can introduce
                                                                  possible problems and make scripts hard to maintain. Please
                                                                  consider changing alias to its full content.

1

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.6.0-preview.2
PSEdition                      Core
GitCommitId                    7.6.0-preview.2
OS                             Microsoft Windows 10.0.19045
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.23.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions