FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow suppression of PSUseSingularNouns for specific function by fflaten · Pull Request #1903 · PowerShell/PSScriptAnalyzer · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cs  (1) .md  (1) .ps1  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions Rules/UseSingularNouns.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
GetName(),
DiagnosticSeverity.Warning,
fileName,
funcAst.Name,
suggestedCorrections: new CorrectionExtent[] { GetCorrection(pluralizer, extent, funcAst.Name, noun) });
}
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ Write-Output "Adding some data"
$diagnostics.SuggestedCorrections.Text | Should -BeExactly $Correction
}
}
Context 'Suppression' {
It 'Can be suppressed by RuleSuppressionId' {
$scriptDef = @"
function Get-Elements {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('$nounViolationName', 'Get-Elements')]
param()
}
"@
$warnings = @(Invoke-ScriptAnalyzer -ScriptDefinition $scriptDef)
$warnings.Count | Should -Be 0
}
}
}

Describe "UseApprovedVerbs" {
Expand Down
9 changes: 9 additions & 0 deletions docs/Rules/UseSingularNouns.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ title: UseSingularNouns

PowerShell team best practices state cmdlets should use singular nouns and not plurals.

Suppression allows to suppress just specific function names, for example

```
function Get-Elements {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', 'Get-Elements')]
Param()
}
```

## How

Change plurals to singular.
Expand Down

Back | FazBrowse Home | New Git URL