Skip to content

Crashes with comment only files #10

Open
@jdesgats

Description

@jdesgats

When a file contains only comments (use case: ldoc API definitions), the formatter crashes:

printf -- '-- this is just a comment\n-- more comments\n' | luaformatter /dev/stdin
/usr/bin/lua5.1: ...ome/julien/.luaenv/check/share/lua/5.1/formatter.lua:57: attempt to index local 'node' (a nil value)
stack traceback:
	...ome/julien/.luaenv/check/share/lua/5.1/formatter.lua:57: in function 'getlastline'
	...ome/julien/.luaenv/check/share/lua/5.1/formatter.lua:373: in function 'getindentlevel'
	...ome/julien/.luaenv/check/share/lua/5.1/formatter.lua:512: in function 'indentcode'
	...uarocks/rocks-5.1/formatter/0.1.1-1/bin/luaformatter:79: in main chunk
	[C]: ?

Interestingly, the issue doesn't exist with a single line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions