Title: Cannot Suppress Messages About a Specific Automatic Variable · Issue #1589 · PowerShell/PSScriptAnalyzer · GitHub
Open Graph Title: Cannot Suppress Messages About a Specific Automatic Variable · Issue #1589 · PowerShell/PSScriptAnalyzer
X Title: Cannot Suppress Messages About a Specific Automatic Variable · Issue #1589 · PowerShell/PSScriptAnalyzer
Description: Setting the CheckID of a SuppressMessageAttribute decoration to '_' fails to suppress the specified message about the '_' automatic variable. Specifically, this fails: [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignment...
Open Graph Description: Setting the CheckID of a SuppressMessageAttribute decoration to '_' fails to suppress the specified message about the '_' automatic variable. Specifically, this fails: [Diagnostics.CodeAnalysis.Sup...
X Description: Setting the CheckID of a SuppressMessageAttribute decoration to '_' fails to suppress the specified message about the '_' automatic variable. Specifically, this fails: [Diagnostics....
Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/issues/1589
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Cannot Suppress Messages About a Specific Automatic Variable","articleBody":"Setting the CheckID of a `SuppressMessageAttribute` decoration to '\\_' fails to suppress the specified message about the '\\_' automatic variable.\r\n\r\nSpecifically, this fails:\r\n`[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '_', Justification='Assignment is by design.')]`\r\nWhile this works as expected:\r\n`[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '', Justification='Assignment is by design.')]`\r\n\r\nSteps to reproduce\r\n------------------\r\nRun `Invoke-ScriptAnalyzer` against the following PowerShell script.\r\n```PowerShell\r\nfunction Import-StringData {\r\n[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', '_', Justification='Assignment is by design.')]\r\n[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'newEntryTemplate', Justification='The subsequent use of newEntryTemplate is not detected by PSScriptAnalyzer.')]\r\nParam([string]$stringToParse)\r\n#region Prepare CrossRef Table\r\n [System.Data.DataTable]$dt = New-Object System.Data.DataTable\r\n $dt.Columns.Add(\"measCode\", [string]) | Out-Null\r\n $dt.Columns.Add(\"measBasis\", [string]) | Out-Null\r\n $dt.Rows.Add(@(\"BZ\",\"MMBtu\")) | Out-Null\r\n $dt.Rows.Add(@(\"G8\",\"Gigacalories\")) | Out-Null\r\n $dt.Rows.Add(@(\"GV\",\"Gigajoules\")) | Out-Null\r\n $dt.Rows.Add(@(\"TZ\",\"MCF\")) | Out-Null\r\n $dt.AcceptChanges()\r\n#endregion Prepare CrossRef Table\r\n\r\n $stringToParse | Select-Object -First 7 | ForEach-Object -Begin {$newEntryTemplate = \"`r`n{0}={1}\"} -Process {\r\n $match = ($_ | Select-String \"Meas Basis Desc[:] (.*)\" -List).Matches\r\n if($null -ne $match){$_ += $newEntryTemplate -f \"measCode\", $dt.Select(\"measBasis='$($match.Groups[1].Value)'\").measCode}\r\n $_ -replace \": \", \"=\"} | ConvertFrom-StringData\r\n}\r\n\r\n$stringToParse = @\"\r\nPosting Date: 2020-09-17\r\nPosting Time: 22:05:44 \r\nEffective Gas Day: 2020-09-18\r\nEffective Gas Time: 9:00:00 am \r\nMeas Basis Desc: MMBtu\r\n\"@\r\n\r\nImport-StringData $stringToParse\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n`Invoke-ScriptAnalyzer` should find 0 rule violations.\r\n\r\nThe `PSAvoidAssignmentToAutomaticVariable` warning about the '\\_' variable on line 18 should be suppressed as per the targeted `SuppressMessageAttribute` decoration on line 2. \r\n\r\nActual behavior\r\n---------------\r\nThe `SuppressMessageAttribute` decoration on line 2 has no effect and `Invoke-ScriptAnalyzer` outputs the following:\r\n>Invoke-ScriptAnalyzer: Suppression Message Attribute error at line 2 in Test PSScriptAnalyzer.ps1 : Cannot find any DiagnosticRecord with the Rule Suppression ID \\_.\r\n>\r\n>RuleName | Severity | ScriptName | Line | Message\r\n>-------- | -------- | ---------- | ---- | -------\r\n>PSAvoidAssignmentToAutomaticVariable | Warning | Test Suppression.ps1 |18 | The Variable '\\_' is an automatic variable that is built into PowerShell, assigning to it might have undesired side effects. If assignment is not by design, please use a different name.\r\n>\r\n>1 rule violation found. Severity distribution: Error = 0, Warning = 1, Information = 0\r\n\r\nEnvironment data\r\n----------------\r\n```PowerShell\r\n> $PSVersionTable\r\nName Value\r\n---- -----\r\nPSVersion 7.0.3\r\nPSEdition Core\r\nGitCommitId 7.0.3\r\nOS Microsoft Windows 10.0.18363\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n\r\n> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }\r\n1.19.1\r\n```\r\n","author":{"url":"https://github.com/marshallwp","@type":"Person","name":"marshallwp"},"datePublished":"2020-09-18T16:28:06Z","url":"https://github.com/PowerShell/PSScriptAnalyzer/issues/1589"}
| 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:3eb2f008-9ba2-83bd-76a0-f0632b604c2a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C58:2C8B07:8AF580:C08A64:6AFD2FA5 |
| html-safe-nonce | 16dfaeb6804218aa922a506323d29ab496db1da90a0fd961e3b4f67a2c7c5368 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QzU4OjJDOEIwNzo4QUY1ODA6QzA4QTY0OjZBRkQyRkE1IiwidmlzaXRvcl9pZCI6IjczMzQ0MDYxMjcyMTMxNjI0MDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 54fe93fedda4fc152b7e6901e7339132d4f73e3c8661fd9e30b5a252ec7e2e81 |
| hovercard-subject-tag | issue:704506847 |
| 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/1589/issue_layout |
| twitter:image | https://opengraph.githubassets.com/08de04fa1303e56899e5b936cd80ffa1e747373f072ffef88a686e2d4e4d0eb0/PowerShell/PSScriptAnalyzer/issues/1589 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/08de04fa1303e56899e5b936cd80ffa1e747373f072ffef88a686e2d4e4d0eb0/PowerShell/PSScriptAnalyzer/issues/1589 |
| og:image:alt | Setting the CheckID of a SuppressMessageAttribute decoration to '_' fails to suppress the specified message about the '_' automatic variable. Specifically, this fails: [Diagnostics.CodeAnalysis.Sup... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marshallwp |
| hostname | github.com |
| expected-hostname | github.com |
| None | 065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19 |
| 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 | 941021edf0c2ec58298f4a2c8f27ae507d129c92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width