Skip to content

Commit 45edb8d

Browse files
fflatenbergmeister
andauthored
Allow suppression of PSUseSingularNouns for specific function (#1903)
* Add ruleId to PSUseSingularNouns * Update UseSingularNouns.md * Update UseSingularNouns.md --------- Co-authored-by: Christoph Bergmeister <[email protected]>
1 parent 847b146 commit 45edb8d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Diff for: Rules/UseSingularNouns.cs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
8888
GetName(),
8989
DiagnosticSeverity.Warning,
9090
fileName,
91+
funcAst.Name,
9192
suggestedCorrections: new CorrectionExtent[] { GetCorrection(pluralizer, extent, funcAst.Name, noun) });
9293
}
9394
}

Diff for: Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ Write-Output "Adding some data"
8686
$diagnostics.SuggestedCorrections.Text | Should -BeExactly $Correction
8787
}
8888
}
89+
Context 'Suppression' {
90+
It 'Can be suppressed by RuleSuppressionId' {
91+
$scriptDef = @"
92+
function Get-Elements {
93+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('$nounViolationName', 'Get-Elements')]
94+
param()
95+
}
96+
"@
97+
$warnings = @(Invoke-ScriptAnalyzer -ScriptDefinition $scriptDef)
98+
$warnings.Count | Should -Be 0
99+
}
100+
}
89101
}
90102

91103
Describe "UseApprovedVerbs" {

Diff for: docs/Rules/UseSingularNouns.md

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ title: UseSingularNouns
1313

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

16+
Suppression allows to suppress just specific function names, for example
17+
18+
```
19+
function Get-Elements {
20+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', 'Get-Elements')]
21+
Param()
22+
}
23+
```
24+
1625
## How
1726

1827
Change plurals to singular.

0 commit comments

Comments
 (0)