python中的lua代码格式化程序!
luastyle的Python项目详细描述
用python编写的lua代码格式化程序。
安装:
该软件包可以通过pip安装:
$ python3.6 -m pip install luastyle
它将安装shell命令“luastyle”。
选项
这些是命令行标志:
用法:luastyle[选项]file_或_dir1 file_或_dir2…
CLI Options: --version Show program's version number and exit -h, --help Show this help message and exit -i, --in-place Write output in-place, replacing input --config=F Path to config file --config-generate Generate a default config file --type=EXT File extension to indent (can be repeated) [lua] -d, --debug Enable debugging messages -j N, --jobs=N Number of parallel jobs in recursive mode -C, --check-bytecode Check lua bytecode with luac, $LUAC can also be set to use a specific compiler Beautifier Options: -a, --space-around-assign Ensure one space before and after assign op "=" -c S, --indent-char=S Indentation character [" "] -f, --check-field-list Format field-list (table) -l N, --indent-level=N Initial indentation level [0] -p, --check-param-list Format var-list, name-list and expr-list -s N, --indent-size=N Indentation size [2] -t, --indent-with-tabs Indent with tabs, overrides -s and -c --close-on-lowest-level If several closing tokens, indent on lowest token level -F N, --func-cont-level=N Continuation lines level in function arguments [2] -I N, --if-cont-level=N If statement continuation line level [2] -M, --check-line-comment-text Ensure that line comments text is started by at least N char -N N, --com-txt-space-size=N If --check-line-comment-text is enabled, configure the number of spaces [1] -S, --skip-sem-colon Skip all semi-colon after statements --break-if Break mono-line if statement --break-while In while and repeat statement, ensure newline after "do" or "repeat" and before "end" or "until" keyword --break-all Enable --break-if --break-for and --break-while and before "end" or "until" keyword --force-call-spaces Force spaces before opening parenthesis in function call [0] --call-spaces-size=N If --force-call-spaces is enabled, configure the number of spaces --strict Enable all features
从环境或.luastylerc加载设置
除了cli参数外,您还可以通过:
- luastyle_conf环境变量指向配置文件
- 位于用户目录中的.luastylerc文件
选项示例
函数参数中的连续行级别(-f)
-F N, --func-cont-level=N Continuation lines level in function arguments [2]
给定:
localfunctionprocess(param_1,param_2,param_3,param_4,param_5,param_6)returndo_something()end
$ luastyle -c "." -F 2 source.lua
localfunctionprocess(param_1,param_2,param_3,....param_4,param_5,param_6)..returndo_something()end
break if语句选项(–break if)
给定:
ifconditionthenreturnsuccess()elsereturnfailure()end
$ luastyle --break-if source.lua
ifconditionthenreturnsuccess()elsereturnfailure()end
格式表字段列表(-f)
- 此选项确保:
- 表('、'或';'中的字段分隔符是尾随的
- 逗号前面有一个空格,后面有两个空格
放在左大括号后面的注释中的关键字‘@luastyle.disable 将禁用相关表中的此功能。
给定:
localdays={monday=1,tuesday=2,wednesday=3}localn={1,2,3}localt={-- @luastyle.disable1,2,4,8,16,32}
$ luastyle -f source.lua
localdays={monday=1,tuesday=2,wednesday=3}localn={1,2,3}localt={-- @luastyle.disable1,2,4,8,16,32}
缩进关闭标记(–在最低级别关闭)
给定:
describe('must indent',function()done()end)
$ luastyle --close-on-lowest-level source.lua
describe('must indent',function()done()end)
$ luastyle source.lua
describe('must indent',function()done()end)
函数调用格式选项(–强制调用空间,–调用空间大小)
给定:
build(foo)
$ luastyle --force-call-spaces source.lua
build(foo)
$ luastyle --force-call-spaces --call-spaces-size=1 source.lua
build(foo)
注释格式选项(-m,-n)
可用选项有:
给定: