Skip to content
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