New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter calculates the width of a fullwidth character as 1 #11034
Comments
Sorry, I don't understand what's the issue. Could you provide the description like this?
|
Okay, I have this code, and this is what I want after the formatting: require "spec"
describe ".ord" do
it "runs for each character" do
"ABA".chars.map(&.ord).should eq([65,
66,
65313])
end
end But when I format it, I get this: require "spec"
describe ".ord" do
it "runs for each character" do
"ABA".chars.map(&.ord).should eq([65,
66,
65313])
end
end Note that |
What about the character require "spec"
describe ".ord" do
it "runs for each character" do
"AB你".chars.map(&.ord).should eq([65,
66, # Not well aligned
65313])
end
end Still not correctly aligned: require "spec"
describe ".ord" do
it "runs for each character" do
"AB你".chars.map(&.ord).should eq([65,
66,
65313])
end
end There's no possible way it will look right. The formatter considers each char to be width 1. If things don't look well like that, it's fine. They are small exceptions. And it's impossible to fix in the general case. Just my opinion, though! |
I see, that makes sense. We can leave this open. We first need to have support in the standard library to compute the width of unicode characters. |
Looks like a good use case for https://forum.crystal-lang.org/t/unicode-character-string-width/3286 |
Original file (Note that the third character is fullwidth):
After running
crystal tool format
:This file passes
crystal tool format
:You can replace
A
with either가
or😀
as they're also treated as halfwidth characters by formatter.The text was updated successfully, but these errors were encountered: