Skip to content

Commit 44d9b58

Browse files
authored
chore: use builtin EmmyLuaCodeStyle for style checking (#3084)
* chore: sync EmmyLuaCodeStyle settings between .editorconfig and .luarc.json * chore: lua-language-server 3.11.0 -> 3.13.9 * chore: fix incorrect definition of vim.loop.fs_lstat * chore: add codestyle-check option to luals-check.sh * chore: use luals for style check * chore: use luals for style check * Revert "chore: use luals for style check" This reverts commit e5fde80. * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check * chore: use luals for style check
1 parent c09ff35 commit 44d9b58

File tree

7 files changed

+69
-53
lines changed

7 files changed

+69
-53
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ end_of_line = lf
77
[nvim-tree-lua.txt]
88
max_line_length = 78
99

10+
# keep these in sync with .luarc.json
11+
# .editorconfig is used within nvim, overriding .luarc.json
12+
# .luarc.json is used by style check
1013
[*.lua]
1114
indent_style = space
1215
max_line_length = 140

.github/workflows/ci.yml

+24-39
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,25 @@ jobs:
2020
strategy:
2121
matrix:
2222
lua_version: [ 5.1 ]
23+
luacheck_version: [ 1.2.0 ]
2324

2425
steps:
25-
- uses: actions/checkout@v4
26+
- name: checkout
27+
uses: actions/checkout@v4
2628

27-
- uses: leafo/gh-actions-lua@v11
29+
- name: install lua ${{ matrix.lua_version }}
30+
uses: leafo/gh-actions-lua@v11
2831
with:
2932
luaVersion: ${{ matrix.lua_version }}
3033

31-
- uses: leafo/gh-actions-luarocks@v4
34+
- name: install luarocks
35+
uses: leafo/gh-actions-luarocks@v5
3236

33-
- run: luarocks install luacheck 1.1.1
37+
- name: install luacheck ${{ matrix.luacheck_version }}
38+
run: luarocks install luacheck ${{ matrix.luacheck_version }}
3439

3540
- run: make lint
3641

37-
style:
38-
runs-on: ubuntu-latest
39-
40-
concurrency:
41-
group: ${{ github.workflow }}-${{ matrix.emmy_lua_code_style_version }}-${{ github.head_ref || github.ref_name }}
42-
cancel-in-progress: true
43-
44-
strategy:
45-
matrix:
46-
emmy_lua_code_style_version: [ 1.5.6 ]
47-
48-
steps:
49-
- uses: actions/checkout@v4
50-
51-
- name: install emmy_lua_code_style
52-
run: |
53-
mkdir -p CodeFormat
54-
curl -L "https://github.com/CppCXY/EmmyLuaCodeStyle/releases/download/${{ matrix.emmy_lua_code_style_version }}/linux-x64.tar.gz" | tar zx --directory CodeFormat
55-
56-
- run: echo "CodeFormat/linux-x64/bin" >> "$GITHUB_PATH"
57-
58-
- run: make style
59-
60-
- run: make style-doc
61-
6242
check:
6343
runs-on: ubuntu-latest
6444

@@ -69,26 +49,31 @@ jobs:
6949
strategy:
7050
matrix:
7151
nvim_version: [ stable, nightly ]
72-
luals_version: [ 3.11.0 ]
52+
luals_version: [ 3.13.9 ]
53+
54+
env:
55+
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime
7356

7457
steps:
75-
- uses: actions/checkout@v4
58+
- name: checkout
59+
uses: actions/checkout@v4
7660

77-
- uses: rhysd/action-setup-vim@v1
61+
- name: install nvim ${{ matrix.nvim_version }}
62+
uses: rhysd/action-setup-vim@v1
7863
with:
7964
neovim: true
8065
version: ${{ matrix.nvim_version }}
8166

82-
- name: install luals
67+
- name: install lua-language-server ${{ matrix.luals_version }}
8368
run: |
8469
mkdir -p luals
8570
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
71+
echo "luals/bin" >> "$GITHUB_PATH"
8672
87-
- run: echo "luals/bin" >> "$GITHUB_PATH"
88-
89-
- name: make check
90-
env:
91-
VIMRUNTIME: /home/runner/nvim-${{ matrix.nvim_version }}/share/nvim/runtime
92-
run: make check
73+
- run: make check
9374

9475
- run: make help-check
76+
77+
- run: make style
78+
79+
- run: make style-doc

.luarc.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
3-
"runtime.version.luals-check-only": "Lua 5.1",
43
"workspace": {
54
"library": [
65
"$VIMRUNTIME/lua/vim",
76
"${3rd}/luv/library"
87
]
98
},
9+
"format": {
10+
"defaultConfig": {
11+
"indent_style": "space",
12+
"max_line_length": "140",
13+
"indent_size": "2",
14+
"continuation_indent": "2",
15+
"quote_style": "double",
16+
"call_arg_parentheses": "always",
17+
"space_before_closure_open_parenthesis": "false",
18+
"align_continuous_similar_call_args": "true"
19+
}
20+
},
1021
"diagnostics": {
1122
"libraryFiles": "Disable",
1223
"globals": [],

CONTRIBUTING.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Language server: [luals](https://luals.github.io)
1212

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

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

17-
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
17+
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)
1818

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

@@ -36,14 +36,14 @@ make lint
3636

3737
## style
3838

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

4242
```sh
4343
make style
4444
```
4545

46-
You can automatically fix `CodeCheck` issues via:
46+
You can automatically fix style issues using `CodeCheck`:
4747

4848
```sh
4949
make style-fix

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ luacheck:
1717

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

2222
style-doc:
2323
scripts/doc-comments.sh

lua/nvim-tree/explorer/init.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ function Explorer:reload(node, project)
214214
end
215215

216216
local abs = utils.path_join({ cwd, name })
217-
---@type uv.fs_stat.result|nil
218-
local stat = vim.loop.fs_lstat(abs)
217+
218+
-- path incorrectly specified as an integer
219+
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch
219220

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

376-
---@type uv.fs_stat.result|nil
377-
local stat = vim.loop.fs_lstat(abs)
377+
-- path incorrectly specified as an integer
378+
local stat = vim.loop.fs_lstat(abs) ---@diagnostic disable-line param-type-mismatch
379+
378380
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
379381
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
380382
local child = node_factory.create({

scripts/luals-check.sh

+19-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# luals-out/check.json will be produced on any issues, returning 1.
55
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.
66
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
7+
#
8+
# Call with codestyle-check param to enable only codestyle-check
79

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

20-
# Uncomment runtime.version for strict neovim baseline 5.1
21-
# 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()
22-
cat "${PWD}/.luarc.json" | sed -E 's/.luals-check-only//g' > "${FILE_LUARC}"
22+
case "${1}" in
23+
"codestyle-check")
24+
jq \
25+
'.diagnostics.neededFileStatus[] = "None" | .diagnostics.neededFileStatus."codestyle-check" = "Any"' \
26+
"${PWD}/.luarc.json" > "${FILE_LUARC}"
2327

24-
# execute inside lua to prevent luals itself from being checked
28+
;;
29+
*)
30+
# Add runtime.version for strict neovim baseline 5.1
31+
# 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
32+
jq \
33+
'."runtime.version" = "Lua 5.1"' \
34+
"${PWD}/.luarc.json" > "${FILE_LUARC}"
35+
36+
;;
37+
esac
38+
39+
# execute inside lua directory to prevent luals itself from being checked
2540
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${FILE_LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
2641
RC=$?
2742

0 commit comments

Comments
 (0)