Skip to content

Commit

Permalink
build: enable lintlua for test/ dir
Browse files Browse the repository at this point in the history
Problem:
Not all Lua code is checked by stylua. Automating code-style is an
important mechanism for reducing time spent on accidental
(non-essential) complexity.

Solution:
- Enable stylua for entire `test/` directory.
- Exclude these high-churn files until this issue is resolved: JohnnyMorganz/StyLua#829
  ```
  test/functional/ui/decorations_spec.lua  | 3560 ++++++++++++++++++++++++++++++++++++----------------
  test/functional/ui/float_spec.lua        | 5826 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
  test/functional/ui/multigrid_spec.lua    | 1349 ++++++++++++++------
  ```
- Make surgical changes to these files (or add `stylua: ignore` in some
  small scopes) to improve the result:
  ```
  test/functional/vimscript/msgpack_functions_spec.lua | 1414 +++++++++++++++------
  test/functional/api/buffer_spec.lua                  | 1389 +++++++++++----------
  test/functional/api/vim_spec.lua                     | 2740 +++++++++++++++++++++++-----------------
  ```
- These "high churn" files are NOT excluded because the changes are
  largely an improvement:
  ```
  test/functional/plugin/lsp_spec.lua      | 2198 ++++++++++++++++++---------------
  test/functional/plugin/shada_spec.lua    | 4078 +++++++++++++++++++++++++++++++++++-------------------------
  test/functional/ui/cmdline_spec.lua      | 1199 +++++++++++-------
  test/functional/ui/popupmenu_spec.lua    | 1267 +++++++++++--------
  test/functional/ui/messages_spec.lua     | 1643 +++++++++++++++---------
  ```
- TODO: how to check "all directories"? With `GLOB_DIRS *` and `/.deps/` (or
  `.deps/`) in `.styluaignore`, Lua code in `.deps/` is still checked...
  • Loading branch information
justinmk authored and cleong14 committed Jan 16, 2024
1 parent 142310c commit 1784350
Show file tree
Hide file tree
Showing 6 changed files with 2,290 additions and 1,822 deletions.
7 changes: 5 additions & 2 deletions .styluaignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/build
/build/
/.deps/
/runtime/lua/coxpcall.lua
/runtime/lua/vim/_meta
/runtime/lua/vim/re.lua

/test/functional
test/functional/ui/decorations_spec.lua
test/functional/ui/float_spec.lua
test/functional/ui/multigrid_spec.lua
/test/functional/fixtures/lua/syntax_error.lua
/test/functional/legacy/030_fileformats_spec.lua
/test/functional/legacy/044_099_regexp_multibyte_magic_spec.lua
Expand Down
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ endif()
find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED})
find_program(STYLUA_PRG stylua ${LINT_REQUIRED})

set(STYLUA_DIRS runtime scripts src test/unit)
set(STYLUA_DIRS runtime scripts src test)

add_glob_target(
TARGET lintlua-luacheck
COMMAND $<TARGET_FILE:nvim>
FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr luacheck -q
GLOB_DIRS runtime scripts src test
GLOB_PAT *.lua
TOUCH_STRATEGY SINGLE)
TOUCH_STRATEGY PER_DIR)
add_dependencies(lintlua-luacheck lua-dev-deps)

add_glob_target(
Expand All @@ -244,7 +244,7 @@ add_glob_target(
FLAGS --color=always --check --respect-ignores
GLOB_DIRS ${STYLUA_DIRS}
GLOB_PAT *.lua
TOUCH_STRATEGY SINGLE)
TOUCH_STRATEGY PER_DIR)

add_custom_target(lintlua)
add_dependencies(lintlua lintlua-luacheck lintlua-stylua)
Expand All @@ -255,7 +255,7 @@ add_glob_target(
FLAGS -x -a
GLOB_DIRS scripts
GLOB_PAT *.sh
TOUCH_STRATEGY SINGLE)
TOUCH_STRATEGY PER_DIR)

add_custom_target(lintcommit
COMMAND $<TARGET_FILE:nvim> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
Expand All @@ -270,7 +270,8 @@ add_glob_target(
COMMAND ${STYLUA_PRG}
FLAGS --respect-ignores
GLOB_DIRS ${STYLUA_DIRS}
GLOB_PAT *.lua)
GLOB_PAT *.lua
TOUCH_STRATEGY PER_DIR)

add_custom_target(format)
add_dependencies(format formatc formatlua)
Expand Down
Loading

0 comments on commit 1784350

Please sign in to comment.