@@ -23,13 +23,15 @@ public struct ClosureBodyLengthRule: ASTRule, OptInRule, ConfigurationProviderRu
23
23
triggeringExamples: ClosureBodyLengthRuleExamples . triggeringExamples
24
24
)
25
25
26
+ private typealias ClosureBounds = ( offset: Int , startLine: Int , endLine: Int )
27
+
26
28
public func validate( file: File ,
27
29
kind: SwiftExpressionKind ,
28
30
dictionary: [ String : SourceKitRepresentable ] ) -> [ StyleViolation ] {
29
31
guard kind == . call else { return [ ] }
30
32
31
33
return findClosures ( in: dictionary)
32
- . flatMap { closureDictionary -> ( Int , Int , Int ) ? in
34
+ . flatMap { closureDictionary -> ClosureBounds ? in
33
35
guard
34
36
let bodyOffset = closureDictionary. bodyOffset,
35
37
let bodyLength = closureDictionary. bodyLength,
@@ -38,12 +40,12 @@ public struct ClosureBodyLengthRule: ASTRule, OptInRule, ConfigurationProviderRu
38
40
let endLine = contents. lineAndCharacter ( forByteOffset: bodyOffset + bodyLength) ? . line
39
41
else { return nil }
40
42
41
- return ( offset: bodyOffset, startLine: startLine, endLine: endLine)
43
+ return ClosureBounds ( offset: bodyOffset, startLine: startLine, endLine: endLine)
42
44
}
43
- . flatMap { offset , startLine , endLine -> [ StyleViolation ] in
45
+ . flatMap { closureBounds -> [ StyleViolation ] in
44
46
return configuration. params. flatMap { parameter -> StyleViolation ? in
45
- let ( exceeds, count) = file. exceedsLineCountExcludingCommentsAndWhitespace ( startLine,
46
- endLine,
47
+ let ( exceeds, count) = file. exceedsLineCountExcludingCommentsAndWhitespace ( closureBounds . startLine,
48
+ closureBounds . endLine,
47
49
parameter. value)
48
50
guard exceeds else { return nil }
49
51
@@ -52,7 +54,7 @@ public struct ClosureBodyLengthRule: ASTRule, OptInRule, ConfigurationProviderRu
52
54
53
55
return StyleViolation ( ruleDescription: type ( of: self ) . description,
54
56
severity: parameter. severity,
55
- location: Location ( file: file, byteOffset: offset) ,
57
+ location: Location ( file: file, byteOffset: closureBounds . offset) ,
56
58
reason: reason)
57
59
}
58
60
}
0 commit comments