mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
Merge branch 'master' into relative-path-html-report
# Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
* `operator_usage_whitespace` rule is now correctable.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
|
||||
* `implicit_getter` and `mark` rule performance improvements.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
|
||||
* HTML reports now display a relative path to files.
|
||||
[Jamie Edge](https://github.com/JamieEdge)
|
||||
|
||||
@@ -31,6 +34,13 @@
|
||||
* Grammar checks.
|
||||
[Michael Helmbrecht](https://github.com/mrh-is)
|
||||
|
||||
* Fix the validity and styling of the HTML reporter.
|
||||
[Jamie Edge](https://github.com/JamieEdge)
|
||||
|
||||
* Fix false positive in `empty_parentheses_with_trailing_closure` rule.
|
||||
[Marcelo Fabri](https://github.com/marcelofabri)
|
||||
[#1021](https://github.com/realm/SwiftLint/issues/1021)
|
||||
|
||||
## 0.14.0: Super Awesome Retractable Drying Rack
|
||||
|
||||
##### Breaking
|
||||
|
||||
@@ -219,7 +219,7 @@ variable_name:
|
||||
- id
|
||||
- URL
|
||||
- GlobalAPIKey
|
||||
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, emoji)
|
||||
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
|
||||
```
|
||||
|
||||
#### Defining Custom Rules
|
||||
|
||||
@@ -45,35 +45,60 @@ public struct HTMLReporter: Reporter {
|
||||
"<!doctype html>\n",
|
||||
"<html>\n",
|
||||
"\t<head>\n",
|
||||
"\t\t<title>Swiftlint Report</title>\n",
|
||||
"\t\t<style type='text/css'>\n",
|
||||
"\t\t<meta charset=\"utf-8\" />\n",
|
||||
"\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n",
|
||||
"\t\t\n",
|
||||
"\t\t<style type=\"text/css\">\n",
|
||||
"\t\t\tbody {\n",
|
||||
"\t\t\t\tfont-family: Arial, Helvetica, sans-serif;\n",
|
||||
"\t\t\t\tfont-size: 0.9rem;\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\ttable {\n",
|
||||
"\t\t\t\tborder: 1px solid gray;\n",
|
||||
"\t\t\t\tborder-collapse: collapse;\n",
|
||||
"\t\t\t\t-moz-box-shadow: 3px 3px 4px #AAA;\n",
|
||||
"\t\t\t\t-webkit-box-shadow: 3px 3px 4px #AAA;\n",
|
||||
"\t\t\t\tbox-shadow: 3px 3px 4px #AAA;\n",
|
||||
"\t\t\t\tvertical-align: top;\n",
|
||||
"\t\t\t\theight: 64px;\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\ttd, th {\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\ttd, th {\n",
|
||||
"\t\t\t\tborder: 1px solid #D3D3D3;\n",
|
||||
"\t\t\t\tpadding: 5px 10px 5px 10px;\n",
|
||||
"\t\t}\n",
|
||||
"\t\tth {\n",
|
||||
"\t\t\tborder-bottom: 1px solid gray;\n",
|
||||
"\t\t\tbackground-color: rgba(41,52,92,0.313);\n",
|
||||
"\t\t}\n",
|
||||
"\t\t.error, .warning {\n",
|
||||
"\t\t\tbackground-color: #f0f099;\n",
|
||||
"\t\t} .error{ color: #ff0000;}\n",
|
||||
"\t\t.warning { color: #b36b00;\n",
|
||||
"\t\t}\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\tth {\n",
|
||||
"\t\t\t\tborder-bottom: 1px solid gray;\n",
|
||||
"\t\t\t\tbackground-color: rgba(41,52,92,0.313);\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\t.error, .warning {\n",
|
||||
"\t\t\t\ttext-align: center;\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\t.error {\n",
|
||||
"\t\t\t\tbackground-color: #FF9D92;\n",
|
||||
"\t\t\t\tcolor: #7F0800;\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t\t\n",
|
||||
"\t\t\t.warning {\n",
|
||||
"\t\t\t\tbackground-color: #FFF59E;\n",
|
||||
"\t\t\t\tcolor: #7F7000;\n",
|
||||
"\t\t\t}\n",
|
||||
"\t\t</style>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<title>SwiftLint Report</title>\n",
|
||||
"\t</head>\n",
|
||||
"\t<body>\n",
|
||||
"\t\t<h1>Swiftlint Report</h1>\n",
|
||||
"\t\t<h1>SwiftLint Report</h1>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<hr />\n",
|
||||
"\t\t\n",
|
||||
"\t\t<h2>Violations</h2>\n",
|
||||
"\t\t<table border=\"1\" style=\"vertical-align: top; height: 64px;\">\n",
|
||||
"\t\t\n",
|
||||
"\t\t<table>\n",
|
||||
"\t\t\t<thead>\n",
|
||||
"\t\t\t\t<tr>\n",
|
||||
"\t\t\t\t\t<th style=\"width: 60pt;\">\n",
|
||||
@@ -95,9 +120,12 @@ public struct HTMLReporter: Reporter {
|
||||
"\t\t\t</thead>\n",
|
||||
"\t\t\t<tbody>\n", rows, "\t\t\t</tbody>\n",
|
||||
"\t\t</table>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<br/>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<h2>Summary</h2>\n",
|
||||
"\t\t<table border=\"1\" style=\"vertical-align: top; height: 64px;\">\n",
|
||||
"\t\t\n",
|
||||
"\t\t<table>\n",
|
||||
"\t\t\t<tbody>\n",
|
||||
"\t\t\t\t<tr>\n",
|
||||
"\t\t\t\t\t<td>Total files with violations</td>\n",
|
||||
@@ -113,10 +141,14 @@ public struct HTMLReporter: Reporter {
|
||||
"\t\t\t\t</tr>\n",
|
||||
"\t\t\t</tbody>\n",
|
||||
"\t\t</table>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<hr />\n",
|
||||
"\t\t<p>Created with <a href=\"https://github.com/realm/SwiftLint\">\n",
|
||||
"\t\t\t<b>Swiftlint</b>\n",
|
||||
"\t\t</a> ", swiftlintVersion, " on: ", dateString, "</p>\n",
|
||||
"\t\t\n",
|
||||
"\t\t<p>\n",
|
||||
"\t\t\tCreated with\n",
|
||||
"\t\t\t<a href=\"https://github.com/realm/SwiftLint\"><b>SwiftLint</b></a>\n",
|
||||
"\t\t\t", swiftlintVersion, " on ", dateString, "\n",
|
||||
"\t\t</p>\n",
|
||||
"\t</body>\n",
|
||||
"</html>"
|
||||
].joined()
|
||||
@@ -130,10 +162,10 @@ public struct HTMLReporter: Reporter {
|
||||
let character: Int = location.character ?? 0
|
||||
return [
|
||||
"\t\t\t\t<tr>\n",
|
||||
"\t\t\t\t\t<td align=\"right\">\(index)</td>\n",
|
||||
"\t\t\t\t\t<td style=\"text-align: right;\">\(index)</td>\n",
|
||||
"\t\t\t\t\t<td>", file, "</td>\n",
|
||||
"\t\t\t\t\t<td align=\"center\">\(line):\(character)</td>\n",
|
||||
"\t\t\t\t\t<td class=\'", severity.lowercased(), "\'>", severity, "</td>\n",
|
||||
"\t\t\t\t\t<td style=\"text-align: center;\">\(line):\(character)</td>\n",
|
||||
"\t\t\t\t\t<td class=\"", severity.lowercased(), "\">", severity, "</td>\n",
|
||||
"\t\t\t\t\t<td>\(violation.reason.escapedForXML())</td>\n",
|
||||
"\t\t\t\t</tr>\n"
|
||||
].joined()
|
||||
|
||||
@@ -24,7 +24,12 @@ public struct EmptyParenthesesWithTrailingClosureRule: ASTRule, ConfigurationPro
|
||||
"[1, 2].map({ $0 + 1 })\n",
|
||||
"[1, 2].reduce(0) { $0 + $1 }",
|
||||
"[1, 2].map { number in\n number + 1 \n}\n",
|
||||
"let isEmpty = [1, 2].isEmpty()\n"
|
||||
"let isEmpty = [1, 2].isEmpty()\n",
|
||||
"UIView.animateWithDuration(0.3, animations: {\n" +
|
||||
" self.disableInteractionRightView.alpha = 0\n" +
|
||||
"}, completion: { _ in\n" +
|
||||
" ()\n" +
|
||||
"})"
|
||||
],
|
||||
triggeringExamples: [
|
||||
"[1, 2].map↓() { $0 + 1 }",
|
||||
@@ -59,7 +64,7 @@ public struct EmptyParenthesesWithTrailingClosureRule: ASTRule, ConfigurationPro
|
||||
guard let range = file.contents.bridge()
|
||||
.byteRangeToNSRange(start: rangeStart, length: rangeLength),
|
||||
let match = regex.firstMatch(in: file.contents, options: [], range: range),
|
||||
match.range.location != NSNotFound else {
|
||||
match.range.location == range.location else {
|
||||
return []
|
||||
}
|
||||
|
||||
|
||||
@@ -46,22 +46,20 @@ public struct ImplicitGetterRule: Rule, ConfigurationProviderRule {
|
||||
],
|
||||
triggeringExamples: [
|
||||
classScoped("var foo: Int {\n ↓get {\n return 20 \n} \n} \n}"),
|
||||
classScoped("var foo: Int {\n ↓get{\n return 20 \n} \n} \n}"),
|
||||
classScoped("static var foo: Int {\n ↓get {\n return 20 \n} \n} \n}")
|
||||
]
|
||||
)
|
||||
|
||||
public func validateFile(_ file: File) -> [StyleViolation] {
|
||||
let getTokens = file.syntaxMap.tokens.filter { token -> Bool in
|
||||
guard SyntaxKind(rawValue: token.type) == .keyword else {
|
||||
return false
|
||||
let pattern = "\\bget\\b"
|
||||
let getTokens: [SyntaxToken] = file.rangesAndTokensMatching(pattern).flatMap { _, tokens in
|
||||
guard tokens.count == 1, let token = tokens.first,
|
||||
SyntaxKind(rawValue: token.type) == .keyword else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let tokenValue = file.contents.bridge()
|
||||
.substringWithByteRange(start: token.offset, length: token.length) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return tokenValue == "get"
|
||||
return token
|
||||
}
|
||||
|
||||
let violatingTokens = getTokens.filter { token -> Bool in
|
||||
|
||||
@@ -54,27 +54,27 @@ public struct MarkRule: CorrectableRule, ConfigurationProviderRule {
|
||||
private let mark = "MARK:"
|
||||
|
||||
private var nonSpaceOrTwoOrMoreSpace: String {
|
||||
return "(\(nonSpace)|\(twoOrMoreSpace))"
|
||||
return "(?:\(nonSpace)|\(twoOrMoreSpace))"
|
||||
}
|
||||
|
||||
private var spaceStartPattern: String {
|
||||
return "(\(nonSpaceOrTwoOrMoreSpace)\(mark))"
|
||||
return "(?:\(nonSpaceOrTwoOrMoreSpace)\(mark))"
|
||||
}
|
||||
|
||||
private var endNonSpacePattern: String {
|
||||
return "(\(mark)\(nonSpace))"
|
||||
return "(?:\(mark)\(nonSpace))"
|
||||
}
|
||||
|
||||
private var endTwoOrMoreSpacePattern: String {
|
||||
return "(\(mark)\(twoOrMoreSpace))"
|
||||
return "(?:\(mark)\(twoOrMoreSpace))"
|
||||
}
|
||||
|
||||
private var twoOrMoreSpacesAfterHyphenPattern: String {
|
||||
return "(\(mark) -\(twoOrMoreSpace))"
|
||||
return "(?:\(mark) -\(twoOrMoreSpace))"
|
||||
}
|
||||
|
||||
private var nonSpaceOrNewlineAfterHyphenPattern: String {
|
||||
return "(\(mark) -[^ \n])"
|
||||
return "(?:\(mark) -[^ \n])"
|
||||
}
|
||||
|
||||
private var pattern: String {
|
||||
|
||||
@@ -1,35 +1,60 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Swiftlint Report</title>
|
||||
<style type='text/css'>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
table {
|
||||
border: 1px solid gray;
|
||||
border-collapse: collapse;
|
||||
-moz-box-shadow: 3px 3px 4px #AAA;
|
||||
-webkit-box-shadow: 3px 3px 4px #AAA;
|
||||
box-shadow: 3px 3px 4px #AAA;
|
||||
vertical-align: top;
|
||||
height: 64px;
|
||||
}
|
||||
td, th {
|
||||
|
||||
td, th {
|
||||
border: 1px solid #D3D3D3;
|
||||
padding: 5px 10px 5px 10px;
|
||||
}
|
||||
th {
|
||||
border-bottom: 1px solid gray;
|
||||
background-color: rgba(41,52,92,0.313);
|
||||
}
|
||||
.error, .warning {
|
||||
background-color: #f0f099;
|
||||
} .error{ color: #ff0000;}
|
||||
.warning { color: #b36b00;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
border-bottom: 1px solid gray;
|
||||
background-color: rgba(41,52,92,0.313);
|
||||
}
|
||||
|
||||
.error, .warning {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error {
|
||||
background-color: #FF9D92;
|
||||
color: #7F0800;
|
||||
}
|
||||
|
||||
.warning {
|
||||
background-color: #FFF59E;
|
||||
color: #7F7000;
|
||||
}
|
||||
</style>
|
||||
|
||||
<title>SwiftLint Report</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Swiftlint Report</h1>
|
||||
<h1>SwiftLint Report</h1>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2>Violations</h2>
|
||||
<table border="1" style="vertical-align: top; height: 64px;">
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 60pt;">
|
||||
@@ -51,38 +76,41 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="right">1</td>
|
||||
<td style="text-align: right;">1</td>
|
||||
<td>filename</td>
|
||||
<td align="center">1:2</td>
|
||||
<td class='warning'>Warning</td>
|
||||
<td style="text-align: center;">1:2</td>
|
||||
<td class="warning">Warning</td>
|
||||
<td>Violation Reason.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">2</td>
|
||||
<td style="text-align: right;">2</td>
|
||||
<td>filename</td>
|
||||
<td align="center">1:2</td>
|
||||
<td class='error'>Error</td>
|
||||
<td style="text-align: center;">1:2</td>
|
||||
<td class="error">Error</td>
|
||||
<td>Violation Reason.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">3</td>
|
||||
<td style="text-align: right;">3</td>
|
||||
<td>filename</td>
|
||||
<td align="center">1:2</td>
|
||||
<td class='error'>Error</td>
|
||||
<td style="text-align: center;">1:2</td>
|
||||
<td class="error">Error</td>
|
||||
<td>Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="right">4</td>
|
||||
<td style="text-align: right;">4</td>
|
||||
<td><nopath></td>
|
||||
<td align="center">0:0</td>
|
||||
<td class='error'>Error</td>
|
||||
<td style="text-align: center;">0:0</td>
|
||||
<td class="error">Error</td>
|
||||
<td>Colons should be next to the identifier when specifying a type.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
|
||||
<h2>Summary</h2>
|
||||
<table border="1" style="vertical-align: top; height: 64px;">
|
||||
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Total files with violations</td>
|
||||
@@ -98,9 +126,13 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<hr />
|
||||
<p>Created with <a href="https://github.com/realm/SwiftLint">
|
||||
<b>Swiftlint</b>
|
||||
</a> 1.2.3 on: 13/12/2016</p>
|
||||
|
||||
<p>
|
||||
Created with
|
||||
<a href="https://github.com/realm/SwiftLint"><b>SwiftLint</b></a>
|
||||
1.2.3 on 13/12/2016
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user