-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 6bab7c5
Showing
10 changed files
with
256 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj |
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,79 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "danger-swift", | ||
"repositoryURL": "https://github.com/danger/danger-swift.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "dd0d6457adf72eedeb10076e1887d49431fd56a6", | ||
"version": "0.4.0" | ||
} | ||
}, | ||
{ | ||
"package": "Files", | ||
"repositoryURL": "https://github.com/JohnSundell/Files.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "06f95bd1bf4f8d5f50bc6bb30b808c253acd4c88", | ||
"version": "2.2.1" | ||
} | ||
}, | ||
{ | ||
"package": "Marathon", | ||
"repositoryURL": "https://github.com/JohnSundell/Marathon.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "959e82b044f7dbb2680c6e7cdaa80d70e9dfa4ca", | ||
"version": "3.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "Releases", | ||
"repositoryURL": "https://github.com/JohnSundell/Releases.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "e74f0895855b56147cb96f2d45aba3ec37da64fb", | ||
"version": "3.0.0" | ||
} | ||
}, | ||
{ | ||
"package": "Require", | ||
"repositoryURL": "https://github.com/JohnSundell/Require.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "7cfbd0d8a2dede0e01f6f0d8ab2c7acef1df112e", | ||
"version": "2.0.1" | ||
} | ||
}, | ||
{ | ||
"package": "ShellOut", | ||
"repositoryURL": "https://github.com/JohnSundell/ShellOut.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "f1c253a34a40df4bfd268b09fdb101b059f6d52d", | ||
"version": "2.1.0" | ||
} | ||
}, | ||
{ | ||
"package": "Unbox", | ||
"repositoryURL": "https://github.com/JohnSundell/Unbox.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "17ad6aa1cc2f1efa27a0bbbdb66f79796708aa95", | ||
"version": "2.5.0" | ||
} | ||
}, | ||
{ | ||
"package": "Wrap", | ||
"repositoryURL": "https://github.com/JohnSundell/Wrap.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "8085c925060b84a1fc0caef444c130da2c8154c3", | ||
"version": "3.0.1" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
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,23 @@ | ||
// swift-tools-version:4.0 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "DangerIBLinter", | ||
products: [ | ||
.library( | ||
name: "DangerIBLinter", | ||
targets: ["DangerIBLinter"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/danger/danger-swift.git", from: "0.3.0") | ||
], | ||
targets: [ | ||
.target( | ||
name: "DangerIBLinter", | ||
dependencies: ["Danger"]), | ||
.testTarget( | ||
name: "DangerIBLinterTests", | ||
dependencies: ["DangerIBLinter"]), | ||
] | ||
) |
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 @@ | ||
# DangerIBLinter | ||
|
||
A description of this package. |
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,42 @@ | ||
import Foundation | ||
import Danger | ||
|
||
public struct IBLinter { | ||
static let danger = Danger() | ||
} | ||
|
||
extension IBLinter { | ||
|
||
public static func lint(inline: Bool = true) throws { | ||
let arguments = [ | ||
"--reporter", "json" | ||
] | ||
let shellExecutor = ShellExecutor() | ||
let output = shellExecutor.execute("iblinter", arguments: arguments) | ||
let pwd = shellExecutor.execute("pwd") | ||
let decoder = JSONDecoder() | ||
let files = danger.git.createdFiles + danger.git.modifiedFiles | ||
let violations = try decoder.decode([Violation<AbsolutePath>].self, from: output.data(using: .utf8)!) | ||
let filteredViolations = violations.map { $0.convert(gitRoot: pwd) } | ||
.filter { | ||
files.contains($0.relativePath) | ||
} | ||
|
||
if inline { | ||
filteredViolations | ||
.forEach { | ||
fail(message: $0.message, file: $0.relativePath, line: 0) | ||
} | ||
} else { | ||
let header = """ | ||
### IBLinter found issues | ||
| Severity | File | Reason | | ||
| -------- | ---- | ------ |\n | ||
""" | ||
let markdownMessage = filteredViolations.reduce(header) { | ||
$0 + $1.toMarkdown() + "\n" | ||
} | ||
markdown(markdownMessage) | ||
} | ||
} | ||
} |
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,29 @@ | ||
// | ||
// ShellExecutor.swift | ||
// DangerIBLinter | ||
// | ||
// Created by SaitoYuta on 2018/05/26. | ||
// | ||
|
||
import Foundation | ||
|
||
internal class ShellExecutor { | ||
func execute(_ command: String, arguments: [String] = []) -> String { | ||
let script = "\(command) \(arguments.joined(separator: " "))" | ||
print("Executing \(script)") | ||
|
||
var env = ProcessInfo.processInfo.environment | ||
let task = Process() | ||
task.launchPath = env["SHELL"] | ||
task.arguments = ["-l", "-c", script] | ||
task.currentDirectoryPath = FileManager.default.currentDirectoryPath | ||
|
||
let pipe = Pipe() | ||
task.standardOutput = pipe | ||
task.launch() | ||
task.waitUntilExit() | ||
|
||
let data = pipe.fileHandleForReading.readDataToEndOfFile() | ||
return String(data: data, encoding: String.Encoding.utf8)! | ||
} | ||
} |
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,44 @@ | ||
// | ||
// Violation.swift | ||
// DangerIBLinter | ||
// | ||
// Created by SaitoYuta on 2018/05/26. | ||
// | ||
|
||
import Foundation | ||
|
||
enum AbsolutePath {} | ||
enum RelativePath {} | ||
|
||
enum Level: String, Codable { | ||
case warning | ||
case error | ||
} | ||
|
||
struct Violation<PathType>: Codable { | ||
let message: String | ||
let level: Level | ||
private let path: String | ||
} | ||
|
||
extension Violation where PathType == AbsolutePath { | ||
var absolutePath: String { return path } | ||
|
||
func convert(gitRoot: String) -> Violation<RelativePath> { | ||
guard let range = path.range(of: gitRoot)else { | ||
fatalError() | ||
} | ||
var relativePath = path | ||
relativePath.removeSubrange(range) | ||
return .init(message: message, level: level, path: relativePath) | ||
} | ||
} | ||
|
||
extension Violation where PathType == RelativePath { | ||
var relativePath: String { return path } | ||
|
||
func toMarkdown() -> String { | ||
let formattedFile = path.split(separator: "/").last! + ":0" | ||
return "\(level.rawValue) | \(formattedFile) | \(message) |" | ||
} | ||
} |
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,16 @@ | ||
import XCTest | ||
@testable import DangerIBLinter | ||
|
||
final class DangerIBLinterTests: XCTestCase { | ||
func testExample() { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct | ||
// results. | ||
XCTAssertEqual(DangerIBLinter().text, "Hello, World!") | ||
} | ||
|
||
|
||
static var allTests = [ | ||
("testExample", testExample), | ||
] | ||
} |
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,9 @@ | ||
import XCTest | ||
|
||
#if !os(macOS) | ||
public func allTests() -> [XCTestCaseEntry] { | ||
return [ | ||
testCase(DangerIBLinterTests.allTests), | ||
] | ||
} | ||
#endif |
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,7 @@ | ||
import XCTest | ||
|
||
import DangerIBLinterTests | ||
|
||
var tests = [XCTestCaseEntry]() | ||
tests += DangerIBLinterTests.allTests() | ||
XCTMain(tests) |