mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Merge pull request #15325 from RasmusWL/c#-filter-order
C#: Respect order of `LGTM_INDEX_FILTERS` in buildless extraction
This commit is contained in:
@@ -74,16 +74,18 @@ namespace Semmle.Extraction.CSharp.DependencyFetching
|
||||
includeByDefault)
|
||||
});
|
||||
|
||||
// Move included pathfilters to the front of the list:
|
||||
pathFilters.Sort((pf1, pf2) => -1 * pf1.Include.CompareTo(pf2.Include));
|
||||
return unfilteredResult.Where(f =>
|
||||
{
|
||||
var include = f.FileInclusion.Include;
|
||||
foreach (var pathFilter in pathFilters)
|
||||
// LGTM_INDEX_FILTERS is a prioritized list, where later filters take
|
||||
// priority over earlier ones.
|
||||
for (int i = pathFilters.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var pathFilter = pathFilters[i];
|
||||
if (pathFilter.Regex.IsMatch(f.FileInclusion.Path))
|
||||
{
|
||||
include = pathFilter.Include;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ namespace Semmle.Extraction.Tests
|
||||
{
|
||||
(var testSubject, var progressMonitor, var files) = TestSetup();
|
||||
|
||||
// NOTE: the ordering DOES matter, later filters takes priority, so the exclude will end up not mattering at all.
|
||||
Environment.SetEnvironmentVariable("LGTM_INDEX_FILTERS", """
|
||||
exclude:c/x/z
|
||||
include:c/x
|
||||
@@ -174,7 +175,8 @@ namespace Semmle.Extraction.Tests
|
||||
|
||||
var expected = GetExpected(
|
||||
[
|
||||
"/a/b/c/x/y/i.cs"
|
||||
"/a/b/c/x/y/i.cs",
|
||||
"/a/b/c/x/z/i.cs"
|
||||
]);
|
||||
|
||||
AssertFileInfoEquivalence(expected, filtered);
|
||||
|
||||
Reference in New Issue
Block a user