diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6cac10462..2bddf2d83 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/README.md b/README.md
index 1eb34e71e..41120f306 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/Source/SwiftLintFramework/Reporters/HTMLReporter.swift b/Source/SwiftLintFramework/Reporters/HTMLReporter.swift
index a00d8a563..888851224 100644
--- a/Source/SwiftLintFramework/Reporters/HTMLReporter.swift
+++ b/Source/SwiftLintFramework/Reporters/HTMLReporter.swift
@@ -45,35 +45,60 @@ public struct HTMLReporter: Reporter {
"\n",
"\n",
"\t
\n",
- "\t\tSwiftlint Report\n",
- "\t\t\n",
+ "\t\t\n",
+ "\t\tSwiftLint Report\n",
"\t\n",
"\t\n",
- "\t\tSwiftlint Report
\n",
+ "\t\tSwiftLint Report
\n",
+ "\t\t\n",
"\t\t
\n",
+ "\t\t\n",
"\t\tViolations
\n",
- "\t\t\n",
+ "\t\t\n",
+ "\t\t\n",
"\t\t\t\n",
"\t\t\t\t\n",
"\t\t\t\t\t| \n",
@@ -95,9 +120,12 @@ public struct HTMLReporter: Reporter {
"\t\t\t |
\n",
"\t\t\t\n", rows, "\t\t\t\n",
"\t\t
\n",
+ "\t\t\n",
"\t\t
\n",
+ "\t\t\n",
"\t\tSummary
\n",
- "\t\t\n",
+ "\t\t\n",
+ "\t\t\n",
"\t\t\t\n",
"\t\t\t\t\n",
"\t\t\t\t\t| Total files with violations | \n",
@@ -113,10 +141,14 @@ public struct HTMLReporter: Reporter {
"\t\t\t\t
\n",
"\t\t\t\n",
"\t\t
\n",
+ "\t\t\n",
"\t\t
\n",
- "\t\tCreated with \n",
- "\t\t\tSwiftlint\n",
- "\t\t ", swiftlintVersion, " on: ", dateString, "
\n",
+ "\t\t\n",
+ "\t\t\n",
+ "\t\t\tCreated with\n",
+ "\t\t\tSwiftLint\n",
+ "\t\t\t", swiftlintVersion, " on ", dateString, "\n",
+ "\t\t
\n",
"\t\n",
""
].joined()
@@ -130,10 +162,10 @@ public struct HTMLReporter: Reporter {
let character: Int = location.character ?? 0
return [
"\t\t\t\t\n",
- "\t\t\t\t\t| \(index) | \n",
+ "\t\t\t\t\t\(index) | \n",
"\t\t\t\t\t", file, " | \n",
- "\t\t\t\t\t\(line):\(character) | \n",
- "\t\t\t\t\t", severity, " | \n",
+ "\t\t\t\t\t\(line):\(character) | \n",
+ "\t\t\t\t\t", severity, " | \n",
"\t\t\t\t\t\(violation.reason.escapedForXML()) | \n",
"\t\t\t\t
\n"
].joined()
diff --git a/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift b/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift
index 35a7afb9b..d02781cfe 100644
--- a/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift
+++ b/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift
@@ -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 []
}
diff --git a/Source/SwiftLintFramework/Rules/ImplicitGetterRule.swift b/Source/SwiftLintFramework/Rules/ImplicitGetterRule.swift
index 0556db1e6..7fd5edccd 100644
--- a/Source/SwiftLintFramework/Rules/ImplicitGetterRule.swift
+++ b/Source/SwiftLintFramework/Rules/ImplicitGetterRule.swift
@@ -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
diff --git a/Source/SwiftLintFramework/Rules/MarkRule.swift b/Source/SwiftLintFramework/Rules/MarkRule.swift
index eca08b333..4bdda04a0 100644
--- a/Source/SwiftLintFramework/Rules/MarkRule.swift
+++ b/Source/SwiftLintFramework/Rules/MarkRule.swift
@@ -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 {
diff --git a/Tests/SwiftLintFrameworkTests/Resources/CannedHTMLReporterOutput.html b/Tests/SwiftLintFrameworkTests/Resources/CannedHTMLReporterOutput.html
index 8b3a2bed2..76119b9e6 100644
--- a/Tests/SwiftLintFrameworkTests/Resources/CannedHTMLReporterOutput.html
+++ b/Tests/SwiftLintFrameworkTests/Resources/CannedHTMLReporterOutput.html
@@ -1,35 +1,60 @@
- Swiftlint Report
-
+
+ SwiftLint Report
- Swiftlint Report
+ SwiftLint Report
+
+
Violations
-
+
+
|
@@ -51,38 +76,41 @@
|
- | 1 |
+ 1 |
filename |
- 1:2 |
- Warning |
+ 1:2 |
+ Warning |
Violation Reason. |
- | 2 |
+ 2 |
filename |
- 1:2 |
- Error |
+ 1:2 |
+ Error |
Violation Reason. |
- | 3 |
+ 3 |
filename |
- 1:2 |
- Error |
+ 1:2 |
+ Error |
Shorthand syntactic sugar should be used, i.e. [Int] instead of Array<Int>. |
- | 4 |
+ 4 |
<nopath> |
- 0:0 |
- Error |
+ 0:0 |
+ Error |
Colons should be next to the identifier when specifying a type. |
+
+
Summary
-
+
+
| Total files with violations |
@@ -98,9 +126,13 @@
+
- Created with
- Swiftlint
- 1.2.3 on: 13/12/2016
+
+
+ Created with
+ SwiftLint
+ 1.2.3 on 13/12/2016
+
\ No newline at end of file