Please note that this plugin is currently in alpha stage and still under active development. We encourage everyone to try it and give feedback, but we don't recommend it for production use yet.
Intro
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
This plugin adds support for the Lua language to Prettier.
Input
function deepcopy(orig) local orig_type = type(orig) local copy if orig_type == 'table' then; copy = {} for orig_key, orig_value in next, orig, nil do copy[deepcopy(orig_key)] = deepcopy(orig_value) end setmetatable( copy, deepcopy( getmetatable(orig))) else copy = orig end return copy end
Output
function deepcopy(orig) local orig_type = type(orig) local copy if orig_type == "table" then copy = {} for orig_key, orig_value in next, orig, nil do copy[deepcopy(orig_key)] = deepcopy(orig_value) end setmetatable(copy, deepcopy(getmetatable(orig))) else copy = orig end return copyend
Install
yarn:
yarn add --dev prettier @prettier/plugin-lua# or globallyyarn global add prettier @prettier/plugin-lua
Alternatively, "custom_file_extensions": ["lua"] can be added to the JsPrettier plugin user settings.
Contributing
If you're interested in contributing to the development of Prettier for Lua, you can follow the CONTRIBUTING guide from Prettier, as it all applies to this repository too.