Skip to content

UseConsistentWhitespace/CheckOpenBrace false positive #1522

Description

@metablaster

Steps to reproduce

Here is setting snapshot I'm trying to use:

@{
IncludeRules = @(
       'PSUseConsistentWhitespace')

Rules = @{
        PSUseConsistentWhitespace = @{
	         # Checks if there is a space between a keyword and its corresponding open brace.
	         # E.g. foo { } instead of foo{ }
	         # default = true (powershell.codeFormatting.whitespaceBeforeOpenBrace)
	         CheckOpenBrace = $true
        }
}

And here is sample test function, not that open brace is not new line!

function Test-Foo()
{
}

Expected behavior

No warning is shown for bellow function

# NO WARNING HERE
function Test-Foo()
{
}

Actual behavior

Warning is shown because brace is on next line, there is no need for any space here,
This warning is valid only if open brace is on same line as function name.

# PSUseConsistentWhitespace   Warning  Use space before open brace.
function Test-Foo()
{
}

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.18363
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.19.0

Activity

  1. bergmeister commented on Jun 13, 2020

    @bergmeister
    Collaborator

    Thanks for taking the time to report it. I can verify this happens with 1.19.0 but I am happy to say we have fixed this in master already by PR #1491
    We will briefly discuss this issue at the next triage session since there are also other recently fixed cases that would warrant releasing some of the recent fixes in a new patch release, therefore expect this issue to get closed soon but you'll have to wait for the next release in the meantime.

  2. metablaster commented on Jun 15, 2020

    @metablaster
    Author

    Thank you for quick response!
    Glad to hear it's already resolved.

  3. ghost closed this as completedon Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions