-
Notifications
You must be signed in to change notification settings - Fork 394
PSUseConsistentWhitespace for Pester tests and 'Should Throw' #1298
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
Comments
Thanks for the report. Some of the formatting rules were written quite simplistically a few years ago, I am aware that there are a few red herring warnings. Most users don't see them because they don't use custom settings or don't use formatting rules as part of the 'analysis' and their nature is usually harmless. But I still think it's good to write them down and tackle them one by one and slowly make the Formatter better because there are still weird edge cases where the Formatter does not format when it should or corrections cancel each other out, etc. and this would be a small but useful start to tackle the bigger problem. :-) |
Is this a case where the error message is just incorrect? Looks like it means 'after brace', as that's what 'format document' will do. |
@msftrncs Yes, in this context, the error message is incorrect. Putting a space after the opening brace does not resolve the problem. Also, the following code does not have the error: [scriptblock] $sb = {'dummy'} I believe it's related to the opening brace being the beginning of the command. Normally an opening brace is associated with the preceding code. Hope this makes sense. |
I think the correct way to state the issue is that its related to a 'scriptblock', where the rule is meant for a 'statementblock'. 'scriptblock's are for arguments or operands, and a 'statementblock' is for use after a control keyword. Technically I think the rule should work regardless of the type of block, but when its a scriptblock it must be confused that there is no keyword before it. |
I have the same issue :( |
Steps to reproduce
Testing.Tests.ps1 contains:
Expected behavior
No PSScriptAnalyzer issues.
Actual behavior
PSScriptAnalyzer requires a space before the opening brace. The indentation puts eight spaces before the brace. Maybe it's to do with the fact that there is nothing before the opening brace. However, this is the recommended way of testing for exceptions in Pester.
Environment data
VS Code
Installed Extensions for VS Code
alefragnani.Bookmarks
Damien.autoit
eamodio.gitlens
ms-vscode.csharp
ms-vscode.powershell
ms-vscode.powershell-preview
streetsidesoftware.code-spell-checker
vscode-icons-team.vscode-icons
> $PSVersionTable
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
Various Settings Files
settings.json
PSScriptAnalyzerSettings.psd1
CustomRule.psm1
Various configuration files.zip
The text was updated successfully, but these errors were encountered: