Skip to content

stylua -> EmmyLuaCodeStyle #2931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alex-courtis opened this issue Sep 28, 2024 · 2 comments · Fixed by #2932
Closed

stylua -> EmmyLuaCodeStyle #2931

alex-courtis opened this issue Sep 28, 2024 · 2 comments · Fixed by #2932

Comments

@alex-courtis
Copy link
Member

alex-courtis commented Sep 28, 2024

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
@alex-courtis
Copy link
Member Author

Close enough to stylua:

root = true

[*]
insert_final_newline = true
end_of_line = lf

[nvim-tree-lua.txt]
max_line_length = 78

[*.lua]
indent_style = space
max_line_length = 140
indent_size = 2

# EmmyLuaCodeStyle specific, see https://github.com/CppCXY/EmmyLuaCodeStyle/blob/master/lua.template.editorconfig
continuation_indent = 2
call_arg_parentheses = always
space_before_closure_open_parenthesis = false

Removing call_arg_parentheses = always results in only minor table/comment changes.

@alex-courtis
Copy link
Member Author

CppCXY/EmmyLuaCodeStyle#184 needed for proper check exit code

alex-courtis added a commit that referenced this issue Sep 29, 2024
* stylua -> EmmyLuaCodeStyle: config and doc

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle

* stylua -> EmmyLuaCodeStyle: call_arg_parentheses = always

* stylua -> EmmyLuaCodeStyle

* stylua -> EmmyLuaCodeStyle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant