-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Allow users to select a custom reporter that prints JSON instead of `sed` commands - Opt-in by adding `"reporter": "json"` to the configuration file
- Loading branch information
1 parent
9c89147
commit a606a4e
Showing
7 changed files
with
82 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Foundation | ||
|
||
struct JSONReporter: UnusedImportReporter { | ||
func didFind(sourceFilesWithUnusedImports: [SourceFileWithUnusedImports]) { | ||
let jsonEncoder = JSONEncoder() | ||
let removableImportsJSONData = try! jsonEncoder.encode(sourceFilesWithUnusedImports) | ||
let removableImportsJSONString = String(data: removableImportsJSONData, encoding: String.Encoding.utf8)! | ||
|
||
print(removableImportsJSONString) | ||
} | ||
} |
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,10 @@ | ||
import Foundation | ||
|
||
struct SedCommandReporter: UnusedImportReporter { | ||
func didFind(sourceFilesWithUnusedImports: [SourceFileWithUnusedImports]) { | ||
for sourceFile in sourceFilesWithUnusedImports.sorted() { | ||
let sedCmd = sourceFile.unusedImportStatements.map { unusedImport in "\(unusedImport.lineNumber)d" }.joined(separator: ";") | ||
print("/usr/bin/sed -i \"\" '\(sedCmd)' '\(sourceFile.path)'") | ||
} | ||
} | ||
} |
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,3 @@ | ||
protocol UnusedImportReporter { | ||
func didFind(sourceFilesWithUnusedImports: [SourceFileWithUnusedImports]) | ||
} |
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,8 @@ | ||
struct SourceFileWithUnusedImports: Codable, Comparable { | ||
let path: String | ||
let unusedImportStatements: [UnusedImportStatement] | ||
|
||
static func <(lhs: SourceFileWithUnusedImports, rhs: SourceFileWithUnusedImports) -> Bool { | ||
return lhs.path < rhs.path | ||
} | ||
} |
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,8 @@ | ||
struct UnusedImportStatement: Codable, Comparable { | ||
let moduleName: String | ||
let lineNumber: Int | ||
|
||
static func <(lhs: UnusedImportStatement, rhs: UnusedImportStatement) -> Bool { | ||
return lhs.moduleName < rhs.moduleName | ||
} | ||
} |
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