Skip to content

Commit d6d35b6

Browse files
author
Quoc Truong
committed
Throw error if target cannot be found for rulesuppression
1 parent b8fab37 commit d6d35b6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Engine/Generic/RuleSuppression.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,14 @@ public static List<RuleSuppression> GetSuppressions(IEnumerable<AttributeAst> at
334334

335335
if (targetAsts != null)
336336
{
337+
if (targetAsts.Count() == 0)
338+
{
339+
ruleSupp.Error = String.Format(CultureInfo.CurrentCulture, Strings.RuleSuppressionErrorFormat, ruleSupp.StartOffset,
340+
System.IO.Path.GetFileName(scopeAst.Extent.File), String.Format(Strings.TargetCannotBeFoundError, ruleSupp.Target, ruleSupp.Scope));
341+
result.Add(ruleSupp);
342+
continue;
343+
}
344+
337345
foreach (Ast targetAst in targetAsts)
338346
{
339347
result.Add(new RuleSuppression(ruleSupp.RuleName, ruleSupp.RuleSuppressionID, targetAst.Extent.StartOffset, targetAst.Extent.EndOffset));

Engine/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
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
@@ -186,4 +186,7 @@
186186
<data name="NullRuleNameError" xml:space="preserve">
187187
<value>RuleName must not be null.</value>
188188
</data>
189+
<data name="TargetCannotBeFoundError" xml:space="preserve">
190+
<value>Cannot find any Targets {0} that match the Scope {1} to apply the SuppressMessageAttribute.</value>
191+
</data>
189192
</root>

0 commit comments

Comments
 (0)