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 e5fde80fab.
* 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
This commit is contained in:
parent
c09ff35de5
commit
44d9b58f11
@ -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
|
||||
|
||||
63
.github/workflows/ci.yml
vendored
63
.github/workflows/ci.yml
vendored
@ -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
|
||||
|
||||
@ -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
.luarc.json
13
.luarc.json
@ -1,12 +1,23 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
|
||||
"runtime.version.luals-check-only": "Lua 5.1",
|
||||
"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": [],
|
||||
|
||||
@ -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`
|
||||
|
||||
@ -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
|
||||
|
||||
2
Makefile
2
Makefile
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
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({
|
||||
|
||||
@ -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"
|
||||
@ -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=$?
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user