Title: PSUseConsistentIndentation flattens the indentation of commented-out code · Issue #2217 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: PSUseConsistentIndentation flattens the indentation of commented-out code · Issue #2217 · PowerShell/PSScriptAnalyzer
X Title: PSUseConsistentIndentation flattens the indentation of commented-out code · Issue #2217 · PowerShell/PSScriptAnalyzer
Description: Summary PSUseConsistentIndentation rewrites the whitespace before each comment's #, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code (where the nested structure is expressed by...
Open Graph Description: Summary PSUseConsistentIndentation rewrites the whitespace before each comment's #, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code (wh...
X Description: Summary PSUseConsistentIndentation rewrites the whitespace before each comment's #, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/2217
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSUseConsistentIndentation flattens the indentation of commented-out code","articleBody":"## Summary\n\n`PSUseConsistentIndentation` rewrites the whitespace *before* each comment's `#`, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code (where the nested structure is expressed by the indentation before `#`), the rule flattens it, so the structure is lost. Whitespace *after* the `#` is preserved, so the two styles behave differently:\n\n```powershell\n# preserved - the extra indentation is after the '#'\n\t# if ($b) {\n\t# doThing\n\t# }\n\n# flattened - the extra indentation is before the '#'\n\t# if ($b) {\n\t\t# doThing\n\t# }\n```\n\n## Steps to reproduce\n\nOnly the one rule is enabled:\n\n```powershell\n$settings = @{\n\tIncludeRules = @('PSUseConsistentIndentation')\n\tRules = @{\n\t\tPSUseConsistentIndentation = @{ Enable = $true; IndentationSize = 4; PipelineIndentation = 'NoIndentation'; Kind = 'tab' }\n\t}\n}\n```\n\nInput:\n\n```powershell\nif ($a) {\n\t# if ($b) {\n\t\t# doThing\n\t# }\n}\n```\n\nActual (`Invoke-Formatter -ScriptDefinition $code -Settings $settings`):\n\n```powershell\nif ($a) {\n\t# if ($b) {\n\t# doThing\n\t# }\n}\n```\n\nExpected: the commented-out block keeps its relative indentation (at most the whole comment run may be shifted to the code indentation).\n\nThe same happens with `Kind = 'space'` and when there is real code after the comment run.\n\n## Environment\n\n- PSScriptAnalyzer 1.25.0\n- PowerShell 7.6.6 on Windows\n\n## Why it matters\n\nCommenting out a block is a common way to keep code around; flattening the indentation makes the commented-out block unreadable. Tooling that encodes directives as comments (e.g. sources that are uncommented by an external preprocessor) also relies on the indentation before `#` being preserved.\n\nRelated: #2151 asks for an ignore-range directive, but this is about the default behaviour of the indentation rule on ordinary comment runs.\n","author":{"url":"https://github.com/steve02081504","@type":"Person","name":"steve02081504"},"datePublished":"2026-09-18T08:11:46Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/2217"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bab742b8-6314-25f1-dbe6-2467e7dff625 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC4A:2FF8FB:14F2C57:1D893B5:6AFCE77B |
| html-safe-nonce | 923008ba2b6c3dbd23147b9c8fcc6b8b3aba3b9b0109aab873763aa9bce55a2c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzRBOjJGRjhGQjoxNEYyQzU3OjFEODkzQjU6NkFGQ0U3N0IiLCJ2aXNpdG9yX2lkIjoiNDUyMjYxMjczNTM5NTAzOTk1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b723c854e3c85d582a0d3723f89d1d4807dccd8760d9900b8dda7df151162951 |
| hovercard-subject-tag | issue:5497286175 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PSScriptAnalyzer/2217/issue_layout |
| twitter:image | https://opengraph.githubassets.com/82b8165ec6ac35c4c4d4e050ddd76c8fcf3ff69374320a0f45d556a698015f99/PowerShell/PSScriptAnalyzer/issues/2217 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/82b8165ec6ac35c4c4d4e050ddd76c8fcf3ff69374320a0f45d556a698015f99/PowerShell/PSScriptAnalyzer/issues/2217 |
| og:image:alt | Summary PSUseConsistentIndentation rewrites the whitespace before each comment's #, aligning every comment line in a block to the block indentation. When a run of comments is commented-out code (wh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | steve02081504 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 99aede4c5f55ec5cf06666a8c9e03ebf9f85f7231223e7f1c38c16e5504835b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 33149177 |
| octolytics-dimension-repository_nwo | PowerShell/PSScriptAnalyzer |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 33149177 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PSScriptAnalyzer |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ecfd63ca125ec74b42f74eeb158b3fa081c8c497 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width