[test] Optimize offset->line in kondo-ratchet test (#79931)

This commit is contained in:
Oleksandr Yakushev
2026-10-03 20:26:47 +03:00
committed by GitHub
parent 073e520171
commit db6e70c620

View File

@@ -518,7 +518,7 @@
(defn- offset->line
"1-based line number of character offset `i` in `content`."
[content i]
(inc (count (filter #(= % \newline) (subs content 0 i)))))
(reduce (fn [cnt c] (cond-> cnt (= c \newline) inc)) 1 (subs content 0 i)))
(defn- matches-with-offsets
"Like re-seq, but returns `{:start _, :end _, :linters [...]}` for each match of `re` in `masked`."