Skip to content

LuaDevelopmentTools/luaformatter

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Lua Formatter

This library beautify Lua code:

  • Indent block
  • Indent expressions
  • Trim trailing white spaces

It is plain Lua 5.1.

Prerequisites

  • Lua 5.1
  • Metalua >= 0.7
  • Penlight ~> 0.9

Installation

$ luarocks install --local formatter

How does it work?

Library

$ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> formatter = require 'formatter'
> code = [[do
>> local var = 
>> 42
>> end]]
> formattedcode = formatter.indentcode(code, '\n', true, '  ')
> print( formattedcode )
do
  local var =
    42
end

Command line

$ cat sample.lua
do
local var =
42
end
$ luaformatter sample.lua
do
  local var =
    42
end

Want more options?

$ luaformatter --help
Formats Lua code.
  -a, --autosave Flush formatted Lua in given file instead of stdout.
  -s, --spaces (default 2) Spaces to use as indentation.
  -t, --tabs   (default 0) Tabulation(s) to use as indentation.
  -d, --delimiter (default unix) Type of new line to detect and use while formatting:
    * unix: '\n' LF Line feed.
    * windows: '\r\n' CR+LF
    * mac: '\r' CR Carriage Return of Macs before OSX.
  -h, --help This help.
  [files] Files to format.

About

Beautifies Lua code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages