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

Make Invoke-Formatter cleanup its state to avoid knock on effect on Invoke-ScriptAnalyzer #1121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Engine/Commands/InvokeFormatterCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ protected override void ProcessRecord()
this.WriteObject(formattedScriptDefinition);
}

protected override void EndProcessing()
{
ScriptAnalyzer.Instance.CleanUp();
base.EndProcessing();
}

protected override void StopProcessing()
{
ScriptAnalyzer.Instance.CleanUp();
base.StopProcessing();
}

private void ValidateInputSettings()
{
// todo implement this
Expand Down
11 changes: 9 additions & 2 deletions Tests/Engine/InvokeFormatter.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ $testRootDirectory = Split-Path -Parent $directory
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")

Describe "Invoke-Formatter Cmdlet" {
Context "Cmdlet cleans up and has no knock on effect" {
It "Invoke-Formatter has knock on effect on Invoke-ScriptAnalyzer" {
Invoke-Formatter 'foo'
Invoke-ScriptAnalyzer -ScriptDefinition 'gci' | Should -Not -BeNullOrEmpty
}
}

Context "When positional parameters are given" {
It "Should use the positional parameters" {
$def = @"
Expand Down Expand Up @@ -30,12 +37,12 @@ function foo {
}

It "Should not expand unary operators when being used as a single negative argument" {
$script = '$foo.bar(-$a)'
$script = '$foo.bar(-$a)'
Invoke-Formatter '$foo.bar(-$a)' -Settings CodeFormatting | Should -Be $script
}

It "Should expand unary operators when not being used as a single negative argument" {
Invoke-Formatter '$foo.bar(-$a+$b+$c)' -Settings CodeFormatting | Should -Be '$foo.bar(-$a + $b + $c)'
Invoke-Formatter '$foo.bar(-$a+$b+$c)' -Settings CodeFormatting | Should -Be '$foo.bar(-$a + $b + $c)'
}
}

Expand Down