Skip to content

chore: use builtin EmmyLuaCodeStyle for style checking #3084

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

Merged
merged 19 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ end_of_line = lf
[nvim-tree-lua.txt]
max_line_length = 78

# keep these in sync with .luarc.json
# .editorconfig is used within nvim, overriding .luarc.json
# .luarc.json is used by style check
[*.lua]
indent_style = space
max_line_length = 140
Expand Down
63 changes: 24 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,25 @@ jobs:
strategy:
matrix:
lua_version: [ 5.1 ]
luacheck_version: [ 1.2.0 ]

steps:
- uses: actions/checkout@v4
- name: checkout
uses: actions/checkout@v4

- uses: leafo/gh-actions-lua@v11
- name: install lua ${{ matrix.lua_version }}
uses: leafo/gh-actions-lua@v11
with:
luaVersion: ${{ matrix.lua_version }}

- uses: leafo/gh-actions-luarocks@v4
- name: install luarocks
uses: leafo/gh-actions-luarocks@v5

- run: luarocks install luacheck 1.1.1
- name: install luacheck ${{ matrix.luacheck_version }}
run: luarocks install luacheck ${{ matrix.luacheck_version }}

- run: make lint

style:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ matrix.emmy_lua_code_style_version }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

strategy:
matrix:
emmy_lua_code_style_version: [ 1.5.6 ]

steps:
- uses: actions/checkout@v4

- name: install emmy_lua_code_style
run: |
mkdir -p CodeFormat
curl -L "https://github.com/CppCXY/EmmyLuaCodeStyle/releases/download/${{ matrix.emmy_lua_code_style_version }}/linux-x64.tar.gz" | tar zx --directory CodeFormat

- run: echo "CodeFormat/linux-x64/bin" >> "$GITHUB_PATH"

- run: make style

- run: make style-doc

check:
runs-on: ubuntu-latest

Expand All @@ -69,26 +49,31 @@ jobs:
strategy:
matrix:
nvim_version: [ stable, nightly ]
luals_version: [ 3.11.0 ]
luals_version: [ 3.13.9 ]

env:
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime

steps:
- uses: actions/checkout@v4
- name: checkout
uses: actions/checkout@v4

- uses: rhysd/action-setup-vim@v1
- name: install nvim ${{ matrix.nvim_version }}
uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: ${{ matrix.nvim_version }}

- name: install luals
- name: install lua-language-server ${{ matrix.luals_version }}
run: |
mkdir -p luals
curl -L "https://github.com/LuaLS/lua-language-server/releases/download/${{ matrix.luals_version }}/lua-language-server-${{ matrix.luals_version }}-linux-x64.tar.gz" | tar zx --directory luals
echo "luals/bin" >> "$GITHUB_PATH"

- run: echo "luals/bin" >> "$GITHUB_PATH"

- name: make check
env:
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime
run: make check
- run: make check

- run: make help-check

- run: make style

- run: make style-doc
13 changes: 12 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"runtime.version.luals-check-only": "Lua 5.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses a better jq solution in script.

"workspace": {
"library": [
"$VIMRUNTIME/lua/vim",
"${3rd}/luv/library"
]
},
"format": {
"defaultConfig": {
"indent_style": "space",
"max_line_length": "140",
"indent_size": "2",
"continuation_indent": "2",
"quote_style": "double",
"call_arg_parentheses": "always",
"space_before_closure_open_parenthesis": "false",
"align_continuous_similar_call_args": "true"
}
},
"diagnostics": {
"libraryFiles": "Disable",
"globals": [],
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Language server: [luals](https://luals.github.io)

Lint: [luacheck](https://github.com/lunarmodules/luacheck/)

Style: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeCheck`
Style Fixing: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeCheck`

nvim-tree.lua migrated from stylua to EmmyLuaCodeStyle ~2024/10. `vim.lsp.buf.format()` may be used as it is the default formatter for luals
nvim-tree.lua migrated from stylua to EmmyLuaCodeStyle ~2024/10. `vim.lsp.buf.format()` may be used as it is the default formatter for luals, using an embedded [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle)

You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks`

Expand All @@ -36,14 +36,14 @@ make lint

## style

1. Runs CodeCheck using `.editorconfig` settings
1. Runs lua language server `codestyle-check` only, using `.luarc.json` settings
1. Runs `scripts/doc-comments.sh` to validate annotated documentation

```sh
make style
```

You can automatically fix `CodeCheck` issues via:
You can automatically fix style issues using `CodeCheck`:

```sh
make style-fix
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ luacheck:

# --diagnosis-as-error does not function for workspace, hence we post-process the output
style-check:
CodeFormat check --config .editorconfig --diagnosis-as-error --workspace lua
@scripts/luals-check.sh codestyle-check

style-doc:
scripts/doc-comments.sh
Expand Down
10 changes: 6 additions & 4 deletions lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ function Explorer:reload(node, project)
end

local abs = utils.path_join({ cwd, name })
---@type uv.fs_stat.result|nil
local stat = vim.loop.fs_lstat(abs)

-- path incorrectly specified as an integer
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch

local filter_reason = self.filters:should_filter_as_reason(abs, stat, filter_status)
if filter_reason == FILTER_REASON.none then
Expand Down Expand Up @@ -373,8 +374,9 @@ function Explorer:populate_children(handle, cwd, node, project, parent)
if Watcher.is_fs_event_capable(abs) then
local profile = log.profile_start("populate_children %s", abs)

---@type uv.fs_stat.result|nil
local stat = vim.loop.fs_lstat(abs)
-- path incorrectly specified as an integer
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result of lua-language-server upgrade

local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
local child = node_factory.create({
Expand Down
23 changes: 19 additions & 4 deletions scripts/luals-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# luals-out/check.json will be produced on any issues, returning 1.
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
#
# Call with codestyle-check param to enable only codestyle-check

if [ -z "${VIMRUNTIME}" ]; then
export VIMRUNTIME="/usr/share/nvim/runtime"
Expand All @@ -17,11 +19,24 @@ FILE_LUARC="${DIR_OUT}/luarc.json"
rm -rf "${DIR_OUT}"
mkdir "${DIR_OUT}"

# Uncomment runtime.version for strict neovim baseline 5.1
# It is not set normally, to prevent luals loading 5.1 and 5.x, resulting in both versions being chosen on vim.lsp.buf.definition()
cat "${PWD}/.luarc.json" | sed -E 's/.luals-check-only//g' > "${FILE_LUARC}"
case "${1}" in
"codestyle-check")
jq \
'.diagnostics.neededFileStatus[] = "None" | ''.diagnostics.neededFileStatus."codestyle-check" = "Any"' \
"${PWD}/.luarc.json" > "${FILE_LUARC}"

# execute inside lua to prevent luals itself from being checked
;;
*)
# Add runtime.version for strict neovim baseline 5.1
# It is not set normally, to prevent luals loading 5.1 and 5.x, resulting in both versions being chosen on vim.lsp.buf.definition
jq \
'."runtime.version" = "Lua 5.1"' \
"${PWD}/.luarc.json" > "${FILE_LUARC}"

;;
esac

# execute inside lua directory to prevent luals itself from being checked
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${FILE_LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
RC=$?

Expand Down
Loading