Skip to content

Commit d867fbe

Browse files
committed
Merge pull request #432 from PowerShell/SingularNounRuleBugFixBranch
Improved heuristics for Singular noun rule
2 parents 86a5af4 + b3aa9a6 commit d867fbe

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Engine/PSScriptAnalyzer.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
1111
RootModule = 'PSScriptAnalyzer.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.3.0'
14+
ModuleVersion = '1.3.1'
1515

1616
# ID used to uniquely identify this module
1717
GUID = '324fc715-36bf-4aee-8e58-72e9b4a08ad9'

Rules/UseSingularNouns.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
1818
using System.ComponentModel.Composition;
1919
using System.Globalization;
20+
using System.Text.RegularExpressions;
2021

2122
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
2223
{
@@ -46,6 +47,11 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
4647
{
4748
funcNamePieces = funcAst.Name.Split(funcSeperator);
4849
String noun = funcNamePieces[1];
50+
51+
// Convert the noun part of the function into a series of space delimited words
52+
// This helps the PluralizationService to provide an accurate determination about the plurality of the string
53+
noun = SplitCamelCaseString(noun);
54+
4955
var ps = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(CultureInfo.GetCultureInfo("en-us"));
5056

5157
if (!ps.IsSingular(noun) && ps.IsPlural(noun))
@@ -108,6 +114,19 @@ public string GetSourceName()
108114
{
109115
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
110116
}
117+
118+
/// <summary>
119+
/// SplitCamelCaseString: Splits a Camel Case'd string into individual words with space delimited
120+
/// </summary>
121+
private string SplitCamelCaseString(string input)
122+
{
123+
if (String.IsNullOrEmpty(input))
124+
{
125+
return String.Empty;
126+
}
127+
128+
return Regex.Replace(input, "([A-Z])", " $1", RegexOptions.Compiled).Trim();
129+
}
111130
}
112131

113132
}

Tests/Rules/GoodCmdlet.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,19 @@ function Get-Reserved*
260260
End
261261
{
262262
}
263+
}
264+
265+
<#
266+
.Synopsis
267+
function that has a noun that is singular
268+
.DESCRIPTION
269+
270+
.EXAMPLE
271+
272+
.EXAMPLE
273+
274+
#>
275+
function Get-MyWidgetStatus
276+
{
277+
263278
}

0 commit comments

Comments
 (0)