Skip to content

Commit ee70de8

Browse files
committed
Fix code review findings
1 parent 728229e commit ee70de8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FilePathFilter.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,22 @@ public IEnumerable<FileInfo> Filter(IEnumerable<FileInfo> files)
6464
pathFilters.Add(new PathFilter(new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline), include));
6565
}
6666

67+
var includeByDefault = pathFilters.All(f => !f.Include);
6768
var unfilteredResult = files.Select(f =>
6869
new
6970
{
7071
FileInfo = f,
7172
FileInclusion = new FileInclusion(
7273
FileUtils.ConvertToUnix(f.FullName.ToLowerInvariant()).Replace(rootFolder, string.Empty).TrimStart('/'),
73-
pathFilters.All(f => !f.Include))
74+
includeByDefault)
7475
});
7576

77+
// Move included pathfilters to the front of the list:
78+
pathFilters.Sort((pf1, pf2) => -1 * pf1.Include.CompareTo(pf2.Include));
7679
return unfilteredResult.Where(f =>
7780
{
7881
var include = f.FileInclusion.Include;
79-
foreach (var pathFilter in pathFilters.OrderBy(pf => pf.Include ? 0 : 1))
82+
foreach (var pathFilter in pathFilters)
8083
{
8184
if (pathFilter.Regex.IsMatch(f.FileInclusion.Path))
8285
{

0 commit comments

Comments
 (0)