Skip to content

Commit 5f73a2c

Browse files
committed
Updates based on CR comments; Updated extent for Singlular Noun Rule also
1 parent 86469ac commit 5f73a2c

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Engine/Helper.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,21 +646,22 @@ public bool SkipBlock(string keyword, Ast namedBlockAst)
646646
}
647647

648648
// Obtain script extent for the function - just around the function name
649-
public IScriptExtent GetScriptExtentForFunctionName(string functionName)
649+
public IScriptExtent GetScriptExtentForFunctionName(FunctionDefinitionAst functionDefinitionAst)
650650
{
651-
if (String.IsNullOrEmpty(functionName))
651+
if (null == functionDefinitionAst)
652652
{
653653
return null;
654654
}
655655

656656
// Obtain the index where the function name is in Tokens
657657
int funcTokenIndex = Tokens.Select((s, index) => new { s, index })
658-
.Where(x => x.s.Text == functionName)
658+
.Where(x => x.s.Extent.StartOffset == functionDefinitionAst.Extent.StartOffset)
659659
.Select(x => x.index).FirstOrDefault();
660660

661-
if (funcTokenIndex > 0 && funcTokenIndex <= Helper.Instance.Tokens.Count())
661+
if (funcTokenIndex > 0 && funcTokenIndex < Helper.Instance.Tokens.Count())
662662
{
663-
return Tokens[funcTokenIndex].Extent;
663+
// return the extent of the next token - this is the extent for the function name
664+
return Tokens[++funcTokenIndex].Extent;
664665
}
665666

666667
return null;

Rules/UseApprovedVerbs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
6363

6464
if (!approvedVerbs.Contains(verb, StringComparer.OrdinalIgnoreCase))
6565
{
66-
IScriptExtent extent = Helper.Instance.GetScriptExtentForFunctionName(funcName);
66+
IScriptExtent extent = Helper.Instance.GetScriptExtentForFunctionName(funcAst);
6767

6868
if (null == extent)
6969
{

Rules/UseSingularNouns.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,15 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName) {
5656

5757
if (!ps.IsSingular(noun) && ps.IsPlural(noun))
5858
{
59+
IScriptExtent extent = Helper.Instance.GetScriptExtentForFunctionName(funcAst);
60+
61+
if (null == extent)
62+
{
63+
extent = funcAst.Extent;
64+
}
65+
5966
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.UseSingularNounsError, funcAst.Name),
60-
funcAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
67+
extent, GetName(), DiagnosticSeverity.Warning, fileName);
6168
}
6269
}
6370
}

0 commit comments

Comments
 (0)