Skip to content

Commit 57054f7

Browse files
authored
Merge pull request swiftlang#134 from dabelknap/lint-linenumbers
The line numbers of nodes should be reported ignoring leading trivia
2 parents cc6923f + 1e112e6 commit 57054f7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/SwiftFormatCore/SyntaxLintRule.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ extension Rule {
3838
on node: Syntax?,
3939
actions: ((inout Diagnostic.Builder) -> Void)? = nil
4040
) {
41+
// TODO: node?.startLocation should be returning the position ignoring leading trivia. It isn't
42+
// working properly, so we are using this workaround until it is fixed.
43+
let loc = node.map {
44+
SourceLocation(
45+
file: context.fileURL.path,
46+
position: $0.positionAfterSkippingLeadingTrivia
47+
)
48+
}
4149
context.diagnosticEngine?.diagnose(
4250
message.withRule(self),
43-
location: node?.startLocation(in: context.fileURL),
51+
location: loc,
4452
actions: actions
4553
)
4654
}

0 commit comments

Comments
 (0)