From 699ffa473698d0e73491619549b6e474327d50a7 Mon Sep 17 00:00:00 2001 From: Ian Leitch Date: Fri, 23 Jul 2021 16:20:26 +0200 Subject: [PATCH] Only print report:exclude debug statement for files with unused declarations. (#382) --- .../Formatters/OutputDeclarationFilter.swift | 18 ++++++++++++++---- Sources/Shared/Configuration.swift | 8 ++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Sources/Frontend/Formatters/OutputDeclarationFilter.swift b/Sources/Frontend/Formatters/OutputDeclarationFilter.swift index 31219c9d7..818d97de2 100644 --- a/Sources/Frontend/Formatters/OutputDeclarationFilter.swift +++ b/Sources/Frontend/Formatters/OutputDeclarationFilter.swift @@ -1,4 +1,5 @@ import Foundation +import SystemPackage import Shared import PeripheryKit @@ -18,12 +19,21 @@ final class OutputDeclarationFilter: Injectable { func filter(_ declarations: [ScanResult]) -> [ScanResult] { let excludedSourceFiles = configuration.reportExcludeSourceFiles - excludedSourceFiles.forEach { - logger.debug("[report:exclude] \($0.string)") - } + var reportedExclusions: Set = [] return declarations.filter { - !excludedSourceFiles.contains($0.declaration.location.file.path) + let path = $0.declaration.location.file.path + + if excludedSourceFiles.contains(path) { + if !reportedExclusions.contains(path) { + self.logger.debug("[report:exclude] \(path)") + reportedExclusions.insert(path) + } + + return false + } + + return true } } } diff --git a/Sources/Shared/Configuration.swift b/Sources/Shared/Configuration.swift index e1cca7582..fd4cd9e03 100644 --- a/Sources/Shared/Configuration.swift +++ b/Sources/Shared/Configuration.swift @@ -277,13 +277,13 @@ public final class Configuration: Singleton { } } - public var indexExcludeSourceFiles: Set { + public lazy var indexExcludeSourceFiles: Set = { Set(indexExclude.flatMap { FilePath.glob($0) }) - } + }() - public var reportExcludeSourceFiles: Set { + public lazy var reportExcludeSourceFiles: Set = { Set(reportExclude.flatMap { FilePath.glob($0) }) - } + }() // MARK: - Private