Skip to content

Commit 5597ceb

Browse files
author
Quoc Truong
committed
Fix rule suppression does not work when the one of the value is null
1 parent 228b727 commit 5597ceb

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

Engine/Generic/RuleSuppression.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public string RuleName
5757
set
5858
{
5959
_ruleName = value;
60-
if ((ScriptAnalyzer.Instance.ScriptRules != null
60+
61+
if (!String.IsNullOrWhiteSpace(_ruleName)
62+
&& (ScriptAnalyzer.Instance.ScriptRules != null
6163
&& ScriptAnalyzer.Instance.ScriptRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0)
6264
&& (ScriptAnalyzer.Instance.TokenRules != null
6365
&& ScriptAnalyzer.Instance.TokenRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0)
@@ -236,6 +238,18 @@ public RuleSuppression(AttributeAst attrAst, int start, int end)
236238
}
237239
}
238240

241+
if (!String.IsNullOrWhiteSpace(Error))
242+
{
243+
// May be cases where the rulename is null because we didn't look at the rulename after
244+
// we found out there is an error
245+
RuleName = String.Empty;
246+
}
247+
else if (String.IsNullOrWhiteSpace(RuleName))
248+
{
249+
RuleName = String.Empty;
250+
Error = Strings.NullRuleNameError;
251+
}
252+
239253
// Must have scope and target together
240254
if (String.IsNullOrWhiteSpace(Scope) && !String.IsNullOrWhiteSpace(Target))
241255
{
@@ -329,7 +343,7 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
329343
}
330344
else
331345
{
332-
// this may add rule suppression that contains erro but we will check for this in the engine to throw out error
346+
// this may add rule suppression that contains error but we will check for this in the engine to throw out error
333347
result.Add(ruleSupp);
334348
}
335349
}

Engine/Helper.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,20 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
743743

744744
while (recordIndex < diagnostics.Count)
745745
{
746+
if (!String.IsNullOrWhiteSpace(ruleSuppression.Error))
747+
{
748+
ruleSuppressionIndex += 1;
749+
750+
if (ruleSuppressionIndex == ruleSuppressions.Count)
751+
{
752+
break;
753+
}
754+
755+
ruleSuppression = ruleSuppressions[ruleSuppressionIndex];
756+
757+
continue;
758+
}
759+
746760
// the record precedes the rule suppression so don't apply the suppression
747761
if (record.Extent.StartOffset < ruleSuppression.StartOffset)
748762
{

Engine/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Engine/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,7 @@
183183
<data name="WrongScopeArgumentSuppressionAttributeError" xml:space="preserve">
184184
<value>Scope can only be either function or class.</value>
185185
</data>
186+
<data name="NullRuleNameError" xml:space="preserve">
187+
<value>RuleName must not be null.</value>
188+
</data>
186189
</root>

0 commit comments

Comments
 (0)