Title: PSUseDeclaredVarsMoreThanAssignments is thrown incorrectly · Issue #903 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: PSUseDeclaredVarsMoreThanAssignments is thrown incorrectly · Issue #903 · PowerShell/PSScriptAnalyzer
X Title: PSUseDeclaredVarsMoreThanAssignments is thrown incorrectly · Issue #903 · PowerShell/PSScriptAnalyzer
Description: Steps to reproduce $files = Get-ChildItem -Recurse $folder $str = $files.Count.ToString( 'n0' ) $totalSize = 0 $files | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object { $totalSize += $_.Length } # warning for $totalSize $s...
Open Graph Description: Steps to reproduce $files = Get-ChildItem -Recurse $folder $str = $files.Count.ToString( 'n0' ) $totalSize = 0 $files | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object { $totalSize +=...
X Description: Steps to reproduce $files = Get-ChildItem -Recurse $folder $str = $files.Count.ToString( 'n0' ) $totalSize = 0 $files | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object { $tota...
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/903
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PSUseDeclaredVarsMoreThanAssignments is thrown incorrectly","articleBody":"Steps to reproduce\r\n------------------\r\n\r\n````powershell\r\n$files = Get-ChildItem -Recurse $folder\r\n$str = $files.Count.ToString( 'n0' )\r\n$totalSize = 0\r\n$files |\r\n Where-Object { $_.PSIsContainer -eq $false } | \r\n ForEach-Object { $totalSize += $_.Length } # warning for $totalSize\r\n$str = $totalSize.ToString( 'n0' )\r\n````\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nOn line 7, nothing should be reported.\r\n\r\nActual behavior\r\n---------------\r\n\r\nOn line 7, $totalSize is underlined with a green squiggle, \"The variable 'totalSize' is assigned but never used. (PSUseDeclaredVarsMoreThanAssignments)\"; which is obviously false.\r\n\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\nLatest VSCode on Windows. PS 5.1 with Win10 patched to current.\r\n\r\n\u003c!-- Provide the output of the following 2 commands -->\r\n\r\n```powershell\r\n> $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 5.1.16299.98\r\nPSEdition Desktop\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nBuildVersion 10.0.16299.98\r\nCLRVersion 4.0.30319.42000\r\nWSManStackVersion 3.0\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\n\r\n> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }\r\n\r\nPS C:\\Users\\michael> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }\r\n1.16.1\r\nPS C:\\Users\\michael>\r\n","author":{"url":"https://github.com/essentialexch","@type":"Person","name":"essentialexch"},"datePublished":"2018-02-21T01:22:55Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/903"}
| 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:2dd17ac6-dfb5-916f-ea28-c9ee36e66402 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C60A:212F96:664B49:86FAE7:6AFCF53F |
| html-safe-nonce | 99b6d14150f021fc5d6b5b6eba6c44c2f7c9803a2ae9b0281acb9d8e39ef58eb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNjBBOjIxMkY5Njo2NjRCNDk6ODZGQUU3OjZBRkNGNTNGIiwidmlzaXRvcl9pZCI6IjU2MzA1ODE1NzU3MDg4OTg2MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d91b382f7497f3cf2c2f54d3f7961ada44157328e76dcaf39b8f33e3351dd20 |
| hovercard-subject-tag | issue:298809826 |
| 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/903/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b86b2494e3bc668c5b713eb6b60c4cd802004fb332adb8784250c6741878be88/PowerShell/PSScriptAnalyzer/issues/903 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b86b2494e3bc668c5b713eb6b60c4cd802004fb332adb8784250c6741878be88/PowerShell/PSScriptAnalyzer/issues/903 |
| og:image:alt | Steps to reproduce $files = Get-ChildItem -Recurse $folder $str = $files.Count.ToString( 'n0' ) $totalSize = 0 $files | Where-Object { $_.PSIsContainer -eq $false } | ForEach-Object { $totalSize +=... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | essentialexch |
| hostname | github.com |
| expected-hostname | github.com |
| None | cfabad6ee26d2b84c7afef4ae0cc71b8b692fb9d66f9f15997652ef991bfd3f4 |
| 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 | 35f85b78676038389558a41adf8d76e474592ede |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width