Skip to content

Commit

Permalink
Add support for ternary whitespace deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Aug 24, 2017
1 parent ebfe1f6 commit ef77749
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
37 changes: 37 additions & 0 deletions src/database/simple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,41 @@ begin
"Compat.ASCIIString",
"String",
)
end

begin
struct ConditionalWhitespace; end
register(ConditionalWhitespace, Deprecation(
"This Compat definition is deprecated",
"julia",
v"0.4.0", v"0.7.0-DEV.797", typemax(VersionNumber)
))

function add_ws_lead_trail!(ret, idx, exprs)
any = false
expr = exprs[2]
allws = string(trailing_ws(exprs[1]), leading_ws(expr))
if isempty(allws) || !isspace(allws[end])
expr = children(ret)[idx] = TriviaReplacementNode(ret, expr, string(leading_ws(expr), " "), trailing_ws(expr))
any = true
end
allws = string(trailing_ws(expr), leading_ws(exprs[3]))
if isempty(allws) || !isspace(allws[end])
expr = children(ret)[idx] = TriviaReplacementNode(ret, expr, leading_ws(expr), string(" ", trailing_ws(expr)))
any = true
end
any
end

match(ConditionalWhitespace, CSTParser.ConditionalOpCall) do x
dep, expr, resolutions, context = x
ret = ChildReplacementNode(nothing, collect(children(expr)), expr)
changed = add_ws_lead_trail!(ret, 2, children(expr)[1:3])
changed |= add_ws_lead_trail!(ret, 4, children(expr)[3:5])
if changed
buf = IOBuffer()
print_replacement(buf, ret, false, false)
push!(resolutions, TextReplacement(expr.span, String(take!(buf))))
end
end
end
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -859,4 +859,8 @@ for t in [
"""
]
@test text_not_edited(t)
end
end

@test edit_text("a?b:c")[2] == "a ? b : c"
@test edit_text("a ?b:c")[2] == "a ? b : c"
@test text_not_edited("a ? b : c")

0 comments on commit ef77749

Please sign in to comment.