Skip to content

Commit

Permalink
Ensure single space before module name (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Nov 4, 2024
1 parent d9a27b9 commit 1675c2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,10 @@ end
# global, const
function spaces_around_keywords(ctx::Context, node::Node)
is_leaf(node) && return nothing
keyword_set = KSet"where do mutable struct abstract primitive type function if elseif catch while return local global const"
keyword_set = KSet"""
where do mutable struct abstract primitive type function if elseif catch while return
local global const module baremodule
"""
if !(kind(node) in keyword_set)
return nothing
end
Expand Down Expand Up @@ -1331,7 +1334,7 @@ function spaces_around_keywords(ctx::Context, node::Node)
@assert false # Unreachable?
else
# Reachable in e.g. `T where{T}`, `if(`, ... insert space
@assert kind(node) in KSet"where if elseif while do function return local global"
@assert kind(node) in KSet"where if elseif while do function return local global module baremodule"
any_changes = true
if kids′ === kids
kids′ = kids[1:(i - 1)]
Expand Down Expand Up @@ -3001,10 +3004,10 @@ function indent_module(ctx::Context, node::Node; do_indent::Bool = true)
space_idx = 2
space_node = kids[space_idx]
if kind(space_node) === K"Whitespace"
# Now we need an identifier or var"
# Now we need an identifier, var" or parens...
id_idx = 3
id_node = kids[id_idx]
@assert kind(id_node) in KSet"Identifier var"
@assert kind(id_node) in KSet"Identifier var parens"
block_idx = 4
else
# This can be reached if the module name is interpolated or parenthesized, for
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ end
@test format_string("f()$(sp)do; y end") == "f() do;\n y\nend"
@test format_string("function f()\n return$(sp)1\nend") == "function f()\n return 1\nend"
@test format_string("function f()\n return$(sp)\nend") == "function f()\n return\nend"
@test format_string("module$(sp)A\nend") == "module A\nend"
@test format_string("module$(sp)(A)\nend") == "module (A)\nend"
for word in ("local", "global"), rhs in ("a", "a, b", "a = 1", "a, b = 1, 2")
word == "const" && rhs in ("a", "a, b") && continue
@test format_string("$(word)$(sp)$(rhs)") == "$(word) $(rhs)"
Expand All @@ -528,6 +530,7 @@ end
@test format_string("function f()\n return(1)\nend") == "function f()\n return (1)\nend"
@test format_string("local(a)") == "local (a)"
@test format_string("global(a)") == "global (a)"
@test format_string("module(A)\nend") == "module (A)\nend"
end

@testset "replace ∈ and = with in in for loops and generators" begin
Expand Down Expand Up @@ -712,8 +715,8 @@ end
@test format_string("$(b)module \$A\n$(sp)x\n$(sp)end\nf") ==
"$(b)module \$A\n x\nend\nf"
# parenthesized module name (Why....)
@test format_string("$(b)module(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module(A)\n x\nend\nf"
@test format_string("$(b)module$(sp)(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module (A)\n x\nend\nf"
@test format_string("$(b)module \$(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module \$(A)\n x\nend\nf"
# single line module
Expand Down

2 comments on commit 1675c2d

@fredrikekre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/117521

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" 1675c2d86cecc0bd19ad45bc2e46681aae01868c
git push origin v1.0.0

Please sign in to comment.