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

fix for #753 #754

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JuliaFormatter"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
authors = ["Dominique Luna <[email protected]>"]
version = "1.0.36"
version = "1.0.37"

[deps]
CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f"
Expand Down
7 changes: 7 additions & 0 deletions src/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ end
function short_to_long_function_def!(fst::FST, s::State)
(fst[1].typ !== Call && fst[1].typ !== Where) && return false

# do not apply if parent is a function or macro definition
parent_is(
fst.ref[],
n -> is_function_or_macro_def(n) || n.head == :macrocall;
ignore = n -> is_block(n),
) && return false

# 3 cases
#
# case 1
Expand Down
23 changes: 22 additions & 1 deletion test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,27 @@
0.0008014; 0.0001464; 2.67e-05; 4.8e-6; 9e-7; 0.0619917; 1.2444292; 0.0486676;
199.9383546; 137.4267984; 1.5180203; 1.5180203]
"""
@test fmt(str_, 4, 92, join_lines_based_on_source=true) == str
@test fmt(str_, 4, 92, join_lines_based_on_source = true) == str
end

@testset "753" begin
str_ = """
using ModelingToolkit
@mtkmodel A begin
@variables begin
i(t) = 0.0, [description = "Line longer than the char limit of 94 characters", unit = u"A"]
end
end
"""
str = """
using ModelingToolkit
@mtkmodel A begin
@variables begin
i(t) = 0.0,
[description = "Line longer than the char limit of 94 characters", unit = u"A"]
end
end
"""
@test format_text(str_, SciMLStyle()) == str
end
end
6 changes: 2 additions & 4 deletions test/sciml_style.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
m.inv_match === nothing && throw(ArgumentError("Backwards matching not defined. `complete` the matching first."))
"""
formatted_str = raw"""
@noinline function require_complete(m::Matching)
m.inv_match === nothing &&
throw(ArgumentError("Backwards matching not defined. `complete` the matching first."))
end
@noinline require_complete(m::Matching) = m.inv_match === nothing &&
throw(ArgumentError("Backwards matching not defined. `complete` the matching first."))
"""
@test format_text(str, SciMLStyle()) == formatted_str

Expand Down