Azure / Azure/template-analyzer
Deduplication of reported lines in analysis results
- Dominant language
- C#
- Stars
- 143
- Forks
- 47
- PR merge metrics
- No merged PRs in 30d
Description
### Please describe the feature or suggestion.
Sometimes the same line in a template is reported for a failure of the same rule. This can happen for many valid reasons:
- Expected properties are absent, and the line number of the closest parent object declaration is the same for the missing properties
- A property is allowed to meet one of many conditions, but it doesn't meet any of them, resulting in a failure of all conditions
- A resource is copied, each copy fails a rule, and the line number in the original template would be the same for all copies
In many cases these failures would be distinguished from each other by better messages in the results. However, while that ability is missing now, they appear to simply be duplicates and result in noise in the reports.
This can be solved broadly by implementing [IEquatable](https://docs.microsoft.com/en-us/dotnet/api/system.iequatable-1?view=net-5.0) in classes implementing `IResult`, implementing both `Equals` and `GetHashCode` and comparing the line numbers across `IResult`s. Reports could then do something simple like the following:
``` cs
IEnumerable distinctFailures = GetFailedResults(evaluation).Distinct();
```
... which would filter out the apparent duplicates. In the future when more detailed messaging is implemented to show information specific to a particular line, this solution would continue to "just work" in the reports by simply updating the `IResult` classes to compare the messages when determining equality. For example, this would result in the same line being shown in multiple *location* properties of SARIF, but with different messages, so it's clear there is more than one failure at that line.
(A little more effort would be needed to address duplicate lines across distinct results in SARIF, for example in the resource copy scenario, since they would be in separate `Evaluation`s, but this scenario is still greatly simplified by the suggested change.)
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.