-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
121 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
Sources/PeripheryKit/Formatters/OutputDeclarationFilter.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
/// A baseline set of declarations that are excluded from results. | ||
public enum Baseline: Codable { | ||
case v1(usrs: Set<String>) | ||
|
||
var usrs: Set<String> { | ||
switch self { | ||
case .v1(let usrs): | ||
return usrs | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
Sources/PeripheryKit/Results/OutputDeclarationFilter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Foundation | ||
import SystemPackage | ||
import Shared | ||
import FilenameMatcher | ||
|
||
public final class OutputDeclarationFilter { | ||
private let configuration: Configuration | ||
private let logger: Logger | ||
private let contextualLogger: ContextualLogger | ||
|
||
public required init(configuration: Configuration = .shared, logger: Logger = .init()) { | ||
self.configuration = configuration | ||
self.logger = logger | ||
self.contextualLogger = logger.contextualized(with: "report:filter") | ||
} | ||
|
||
public func filter(_ declarations: [ScanResult]) throws -> [ScanResult] { | ||
var declarations = declarations | ||
|
||
if let baselinePath = configuration.baseline { | ||
let data = try Data(contentsOf: baselinePath.url) | ||
let baseline = try JSONDecoder().decode(Baseline.self, from: data) | ||
var didFilterDeclaration = false | ||
declarations = declarations.filter { | ||
let isDisjoint = $0.usrs.isDisjoint(with: baseline.usrs) | ||
if !isDisjoint { | ||
didFilterDeclaration = true | ||
} | ||
return isDisjoint | ||
} | ||
|
||
if !didFilterDeclaration { | ||
logger.warn("No results were filtered by the baseline.") | ||
} | ||
} | ||
|
||
if configuration.reportInclude.isEmpty && configuration.reportExclude.isEmpty { | ||
return declarations.sorted { $0.declaration < $1.declaration } | ||
} | ||
|
||
return declarations | ||
.filter { [contextualLogger] in | ||
let path = $0.declaration.location.file.path | ||
|
||
if configuration.reportIncludeMatchers.isEmpty { | ||
if configuration.reportExcludeMatchers.anyMatch(filename: path.string) { | ||
contextualLogger.debug("Excluding \(path.string)") | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
if configuration.reportIncludeMatchers.anyMatch(filename: path.string) { | ||
contextualLogger.debug("Including \(path.string)") | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
.sorted { $0.declaration < $1.declaration } | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters