Skip to content

Commit dc89366

Browse files
author
Kapil Borle
committed
Add whitelist to UseSingularNoun rule
1 parent 635008e commit dc89366

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Rules/UseSingularNouns.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2727
/// </summary>
2828
[Export(typeof(IScriptRule))]
2929
public class CmdletSingularNoun : IScriptRule {
30+
31+
private readonly string[] nounWhiteList =
32+
{
33+
"Data"
34+
};
35+
3036
/// <summary>
3137
/// Checks that all defined cmdlet use singular noun
3238
/// </summary>
@@ -57,12 +63,14 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
5763
if (!ps.IsSingular(noun) && ps.IsPlural(noun))
5864
{
5965
IScriptExtent extent = Helper.Instance.GetScriptExtentForFunctionName(funcAst);
60-
66+
if (nounWhiteList.Contains(noun, StringComparer.OrdinalIgnoreCase))
67+
{
68+
continue;
69+
}
6170
if (null == extent)
6271
{
6372
extent = funcAst.Extent;
6473
}
65-
6674
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.UseSingularNounsError, funcAst.Name),
6775
extent, GetName(), DiagnosticSeverity.Warning, fileName);
6876
}

Tests/Rules/UseSingularNounsReservedVerbs.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ Describe "UseSingularNouns" {
2424
It "has the correct extent" {
2525
$nounViolations[0].Extent.Text | Should be "Verb-Files"
2626
}
27+
28+
It "excludes items from noun whitelist" {
29+
$nounViolationScript = @'
30+
Function Add-SomeData
31+
{
32+
Write-Output "Adding some data"
33+
}
34+
'@
35+
Invoke-ScriptAnalyzer -ScriptDefinition $nounViolationScript `
36+
-IncludeRule "PSUseSingularNouns" `
37+
-OutVariable violations
38+
$violations.Count | Should Be 0
39+
}
2740
}
2841

2942
Context "When there are no violations" {

0 commit comments

Comments
 (0)