Skip to content

Commit 769edb6

Browse files
committed
Revert multibyte codepoint fix in 1a1ca39 (#367)
Codepoint width is difficult to determine with complete accuracy. The previous fix assumed a width of 1, which broke more indentation than it corrected. Reverting back to the previous behavior is not perfect, but it's the best solution we have so far. Fixes #369.
1 parent ec476ac commit 769edb6

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

β€Žcljfmt/src/cljfmt/core.cljcβ€Ž

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,8 @@
194194
(defn- last-line-in-string ^String [^String s]
195195
(subs s (inc (.lastIndexOf s "\n"))))
196196

197-
(defn- line-length [line]
198-
#?(:clj (.codePointCount ^String line 0 (.length ^String line))
199-
:cljs (.-length (js/Array.from line))))
200-
201197
(defn- margin [zloc]
202-
(-> zloc prior-line-string last-line-in-string line-length))
198+
(-> zloc prior-line-string last-line-in-string count))
203199

204200
(defn- whitespace [width]
205201
(n/whitespace-node (apply str (repeat width " "))))

β€Žcljfmt/test/cljfmt/core_test.cljcβ€Ž

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,17 +2012,23 @@
20122012

20132013
(deftest test-multibyte-codepoints
20142014
(is (reformats-to?
2015-
["(defn- x"
2016-
" [x style]"
2017-
" (case style"
2018-
" :normal x"
2019-
" :π•¨π•šπ•π•• (if (sequential? x)"
2020-
" :a"
2021-
" :b)))"]
2022-
["(defn- x"
2023-
" [x style]"
2024-
" (case style"
2025-
" :normal x"
2026-
" :π•¨π•šπ•π•• (if (sequential? x)"
2027-
" :a"
2028-
" :b)))"])))
2015+
["[(str \"email\""
2016+
" \"Brian\")"
2017+
"(str \"πŸ“š \" (str \"email\""
2018+
" \"Convert\"))"
2019+
"(str \"βŒ›οΈ \" (str \"email\""
2020+
" \"Save\"))"
2021+
"(str \"πŸŽ“ \" (str \"email\""
2022+
" \"Help\"))"
2023+
"(str \"πŸ”’ \" (str \"email\""
2024+
" \"Leverage\"))]"]
2025+
["[(str \"email\""
2026+
" \"Brian\")"
2027+
" (str \"πŸ“š \" (str \"email\""
2028+
" \"Convert\"))"
2029+
" (str \"βŒ›οΈ \" (str \"email\""
2030+
" \"Save\"))"
2031+
" (str \"πŸŽ“ \" (str \"email\""
2032+
" \"Help\"))"
2033+
" (str \"πŸ”’ \" (str \"email\""
2034+
" \"Leverage\"))]"])))

0 commit comments

Comments
Β (0)