Skip to content

Commit

Permalink
[bug fix] expiring todo regex (#3597)
Browse files Browse the repository at this point in the history
* Add failing tests

* Fix regex to allow non-zero-padded dates

* Update changelog

* Update CHANGELOG.md
  • Loading branch information
namolnad authored May 2, 2021
1 parent ebb51ed commit dd672b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
with a static member (e.g. `if number == .zero`).
[Marcelo Fabri](https://github.com/marcelofabri)
[#3562](https://github.com/realm/SwiftLint/issues/3562)
* Fix the regex for expiring-todos
[namolnad](https://github.com/namolnad)
[#3597](https://github.com/realm/SwiftLint/pull/3597)

## 0.43.1: Laundroformat

Expand Down
6 changes: 4 additions & 2 deletions Source/SwiftLintFramework/Rules/Lint/ExpiringTodoRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {
],
triggeringExamples: [
Example("// TODO: [10/14/2019]\n"),
Example("// FIXME: [10/14/2019]\n")
Example("// FIXME: [10/14/2019]\n"),
Example("// FIXME: [1/14/2019]\n"),
Example("// FIXME: [10/4/2019]\n")
]
)

Expand All @@ -44,7 +46,7 @@ public struct ExpiringTodoRule: ConfigurationProviderRule, OptInRule {

public func validate(file: SwiftLintFile) -> [StyleViolation] {
// swiftlint:disable:next line_length
let regex = "\\b(?:TODO|FIXME)(?::|\\b)(?:.*)\\\(configuration.dateDelimiters.opening)(\\d{2,4}\\\(configuration.dateSeparator)\\d{2}\\\(configuration.dateSeparator)\\d{2,4})\\\(configuration.dateDelimiters.closing)"
let regex = "\\b(?:TODO|FIXME)(?::|\\b)(?:.*)\\\(configuration.dateDelimiters.opening)(\\d{1,4}\\\(configuration.dateSeparator)\\d{1,2}\\\(configuration.dateSeparator)\\d{1,4})\\\(configuration.dateDelimiters.closing)"

return file.matchesAndSyntaxKinds(matching: regex).compactMap { checkingResult, syntaxKinds in
guard
Expand Down

0 comments on commit dd672b4

Please sign in to comment.