Compare commits

...

1 Commits

Author SHA1 Message Date
Marcelo Fabri 53700ac8fa Don’t trigger colon inside object literals
Fixes #2740
2019-04-30 10:51:45 -07:00
4 changed files with 16 additions and 4 deletions

View File

@ -30,6 +30,11 @@
return type is required.
[Marcelo Fabri](https://github.com/marcelofabri)
* Don't trigger `colon` violations in object literals
(`#imageLiteral(name:"image")` for example).
[Marcelo Fabri](https://github.com/marcelofabri)
[#2740](https://github.com/realm/SwiftLint/issues/2740)
## 0.32.0: Wash-N-Fold-N-Reduce
#### Breaking

View File

@ -2052,6 +2052,10 @@ class ABC { let def = ghi(jkl: mno) } }
func foo() { let dict = [1: 1] }
```
```swift
#imageLiteral(resourceName:"grayArrowUp"))
```
</details>
<details>
<summary>Triggering Examples</summary>

View File

@ -18,7 +18,7 @@ extension ColonRule {
internal func functionCallColonViolationRanges(in file: File, kind: SwiftExpressionKind,
dictionary: [String: SourceKitRepresentable]) -> [NSRange] {
guard kind == .argument,
let ranges = functionCallColonRanges(dictionary: dictionary) else {
let ranges = functionCallColonRanges(dictionary: dictionary, file: file) else {
return []
}
@ -37,12 +37,14 @@ extension ColonRule {
}
}
private func functionCallColonRanges(dictionary: [String: SourceKitRepresentable]) -> [NSRange]? {
private func functionCallColonRanges(dictionary: [String: SourceKitRepresentable], file: File) -> [NSRange]? {
guard let nameOffset = dictionary.nameOffset,
let nameLength = dictionary.nameLength, nameLength > 0,
let bodyOffset = dictionary.bodyOffset,
case let location = nameOffset + nameLength,
bodyOffset > location else {
bodyOffset > location,
case let nameRange = NSRange(location: nameOffset, length: nameLength),
file.syntaxMap.kinds(inByteRange: nameRange) != [.objectLiteral] else {
return nil
}

View File

@ -37,7 +37,8 @@ internal struct ColonRuleExamples {
"func abc() { def(ghi: jkl) }",
"func abc(def: Void) { ghi(jkl: mno) }",
"class ABC { let def = ghi(jkl: mno) } }",
"func foo() { let dict = [1: 1] }"
"func foo() { let dict = [1: 1] }",
"#imageLiteral(resourceName:\"grayArrowUp\"))"
]
static let triggeringExamples = [