-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
12 changed files
with
147 additions
and
21 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
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
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
18 changes: 1 addition & 17 deletions
18
Source/SwiftLintFramework/Extensions/Configuration+Cache.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
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,15 @@ | ||
#if canImport(CommonCrypto) | ||
import CommonCrypto | ||
|
||
extension String { | ||
internal func md5() -> String { | ||
let context = UnsafeMutablePointer<CC_MD5_CTX>.allocate(capacity: 1) | ||
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH)) | ||
CC_MD5_Init(context) | ||
CC_MD5_Update(context, self, CC_LONG(lengthOfBytes(using: .utf8))) | ||
CC_MD5_Final(&digest, context) | ||
context.deallocate() | ||
return digest.reduce(into: "") { $0.append(String(format: "%02x", $1)) } | ||
} | ||
} | ||
#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
49 changes: 49 additions & 0 deletions
49
Source/SwiftLintFramework/Reporters/CodeClimateReporter.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,49 @@ | ||
#if canImport(CryptoSwift) | ||
import CryptoSwift | ||
#endif | ||
import Foundation | ||
import SourceKittenFramework | ||
|
||
/// Reports violations as a JSON array in Code Climate format. | ||
public struct CodeClimateReporter: Reporter { | ||
// MARK: - Reporter Conformance | ||
|
||
public static let identifier = "codeclimate" | ||
public static let isRealtime = false | ||
|
||
public var description: String { | ||
return "Reports violations as a JSON array in Code Climate format." | ||
} | ||
|
||
public static func generateReport(_ violations: [StyleViolation]) -> String { | ||
return toJSON(violations.map(dictionary(for:))) | ||
.replacingOccurrences(of: "\\/", with: "/") | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private static func dictionary(for violation: StyleViolation) -> [String: Any] { | ||
return [ | ||
"check_name": violation.ruleName, | ||
"description": violation.reason, | ||
"engine_name": "SwiftLint", | ||
"fingerprint": generateFingerprint(violation), | ||
"location": [ | ||
"path": violation.location.file ?? NSNull() as Any, | ||
"lines": [ | ||
"begin": violation.location.line ?? NSNull() as Any, | ||
"end": violation.location.line ?? NSNull() as Any | ||
] | ||
], | ||
"severity": violation.severity == .error ? "MAJOR": "MINOR", | ||
"type": "issue" | ||
] | ||
} | ||
|
||
internal static func generateFingerprint(_ violation: StyleViolation) -> String { | ||
return [ | ||
"\(violation.location)", | ||
"\(violation.ruleIdentifier)" | ||
].joined().md5() | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
Tests/SwiftLintFrameworkTests/Resources/CannedCodeClimateReporterOutput.json
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,62 @@ | ||
[ | ||
{ | ||
"check_name" : "Line Length", | ||
"description" : "Violation Reason.", | ||
"engine_name" : "SwiftLint", | ||
"fingerprint" : "091a80392f7aebde05dab908162c3629", | ||
"location" : { | ||
"lines" : { | ||
"begin" : 1, | ||
"end" : 1 | ||
}, | ||
"path" : "filename" | ||
}, | ||
"severity" : "MINOR", | ||
"type" : "issue" | ||
}, | ||
{ | ||
"check_name" : "Line Length", | ||
"description" : "Violation Reason.", | ||
"engine_name" : "SwiftLint", | ||
"fingerprint" : "091a80392f7aebde05dab908162c3629", | ||
"location" : { | ||
"lines" : { | ||
"begin" : 1, | ||
"end" : 1 | ||
}, | ||
"path" : "filename" | ||
}, | ||
"severity" : "MAJOR", | ||
"type" : "issue" | ||
}, | ||
{ | ||
"check_name" : "Syntactic Sugar", | ||
"description" : "Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>.", | ||
"engine_name" : "SwiftLint", | ||
"fingerprint" : "624a4e77e797c9e6a42c82b6428e9c45", | ||
"location" : { | ||
"lines" : { | ||
"begin" : 1, | ||
"end" : 1 | ||
}, | ||
"path" : "filename" | ||
}, | ||
"severity" : "MAJOR", | ||
"type" : "issue" | ||
}, | ||
{ | ||
"check_name" : "Colon", | ||
"description" : "Colons should be next to the identifier when specifying a type and next to the key in dictionary literals.", | ||
"engine_name" : "SwiftLint", | ||
"fingerprint" : "1f9389145aa6d7e89a582fce5ae54659", | ||
"location" : { | ||
"lines" : { | ||
"begin" : null, | ||
"end" : null | ||
}, | ||
"path" : null | ||
}, | ||
"severity" : "MAJOR", | ||
"type" : "issue" | ||
} | ||
] |