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

Docstring breaks short_to_long_function_def #867

Open
jw3126 opened this issue Aug 28, 2024 · 1 comment
Open

Docstring breaks short_to_long_function_def #867

jw3126 opened this issue Aug 28, 2024 · 1 comment

Comments

@jw3126
Copy link
Contributor

jw3126 commented Aug 28, 2024

It seems short function defs that have a docstring are never expanded:

using JuliaFormatter
using JuliaFormatter: options, DefaultStyle

fmt1(s; i = 4, m = 80, kwargs...) =
    JuliaFormatter.format_text(s; kwargs..., indent = i, margin = m)
fmt1(s, i, m; kwargs...) = fmt1(s; kwargs..., i = i, m = m)

# Verifies formatting the formatted text
# results in the same output
function fmt(s; i = 4, m = 80, kwargs...)
    kws = merge(options(DefaultStyle()), kwargs)
    s1 = fmt1(s; kws..., i = i, m = m)
    return fmt1(s1; kws..., i = i, m = m)
end
fmt(s, i, m; kwargs...) = fmt(s; kwargs..., i = i, m = m)

str_ = """
    f() = (1,2,3,4,5,6,7,8,9,10)
"""
print(fmt(str_, 4, 10, short_to_long_function_def = true))
# ok

str_ = """
"docstring"
f() = (1,2,3,4,5,6,7,8,9,10)
"""
print(fmt(str_, 4, 10, short_to_long_function_def = true))
# bad
function f()
    (
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
    )
end
"docstring"
f() = (
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
)

@domluna
Copy link
Owner

domluna commented Sep 25, 2024

julia> format_text(str_, short_to_long_function_def=true, margin=10) |> print
"docstring"
function f()
    (
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
    )
end

seems it's fixed in the rewrite to JuliaSyntax. I'll merge that PR sometime this week.

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