Skip to content

stylua -> EmmyLuaCodeStyle #2931

Closed
@alex-courtis

Description

@alex-courtis

What

EmmyLuaCodeStyle is the built in formatter for lua-language-server: https://luals.github.io/wiki/settings/#format

It can be invoked via vim.lsp.buf.format() and has a command line tool CodeFormat.

Why

The stylua nvim plugin is finicky and outdated. It is a barrier to entry for devs who usually end up using style and style-fix, often not seeing style issues until CI, which is not run for first time contributors.

Differences

List, table and comment formatting is more readable:

local WATCHED_FILES = {
  "FETCH_HEAD", -- remote ref
  "HEAD",       -- local ref
  "HEAD.lock",  -- HEAD will not always be updated e.g. revert
  "config",     -- user config
  "index",      -- staging area
}
M.HIGHLIGHT_GROUPS = {
  -- Standard
  { group = "NvimTreeNormal",                  link = "Normal" },
  { group = "NvimTreeNormalFloat",             link = "NormalFloat" },
  { group = "NvimTreeNormalFloatBorder",       link = "FloatBorder" },
  { group = "NvimTreeNormalNC",                link = "NvimTreeNormal" },

call_parentheses = "None" cannot be implemented, as per stylua single table/string argument with no following call. Always using parenthesis (needs 1.5.4) results in more readable code. This only really affects require calls.

Formatting may only be disabled via comment, not re-enabled.

space_before_closure_open_parenthesis = true (default) looks a little more readable, however it's not really the lua standard.

How

Do this when there are no outstanding large PRs.

.editorconfig is used with extensions. It's automatically picked up by nvim, and must be specified on the CLI.

  1. Add to .editorconfig, changes to defaults only
  2. Move default_on_attach to the end, prepending ---@format disable
  3. CodeFormat format -w lua -c .editorconfig
  4. Remove stylua
  5. Update Makefile
  6. Commit and merge
  7. Update Doc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions