Skip to content

Commit

Permalink
Fix formatting of lib's fun starting with uppercase letter
Browse files Browse the repository at this point in the history
  • Loading branch information
bew committed Dec 21, 2017
1 parent 7791254 commit f5eb49d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ describe Crystal::Formatter do
assert_format "lib Foo\nend"
assert_format "lib Foo\ntype Foo = Bar\nend", "lib Foo\n type Foo = Bar\nend"
assert_format "lib Foo\nfun foo\nend", "lib Foo\n fun foo\nend"
assert_format "lib Foo\nfun Bar\nend", "lib Foo\n fun Bar\nend"
assert_format "lib Foo\nfun bar = Bar\nend", "lib Foo\n fun bar = Bar\nend"

This comment has been minimized.

Copy link
@bew

bew Dec 21, 2017

Author Owner

good point, added!

assert_format "lib Foo\nfun foo : Int32\nend", "lib Foo\n fun foo : Int32\nend"
assert_format "lib Foo\nfun foo() : Int32\nend", "lib Foo\n fun foo : Int32\nend"
assert_format "lib Foo\nfun foo () : Int32\nend", "lib Foo\n fun foo : Int32\nend"
Expand Down
10 changes: 7 additions & 3 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1530,9 +1530,13 @@ module Crystal
def visit(node : FunDef)
write_keyword :fun, " "

check :IDENT
write node.name
next_token_skip_space
case @token.type
when :IDENT, :CONST
write node.name
next_token_skip_space
else
raise "expecting :IDENT or :CONST, not `#{@token.type}, #{@token.value}`, at #{@token.location}"
end

if @token.type == :"="
write " = "
Expand Down

0 comments on commit f5eb49d

Please sign in to comment.