Skip to content

Commit cbf864e

Browse files
committed
docs(#2934): lint and check scripts, rewrite luals check script following upstream changes
1 parent ca2c70f commit cbf864e

3 files changed

Lines changed: 44 additions & 34 deletions

File tree

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ check: luals
1212
#
1313
# subtasks
1414
#
15+
# TODO #3241 ensure that decorator is checked - all meta should be valid
1516
luacheck:
16-
luacheck --codes --quiet lua --exclude-files "**/_meta/**"
17+
luacheck --codes --quiet lua --exclude-files "**/_meta/api_decorator.lua"
18+
luacheck --codes --quiet scripts
1719

18-
# --diagnosis-as-error does not function for workspace, hence we post-process the output
1920
style-check:
20-
@scripts/luals-check.sh codestyle-check
21+
scripts/luals-check.sh codestyle-check
2122

2223
style-doc:
2324
scripts/doc-comments.sh
2425

2526
luals:
26-
@scripts/luals-check.sh
27+
scripts/luals-check.sh
2728

2829
#
2930
# fixes

scripts/gen_vimdoc_config.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ for _, m in ipairs(srcs) do
5252
srcs_by_name[name] = m
5353
end
5454

55-
---@diagnostic disable-next-line: undefined-doc-name
56-
--- @type table<string,nvim.gen_vimdoc.Config>
55+
-- @type table<string,nvim.gen_vimdoc.Config>
5756
local config = {
5857
all = {
5958
filename = "nvim-tree-lua.txt",

scripts/luals-check.sh

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
11
#!/usr/bin/env sh
22

3-
# Performs a lua-language-server check on all files.
4-
# luals-out/check.json will be produced on any issues, returning 1.
5-
# Outputs only check.json to stdout, all other messages to stderr, to allow jq etc.
3+
# Performs a lua-language-server check on all lua files.
64
# $VIMRUNTIME specifies neovim runtime path, defaults to "/usr/share/nvim/runtime" if unset.
75
#
86
# Call with codestyle-check param to enable only codestyle-check
7+
#
8+
# lua-language-server is inconsisent about which parameters must be absolute paths therefore we pass every path as absolute
9+
10+
if [ $# -eq 1 ] && [ "${1}" != "codestyle-check" ] || [ $# -gt 1 ] ; then
11+
echo "usage: ${0} [codestyle-check]" 1>&2
12+
exit 1
13+
fi
14+
15+
DIR_NVT="${PWD}"
16+
17+
if [ ! -f "${DIR_NVT}/scripts/luals-check.sh" ]; then
18+
echo "Must be run from nvim-tree root" 1>&2
19+
exit 1
20+
fi
921

1022
if [ -z "${VIMRUNTIME}" ]; then
1123
export VIMRUNTIME="/usr/share/nvim/runtime"
24+
echo "Defaulting to VIMRUNTIME=${VIMRUNTIME}"
25+
fi
26+
27+
if [ ! -d "${VIMRUNTIME}" ]; then
28+
echo "\$VIMRUNTIME=${VIMRUNTIME} not found" 1>&2
29+
exit 1
1230
fi
1331

14-
DIR_SRC="${PWD}/lua"
15-
DIR_OUT="${PWD}/luals-out"
16-
FILE_LUARC="${DIR_OUT}/luarc.json"
32+
DIR_OUT="${DIR_NVT}/luals-out"
33+
LUARC="${DIR_OUT}/luarc.json"
34+
RC=0
1735

18-
# clear output
36+
# clear previous output
1937
rm -rf "${DIR_OUT}"
2038
mkdir "${DIR_OUT}"
2139

40+
# create the luarc.json for the requested check
2241
case "${1}" in
2342
"codestyle-check")
2443
jq \
2544
'.diagnostics.neededFileStatus[] = "None" | .diagnostics.neededFileStatus."codestyle-check" = "Any"' \
26-
"${PWD}/.luarc.json" > "${FILE_LUARC}"
45+
"${DIR_NVT}/.luarc.json" > "${LUARC}"
2746

2847
;;
2948
*)
30-
cp "${PWD}/.luarc.json" "${FILE_LUARC}"
49+
cp "${DIR_NVT}/.luarc.json" "${LUARC}"
3150
;;
3251
esac
3352

34-
# execute inside lua directory to prevent luals itself from being checked
35-
OUT=$(lua-language-server --check="${DIR_SRC}" --configpath="${FILE_LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error)
36-
RC=$?
37-
38-
echo "${OUT}" >&2
53+
for SRC in lua scripts; do
54+
DIR_SRC="${DIR_NVT}/${SRC}"
55+
FILE_OUT="${DIR_OUT}/out.${SRC}.log"
56+
echo "Checking ${SRC}/"
3957

40-
if [ $RC -ne 0 ]; then
41-
echo "failed with RC=$RC"
42-
exit $RC
43-
fi
58+
lua-language-server --check="${DIR_SRC}" --configpath="${LUARC}" --checklevel=Information --logpath="${DIR_OUT}" --loglevel=error 2>&1 | tee "${FILE_OUT}"
4459

45-
# any output is a fail
46-
case "${OUT}" in
47-
*Diagnosis\ completed,\ no\ problems\ found*)
48-
exit 0
49-
;;
50-
*)
51-
cat "${DIR_OUT}/check.json"
52-
exit 1
53-
;;
54-
esac
60+
if ! grep --quiet "Diagnosis completed, no problems found" "${FILE_OUT}"; then
61+
RC=1
62+
fi
63+
done
5564

65+
exit "${RC}"

0 commit comments

Comments
 (0)