Skip to content
forked from neovim/neovim

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 committed Dec 7, 2023
1 parent 3198598 commit 4b8df9b
Show file tree
Hide file tree
Showing 371 changed files with 40,540 additions and 25,876 deletions.
4 changes: 2 additions & 2 deletions .styluaignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/build
/build/
/.deps/
/runtime/lua/coxpcall.lua
/runtime/lua/vim/_meta
/runtime/lua/vim/re.lua

/test/functional
/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
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ add_glob_target(
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(
TARGET lintlua-stylua
COMMAND ${STYLUA_PRG}
FLAGS --color=always --check --respect-ignores
GLOB_DIRS runtime/ scripts/ src/ test/unit/
GLOB_DIRS runtime/ scripts/ src/ test/
GLOB_PAT *.lua
TOUCH_STRATEGY SINGLE)
TOUCH_STRATEGY PER_DIR)

add_custom_target(lintlua)
add_dependencies(lintlua lintlua-luacheck lintlua-stylua)
Expand All @@ -246,7 +246,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 @@ -260,8 +260,9 @@ add_glob_target(
TARGET formatlua
COMMAND ${STYLUA_PRG}
FLAGS --respect-ignores
GLOB_DIRS runtime/ scripts/ src/ test/unit/
GLOB_PAT *.lua)
GLOB_DIRS runtime/ scripts/ src/ test/
GLOB_PAT *.lua
TOUCH_STRATEGY PER_DIR)

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

0 comments on commit 4b8df9b

Please sign in to comment.