luaformatter

command module
v0.0.0-...-86b0a68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

Lua formatter

Test codecov Go Report Card codebeat badge

Code formatting rules

Variables

The option alignment.variables will align list of variables.

local a  = 1  -- comment
local bb = 22 -- comment

local c = "short text" -- comment
Comments

Skipped space between a double hyphen and text will be revert. Semantic line (only hyphens) will not have the space.

--------------------------------
-- Description
-- params:  - input
--          - output
Tables

If you create an empty table or table with only key fields or table with one field they will be written in one line.

local t = {}
local t = {"one", "two", 3, 4, 5}
local t = {a = 1, b = 2, c = 3}

If you write more than five fields with only key then table will be written in multiline. Same behaviour will be if you write more than four fields with key and value. If the table is multiline then every field will have trailing comma.

local t = {
    "one",
    "two",
    3,
    4,
    5,
    "six",
}
local t = {
    a = 1,
    b = 2,
    c = 3,
    d = 4,
}

The option alignment.table will align table.

local t = {
    a      = 1,    -- comment
    ["bb"] = "bb", -- comment
    -- comment
    ccc    = "ccc",    -- comment
    dddeee = "dddeee", -- comment
    f = function()
        return 1
    end,
    g = 7, -- comment
    -- comment
}
Newline

If return statement is inside the block with other statements then a newline will be added before it.

function isFalse()
    return false
end

function calc(a, b)
    local c = a + b

    return c
end

If a function is inside the block with other statements then a newline will be added before it.

function isFalse()
    return false
end

isFalse()

If a function has parameters more than max line length then every parameter will be moved to the next line.

function very_long_name(
    very_long_name_parameter_1,
    very_long_name_parameter_2,
    very_long_name_parameter_3
)
    -- stuff
end

If a function call has parameters more than max line length then every parameter will be moved to the next line.

very_long_name_function_call(
    {a = 1, b = 2, c = 3},
    very_long_name_parameter,
    {
        a = 1,
        b = 2,
        c = 3,
        d = 4,
    }
)

Documentation

Overview

Copyright © 2020 Dmitry Stoletov <info@imega.ru>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL