Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow suppression of PSUseSingularNouns for specific function #1903

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rules/UseSingularNouns.cs
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
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
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