Skip to content

Commit

Permalink
Rename an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
gibachan committed Sep 25, 2023
1 parent fd68a80 commit 985918b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Source/SwiftLintBuiltInRules/Rules/Lint/TodoRule.swift
Expand Up @@ -40,28 +40,31 @@ private extension TodoRule {
}

override func visitPost(_ node: TokenSyntax) {
let leadingViolations = node.leadingTrivia.violations(offset: node.position, only: only)
let leadingViolations = node.leadingTrivia.violations(offset: node.position,
for: only)
let trailingViolations = node.trailingTrivia.violations(offset: node.endPositionBeforeTrailingTrivia,
only: only)
for: only)
violations.append(contentsOf: leadingViolations + trailingViolations)
}
}
}

private extension Trivia {
func violations(offset: AbsolutePosition, only: [TodoConfiguration.TodoKeyword]) -> [ReasonedRuleViolation] {
func violations(offset: AbsolutePosition,
for todoKeywords: [TodoConfiguration.TodoKeyword]) -> [ReasonedRuleViolation] {
var position = offset
var violations = [ReasonedRuleViolation]()
for piece in self {
violations.append(contentsOf: piece.violations(offset: position, only: only))
violations.append(contentsOf: piece.violations(offset: position, for: todoKeywords))
position += piece.sourceLength
}
return violations
}
}

private extension TriviaPiece {
func violations(offset: AbsolutePosition, only: [TodoConfiguration.TodoKeyword]) -> [ReasonedRuleViolation] {
func violations(offset: AbsolutePosition,
for todoKeywords: [TodoConfiguration.TodoKeyword]) -> [ReasonedRuleViolation] {
switch self {
case
.blockComment(let comment),
Expand All @@ -70,7 +73,7 @@ private extension TriviaPiece {
.docLineComment(let comment):

// Construct a regex string considering only keywords.
let searchKeywords = only.map(\.rawValue).joined(separator: "|")
let searchKeywords = todoKeywords.map(\.rawValue).joined(separator: "|")
let matches = regex(#"\b((?:\#(searchKeywords))(?::|\b))"#)
.matches(in: comment, range: comment.bridge().fullNSRange)
return matches.reduce(into: []) { violations, match in
Expand Down

0 comments on commit 985918b

Please sign in to comment.