Skip to content

Commit

Permalink
Fix #123. (#125)
Browse files Browse the repository at this point in the history
* Fix #123.

* Now properly skip suffix checking if there's no prefix to check against.

* Clarify variable names
  • Loading branch information
gfs authored Feb 28, 2020
1 parent 65575ce commit f42bc84
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions DevSkim-DotNet/Microsoft.DevSkim/TextContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public Location GetLocation(int index)
}
}
}

return result;
}

Expand Down Expand Up @@ -232,16 +231,19 @@ private bool IsBetween(string text, int index, string prefix, string suffix, str
int lastInline = preText.Substring(0, lastPrefix).LastIndexOf(inline, StringComparison.InvariantCulture);

// For example in C#, If this /* is actually commented out by a //
if (lastInline < lastPrefix && !preText.Substring(lastInline,lastPrefix - lastInline).Contains('\n'))
if (lastInline >= 0 && lastInline < lastPrefix && !preText.Substring(lastInline,lastPrefix - lastInline).Contains('\n'))
{
lastPrefix = 0;
lastPrefix = -1;
}
}
if (lastPrefix >= 0)
{
preText = text.Substring(lastPrefix);
int lastSuffix = preText.IndexOf(suffix, StringComparison.Ordinal);
if (lastSuffix + lastPrefix > index)
var commentedText = text.Substring(lastPrefix);
int nextSuffix = commentedText.IndexOf(suffix, StringComparison.Ordinal);

// If the index is in between the last prefix before the index and the next suffix after that prefix
// Then it is commented out
if (lastPrefix + nextSuffix > index)
result = true;
}

Expand Down

0 comments on commit f42bc84

Please sign in to comment.