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

Multi-line strings with keyword and pair arguments #560

Open
tkf opened this issue Mar 22, 2022 · 3 comments
Open

Multi-line strings with keyword and pair arguments #560

tkf opened this issue Mar 22, 2022 · 3 comments

Comments

@tkf
Copy link

tkf commented Mar 22, 2022

I couldn't find the issue (maybe #501 is the closest) but I find this behavior strange

julia> code = """
       f(
       a = \"\"\"
       string
       \"\"\",
       b = \"\"\"
       string
       \"\"\",
       )
       """;

julia> print(code)
f(
a = """
string
""",
b = """
string
""",
)

julia> print(format_text(code))
f(a = """
  string
  """, b = """
       string
       """)

Similar with =>:

julia> code = """
       f(
       "a" => \"\"\"
       string
       \"\"\",
       "b" => \"\"\"
       string
       \"\"\",
       )
       """;

julia> print(code)
f(
"a" => """
string
""",
"b" => """
string
""",
)

julia> print(format_text(code))
f("a" => """
  string
  """, "b" => """
       string
       """)

I checked this with

(jl_XRYQ8s) pkg> st -m
      Status `/tmp/jl_XRYQ8s/Manifest.toml`
  [00ebfdb7] CSTParser v3.3.3
  [a80b9123] CommonMark v0.8.6
  [34da2185] Compat v3.42.0
  [a8cc5b0e] Crayons v4.1.1
  [864edb3b] DataStructures v0.18.11
  [682c06a0] JSON v0.21.3
  [98e50ef6] JuliaFormatter v0.22.7
  [bac558e1] OrderedCollections v1.4.1
  [69de0a69] Parsers v2.2.3
  [0796e94c] Tokenize v0.5.21
  [5c2747f8] URIs v1.3.0
  ...
@domluna
Copy link
Owner

domluna commented Mar 22, 2022

hmmm so what's going on is it thinks the width of the code < the maximum width so it joins the lines which in this case ends up with a strange format.

If you just some 2 multiline strings (no binary op) then it doesn't do this right?

@tkf
Copy link
Author

tkf commented Mar 22, 2022

Yeah, I think this is expected:

julia> code = """
       f(
       \"\"\"
       string
       \"\"\",
       \"\"\"
       string
       \"\"\",
       )
       """;

julia> print(code)
f(
"""
string
""",
"""
string
""",
)

julia> print(format_text(code))
f(
    """
    string
    """,
    """
    string
    """,
)

@tkf
Copy link
Author

tkf commented Mar 22, 2022

My workaround ATM is to put some comments inside:

julia> code = """
       f(
       # workaround
       "a" => \"\"\"
       string
       \"\"\",
       "b" => \"\"\"
       string
       \"\"\",
       )
       """;

julia> print(code)
f(
# workaround
"a" => """
string
""",
"b" => """
string
""",
)

julia> print(format_text(code))
f(
    # workaround
    "a" => """
    string
    """,
    "b" => """
    string
    """,
)

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

2 participants