forked from realm/SwiftLint
-
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
Showing
10 changed files
with
92 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
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
52 changes: 52 additions & 0 deletions
52
Source/SwiftLintFramework/Reporters/MarkdownReporter.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,52 @@ | ||
import Foundation | ||
|
||
private extension String { | ||
func escapedForMarkdown() -> String { | ||
let escapedString = replacingOccurrences(of: "\"", with: "\"\"") | ||
if escapedString.contains("|") || escapedString.contains("\n") { | ||
return "\"\(escapedString)\"" | ||
} | ||
return escapedString | ||
} | ||
} | ||
|
||
public struct MarkdownReporter: Reporter { | ||
public static let identifier = "markdown" | ||
public static let isRealtime = false | ||
|
||
public var description: String { | ||
return "Reports violations as markdown formated (with tables)" | ||
} | ||
|
||
public static func generateReport(_ violations: [StyleViolation]) -> String { | ||
let keys = [ | ||
"file", | ||
"line", | ||
"severity", | ||
"reason", | ||
"rule_id" | ||
].joined(separator: " | ") | ||
|
||
let rows = [keys, "--- | --- | --- | --- | ---"] + violations.map(markdownRow(for:)) | ||
return rows.joined(separator: "\n") | ||
} | ||
|
||
fileprivate static func markdownRow(for violation: StyleViolation) -> String { | ||
return [ | ||
violation.location.file?.escapedForMarkdown() ?? "", | ||
violation.location.line?.description ?? "", | ||
severity(for: violation.severity), | ||
violation.ruleDescription.name.escapedForMarkdown() + ": " + violation.reason.escapedForMarkdown(), | ||
violation.ruleDescription.identifier | ||
].joined(separator: " | ") | ||
} | ||
|
||
fileprivate static func severity(for severity: ViolationSeverity) -> String { | ||
switch severity { | ||
case .error: | ||
return ":stop\\_sign:" | ||
case .warning: | ||
return ":warning:" | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
SwiftLint.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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
6 changes: 6 additions & 0 deletions
6
Tests/SwiftLintFrameworkTests/Resources/CannedMarkdownReporterOutput.md
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,6 @@ | ||
file | line | severity | reason | rule_id | ||
--- | --- | --- | --- | --- | ||
filename | 1 | :warning: | Line Length: Violation Reason. | line_length | ||
filename | 1 | :stop\_sign: | Line Length: Violation Reason. | line_length | ||
filename | 1 | :stop\_sign: | Syntactic Sugar: Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>. | syntactic_sugar | ||
| | :stop\_sign: | Colon: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals. | colon |