Home Explore Blog CI



neovim

4th chunk of `CMakeLists.txt`
c9e8d1967e6c1cd054d76a095551faf172155a7dd991f9900000000100000972
 Lint
option(CI_LINT "Abort if lint programs not found" OFF)
if(CI_LINT)
  set(LINT_REQUIRED "REQUIRED")
endif()
find_program(SHELLCHECK_PRG shellcheck ${LINT_REQUIRED})
mark_as_advanced(SHELLCHECK_PRG)
find_program(STYLUA_PRG stylua ${LINT_REQUIRED})
mark_as_advanced(STYLUA_PRG)

set(STYLUA_DIRS runtime scripts src test contrib)

add_glob_target(
  TARGET lintlua-luacheck
  COMMAND $<TARGET_FILE:nvim_bin>
  FLAGS -ll ${PROJECT_SOURCE_DIR}/test/lua_runner.lua ${CMAKE_BINARY_DIR}/usr/share/lua/5.1 luacheck -q
  GLOB_DIRS runtime scripts src test
  GLOB_PAT *.lua
  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 ${STYLUA_DIRS}
  GLOB_PAT *.lua
  TOUCH_STRATEGY PER_DIR)
# Special handling of some files (which are ignored in .styluaignore).
# Workaround because stylua doesn't(?) support file-specific settings.
add_custom_target(lintlua-stylua2
  COMMAND ${STYLUA_PRG} --config-path "${PROJECT_SOURCE_DIR}/.stylua2.toml"
    --color=always --check
    "${PROJECT_SOURCE_DIR}/test/functional/ui/decorations_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/float_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/multigrid_spec.lua"
)
add_dependencies(lintlua-stylua lintlua-stylua2)

add_custom_target(lintlua)
add_dependencies(lintlua lintlua-luacheck lintlua-stylua)

add_glob_target(
  TARGET lintsh
  COMMAND ${SHELLCHECK_PRG}
  FLAGS -x -a
  GLOB_DIRS scripts
  GLOB_PAT *.sh
  TOUCH_STRATEGY PER_DIR)

add_custom_target(lintcommit
  COMMAND $<TARGET_FILE:nvim_bin> -u NONE -l ${PROJECT_SOURCE_DIR}/scripts/lintcommit.lua main)
add_dependencies(lintcommit nvim_bin)

add_custom_target(lint)
add_dependencies(lint lintc lintlua lintsh)

# Format
add_glob_target(
  TARGET formatlua
  COMMAND ${STYLUA_PRG}
  FLAGS --respect-ignores
  GLOB_DIRS ${STYLUA_DIRS}
  GLOB_PAT *.lua
  TOUCH_STRATEGY PER_DIR)
# Special handling of some files (which are ignored in .styluaignore).
# Workaround because stylua doesn't(?) support file-specific settings.
add_custom_target(formatlua2
  COMMAND ${STYLUA_PRG} --config-path "${PROJECT_SOURCE_DIR}/.stylua2.toml"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/decorations_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/float_spec.lua"
    "${PROJECT_SOURCE_DIR}/test/functional/ui/multigrid_spec.lua"

Title: CMake Configuration - Linting and Formatting Targets
Summary
This section of the CMake configuration defines targets for linting and formatting code. It finds the `shellcheck` and `stylua` programs and creates targets to run them on shell scripts and Lua code, respectively. It uses `luacheck` for additional Lua linting. It sets up special handling for some files ignored by stylua via a custom configuration file. It also includes a target for linting commit messages and a general `lint` target that depends on all other linting targets. Finally, it defines a target to format Lua code using stylua, including the files with special handling.