PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

WIP: Fix: PSUseConsistentWhitespace formatting for do-while, unary operators, and native commands

Open DrSkillIssue opened this issue 7 months ago • 1 comments

PR Summary

Fixes multiple whitespace formatting issues in PSUseConsistentWhitespace rule

Issues Fixed:

  • #1561 - CheckParameter removing whitespace inside string literals
  • #1742 - False positive on hashtable closing brace with CheckInnerBrace
  • #2094 - Incorrect comma formatting in native command arguments (e.g., docker --secret id=x,env=y)
  • #2095 - Missing space between } and keywords in do-while/do-until loops

Changes Made:

Core Fixes:

  • Added FindKeywordAfterBraceViolations to handle keywords following closing braces
  • Enhanced unary operator detection and spacing logic in FindOperatorViolations
  • Fixed FindParameterViolations to skip whitespace inside string literals
  • Added comma pattern detection in FindSeparatorViolations for native command arguments
  • Added the additional keywords to openParenKeywordAllowList: Until, Do, Else, Catch, Finally

Tests Added:

  • Added test-cases for the above-mentioned changes.

PR Checklist

DrSkillIssue avatar Jun 17 '25 12:06 DrSkillIssue

These PRs may just need closed as I couldn't reproduce the issues

  • #1168 - Issue may have been fixed as the behavior is corrected when PSUseConsistentWhitespace is enabled.
  • #1288 - Couldn't reproduce this issue
  • #1298 - Couldn't reproduce this issue
  • #1319 - Couldn't reproduce this issue

PRs that were fixed with this PR

  • #1561 - Fixed with this PR
  • #1742 - Fixed with this PR
  • #2094 - Fixed with this PR
  • #2095 - Fixed with this PR

PRs that can be fixed in another PR(s) once this one is merged

Opting for multiple PRs as this one is large already.

  • #950
  • #1813

DrSkillIssue avatar Jun 17 '25 22:06 DrSkillIssue