Skip to content
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

α=1.# causes Formatter to error but should not #853

Open
kellertuer opened this issue Jun 28, 2024 · 0 comments
Open

α=1.# causes Formatter to error but should not #853

kellertuer opened this issue Jun 28, 2024 · 0 comments

Comments

@kellertuer
Copy link

kellertuer commented Jun 28, 2024

We just noticed a bug (we think) where correct Julia code is causing Formatter to error.

If you do

format_text("α=1.# Assigns α to 1.0")

The actual code is correct Julia code (sure not nice, one should write floats with an ending 0 here, but still)
but it errors with

ERROR: Parsing error for input occurred on line 1, offset: 3
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] format_text(text::String, style::DefaultStyle, opts::JuliaFormatter.Options)
   @ JuliaFormatter ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:241
 [3] #format_text#280
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:215 [inlined]
 [4] format_text
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:212 [inlined]
 [5] #format_text#279
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:209 [inlined]
 [6] format_text(text::String)
   @ JuliaFormatter ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:208
 [7] top-level scope
   @ REPL[4]:1

adding the 0 or a space makes the formatting correctly (and adding the 0 for the case of the space)

If you format even

text = raw"""
       α=1.# A
       β=2.0
       """
format_text(text)

the lines are concatenated into one see the error with

ERROR: Error while PARSING formatted text:

1 α = 1.β = 2.0

...

Error occurred on line 1, offset 9 of formatted text.

The error might not be precisely on this line but it should be in the region of the code block. Try commenting the region out and see if that removes the error.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] format_text(cst::CSTParser.EXPR, style::DefaultStyle, s::JuliaFormatter.State)
   @ JuliaFormatter ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:314
 [3] format_text(text::String, style::DefaultStyle, opts::JuliaFormatter.Options)
   @ JuliaFormatter ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:243
 [4] #format_text#280
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:215 [inlined]
 [5] format_text
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:212 [inlined]
 [6] #format_text#279
   @ ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:209 [inlined]
 [7] format_text(text::String)
   @ JuliaFormatter ~/.julia/packages/JuliaFormatter/7y9aN/src/JuliaFormatter.jl:208
 [8] top-level scope
   @ REPL[7]:1

which might lead to misleading line numbers.

PS: In general formatter works great and I am very happy to use it and have a CI reminding me to format my code – thanks for the package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant