René's URL Explorer Experiment


Title: PSUseConsistentIndentation: Hashtable inside method call gets double-indented · Issue #2159 · PowerShell/PSScriptAnalyzer · GitHub

Open Graph Title: PSUseConsistentIndentation: Hashtable inside method call gets double-indented · Issue #2159 · PowerShell/PSScriptAnalyzer

X Title: PSUseConsistentIndentation: Hashtable inside method call gets double-indented · Issue #2159 · PowerShell/PSScriptAnalyzer

Description: Summary PSUseConsistentIndentation incorrectly indents hashtable body content when the hashtable is inside a method call parenthesis (e.g., .Add(@{ ... })). The formatter treats the @{ opening as an additional indentation level relative ...

Open Graph Description: Summary PSUseConsistentIndentation incorrectly indents hashtable body content when the hashtable is inside a method call parenthesis (e.g., .Add(@{ ... })). The formatter treats the @{ opening as a...

X Description: Summary PSUseConsistentIndentation incorrectly indents hashtable body content when the hashtable is inside a method call parenthesis (e.g., .Add(@{ ... })). The formatter treats the @{ opening as a...

Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/2159

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSUseConsistentIndentation: Hashtable inside method call gets double-indented","articleBody":"## Summary\n\n`PSUseConsistentIndentation` incorrectly indents hashtable body content when the hashtable is inside a method call parenthesis (e.g., `.Add(@{ ... })`). The formatter treats the `@{` opening as an additional indentation level relative to the method call position, producing excessive indentation instead of indenting consistently from the line start.\n\nThis was originally reported as [PowerShell/vscode-powershell#5397](https://github.com/PowerShell/vscode-powershell/issues/5397), where a maintainer confirmed it belongs in PSScriptAnalyzer. That issue was auto-closed awaiting author feedback.\n\n## Steps to Reproduce\n\n```powershell\n# PSScriptAnalyzer 1.24.0 / PowerShell 7.5.4\n\n# Minimal repro - only PSUseConsistentIndentation enabled\n$code = @'\n$list.Add([PSCustomObject]@{\n    Name = \"Test\"\n    Value = 123\n})\n'@\n\n$settings = @{\n    IncludeRules = @(\"PSUseConsistentIndentation\")\n    Rules = @{\n        PSUseConsistentIndentation = @{\n            Enable = $true\n            IndentationSize = 4\n            Kind = \"space\"\n        }\n    }\n}\n\nInvoke-Formatter -ScriptDefinition $code -Settings $settings\n```\n\n## Expected Behavior\n\nHashtable properties should be indented by one level (4 spaces) from the line start, regardless of where `@{` appears on the line:\n\n```powershell\n$list.Add([PSCustomObject]@{\n    Name = \"Test\"\n    Value = 123\n})\n```\n\n## Actual Behavior\n\nProperties are indented to the `@{` column position (8 spaces), and the closing `})` gets its own indentation level too:\n\n```powershell\n$list.Add([PSCustomObject]@{\n        Name = \"Test\"\n        Value = 123\n    })\n```\n\n## Additional Test Cases\n\nThe problem compounds with deeper nesting:\n\n```powershell\n# Input:\nforeach ($item in $items) {\n    $results.Add([PSCustomObject]@{\n        Name = $item.Name\n        Value = $item.Value\n        Status = \"OK\"\n    })\n}\n\n# Formatted (actual) - 12 spaces for hashtable body:\nforeach ($item in $items) {\n    $results.Add([PSCustomObject]@{\n            Name = $item.Name\n            Value = $item.Value\n            Status = \"OK\"\n        })\n}\n\n# Expected - 8 spaces (one level deeper than the foreach body):\nforeach ($item in $items) {\n    $results.Add([PSCustomObject]@{\n        Name = $item.Name\n        Value = $item.Value\n        Status = \"OK\"\n    })\n}\n```\n\nStandalone hashtables (not inside method calls) format correctly:\n\n```powershell\n# This formats correctly with 4-space indent:\n$obj = [PSCustomObject]@{\n    Name = \"Test\"\n    Value = 123\n}\n```\n\n## Root Cause Analysis\n\n`PSUseConsistentIndentation` appears to count `(` as an indentation-increasing token, then also counts `@{` as another level. For standalone hashtables like `$x = @{`, the `=` doesn't increase indentation so only `@{` counts — producing 4 spaces correctly. But inside `.Add(@{`, the `(` adds one level and `@{` adds another, producing 8 spaces (2 × 4).\n\n## Impact\n\nThis is a common PowerShell pattern — building lists of `[PSCustomObject]` via `.Add()` is idiomatic. The excessive indentation forces a choice between:\n1. Disabling `PSUseConsistentIndentation` entirely\n2. Accepting unintuitively deep indentation\n3. Disabling `powershell.codeFormatting.alignPropertyValuePairs` (which also disables desirable alignment on standalone hashtables)\n4. Disabling format-on-save for PowerShell files\n\nWhen combined with `PSAlignAssignmentStatement.CheckHashtable`, the problem is amplified because value alignment is calculated from the already-wrong base indentation.\n\n## Workaround\n\nSetting `powershell.codeFormatting.alignPropertyValuePairs: false` in VS Code mitigates the worst visual impact but also disables alignment on standalone hashtables where it's desirable.\n\n## Environment\n\n- PSScriptAnalyzer: 1.24.0\n- PowerShell: 7.5.4\n- OS: Linux (also reported on Windows 11 in vscode-powershell#5397)\n","author":{"url":"https://github.com/quasarea","@type":"Person","name":"quasarea"},"datePublished":"2026-03-05T01:07:43Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/2159"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:17d07dd7-45ed-3711-09b8-869d8a3cc07b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA43A:37F963:82B21:ADCC7:6AFCD73C
html-safe-nonce9261d893f0b0c1c5ada12a8d8f88c9a9f3d5f089960c8312f3497d6d729dd47f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDNBOjM3Rjk2Mzo4MkIyMTpBRENDNzo2QUZDRDczQyIsInZpc2l0b3JfaWQiOiI4OTY5ODQwODA2MzYxNjE4MjM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac604dc77a2d43f035add30d508ec4e2881932c27d72da879c9b864704aeecd4da
hovercard-subject-tagissue:4025052321
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PSScriptAnalyzer/2159/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b89beab20380553a41e9da7cb06af90ca6b9a03738004e04cc4a9136fd64f11a/PowerShell/PSScriptAnalyzer/issues/2159
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b89beab20380553a41e9da7cb06af90ca6b9a03738004e04cc4a9136fd64f11a/PowerShell/PSScriptAnalyzer/issues/2159
og:image:altSummary PSUseConsistentIndentation incorrectly indents hashtable body content when the hashtable is inside a method call parenthesis (e.g., .Add(@{ ... })). The formatter treats the @{ opening as a...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamequasarea
hostnamegithub.com
expected-hostnamegithub.com
Noneb5b7bc7e41e0a604bbdb5035c7ed9620c2d28b9c8a18747182e2262a75abfd91
turbo-cache-controlno-preview
go-importgithub.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id33149177
octolytics-dimension-repository_nwoPowerShell/PSScriptAnalyzer
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id33149177
octolytics-dimension-repository_network_root_nwoPowerShell/PSScriptAnalyzer
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseff5022cc3aa767e6115451d9c322dd975506d40e
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/PowerShell/PSScriptAnalyzer/issues/2159#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPSScriptAnalyzer%2Fissues%2F2159
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPSScriptAnalyzer%2Fissues%2F2159
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=PowerShell%2FPSScriptAnalyzer
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/issues/2159
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/issues/2159
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/issues/2159
PowerShellhttps://github.com/PowerShell
PSScriptAnalyzerhttps://github.com/PowerShell/PSScriptAnalyzer
Codehttps://github.com/PowerShell/PSScriptAnalyzer
Issues407 (407)https://github.com/PowerShell/PSScriptAnalyzer/issues
Pull requests34 (34)https://github.com/PowerShell/PSScriptAnalyzer/pulls
Discussionshttps://github.com/PowerShell/PSScriptAnalyzer/discussions
Actionshttps://github.com/PowerShell/PSScriptAnalyzer/actions
Projectshttps://github.com/PowerShell/PSScriptAnalyzer/projects
Wikihttps://github.com/PowerShell/PSScriptAnalyzer/wiki
Security and qualityhttps://github.com/PowerShell/PSScriptAnalyzer/security
Insightshttps://github.com/PowerShell/PSScriptAnalyzer/insights
https://github.com/PowerShell/PSScriptAnalyzer
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PSScriptAnalyzer/issues/2159
New issuehttps://github.com/login?return_to=https://github.com/PowerShell/PSScriptAnalyzer/issues/2159
#2173https://github.com/PowerShell/PSScriptAnalyzer/pull/2173
PSUseConsistentIndentation: Hashtable inside method call gets double-indentedhttps://github.com/PowerShell/PSScriptAnalyzer/issues/2159#top
#2173https://github.com/PowerShell/PSScriptAnalyzer/pull/2173
Area - Formatterhttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Area%20-%20Formatter%22
Up-for-Grabshttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Up-for-Grabs%22
https://github.com/quasarea
quasareahttps://github.com/quasarea
on Mar 5, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#issue-4025052321
PowerShell/vscode-powershell#5397https://github.com/PowerShell/vscode-powershell/issues/5397
Justin Grote (JustinGrote)https://github.com/JustinGrote
on Mar 5, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#event-23279594194
Formatter aligns hashtable values to method call position instead of respecting indentation settings vscode-powershell#5397https://github.com/PowerShell/vscode-powershell/issues/5397
https://github.com/liamjpeters
Liam Peters (liamjpeters)https://github.com/liamjpeters
on Mar 5, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#issuecomment-4007481609
like thishttps://github.com/PowerShell/PSScriptAnalyzer/commit/3d31f1e83d40de88691f15b7e19c1d01d3512c25
Christoph Bergmeister (bergmeister)https://github.com/bergmeister
Up-for-Grabshttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Up-for-Grabs%22
Area - Formatterhttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Area%20-%20Formatter%22
on Mar 31, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#event-24085736947
https://github.com/bergmeister
Christoph Bergmeister (bergmeister)https://github.com/bergmeister
on Mar 31, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#issuecomment-4164748044
Andy Jordan (andyleejordan)https://github.com/andyleejordan
completedhttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#2173https://github.com/PowerShell/PSScriptAnalyzer/pull/2173
on May 4, 2026https://github.com/PowerShell/PSScriptAnalyzer/issues/2159#event-25149269742
Sign up for freehttps://github.com/signup?return_to=https://github.com/PowerShell/PSScriptAnalyzer/issues/2159
Sign in to commenthttps://github.com/login?return_to=https://github.com/PowerShell/PSScriptAnalyzer/issues/2159
Area - Formatterhttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Area%20-%20Formatter%22
Up-for-Grabshttps://github.com/PowerShell/PSScriptAnalyzer/issues?q=state%3Aopen%20label%3A%22Up-for-Grabs%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.