diff --git a/Rules/UseSingularNouns.cs b/Rules/UseSingularNouns.cs index de9264d35..218537459 100644 --- a/Rules/UseSingularNouns.cs +++ b/Rules/UseSingularNouns.cs @@ -88,6 +88,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName) GetName(), DiagnosticSeverity.Warning, fileName, + funcAst.Name, suggestedCorrections: new CorrectionExtent[] { GetCorrection(pluralizer, extent, funcAst.Name, noun) }); } } diff --git a/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 b/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 index 534e6df4d..db1af36ce 100644 --- a/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 +++ b/Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1 @@ -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" { diff --git a/docs/Rules/UseSingularNouns.md b/docs/Rules/UseSingularNouns.md index 9dc24a017..b618586a5 100644 --- a/docs/Rules/UseSingularNouns.md +++ b/docs/Rules/UseSingularNouns.md @@ -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.