aboutsummaryrefslogtreecommitdiffstats
path: root/.github
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2025-04-21 18:27:20 +0200
committerJustin M. Keyes <justinkz@gmail.com>2025-04-21 18:37:46 +0200
commit0e29bf5ed68f9a67222c834ec44e70c8f884bde7 (patch)
tree270a1c25e93b8d14ded593526d518dec64fe080f /.github
parentdocs: update configs.md (diff)
downloadnvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar.gz
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar.bz2
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar.lz
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar.xz
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.tar.zst
nvim-lspconfig-0e29bf5ed68f9a67222c834ec44e70c8f884bde7.zip
ci(lint): enforce "Lsp" command name prefix
Diffstat (limited to '.github')
-rw-r--r--.github/ci/run_sanitizer.sh59
1 files changed, 44 insertions, 15 deletions
diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh
index 9b560d84..6f1577da 100644
--- a/.github/ci/run_sanitizer.sh
+++ b/.github/ci/run_sanitizer.sh
@@ -1,24 +1,53 @@
#!/usr/bin/env bash
+
+# USAGE: To run locally:
+# bash .github/ci/run_sanitizer.sh origin/master HEAD
+
set -e
REF_BRANCH="$1"
PR_BRANCH="$2"
-# checks for added lines that contain search pattern and prints them
-SEARCH_PATTERN='(path\.dirname|fn\.cwd)'
+# Enforce buffer-local commands.
+_check_cmd_buflocal() {
+ if git grep -P 'nvim_create_user_command' -- 'lsp/*.lua' ; then
+ echo
+ echo 'Define commands with nvim_buf_create_user_command (buffer-local), not nvim_create_user_command'
+ exit 1
+ fi
+}
+
+# Enforce "Lsp" prefix on all user commands.
+_check_lsp_cmd_prefix() {
+ local exclude='tinymist'
+ if git grep -P 'nvim_buf_create_user_command' -- 'lsp/*.lua' | grep -v "$exclude" | grep --color -v Lsp ; then
+ echo
+ echo 'Command names must start with "Lsp" prefix'
+ exit 1
+ fi
+}
+
+_check_deprecated_utils() {
+ # checks for added lines that contain search pattern and prints them
+ SEARCH_PATTERN='(path\.dirname|fn\.cwd)'
+
+ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '(configs|utils)\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
+ echo
+ echo 'String "dirname" found. There is a high risk that this might contradict the directive:'
+ echo '"Do not use vim.fn.cwd or util.path.dirname in root_dir".'
+ echo "see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#adding-a-server-to-lspconfig."
+ exit 1
+ fi
-if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '(configs|utils)\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
- echo
- echo 'String "dirname" found. There is a high risk that this might contradict the directive:'
- echo '"Do not use vim.fn.cwd or util.path.dirname in root_dir".'
- echo "see: https://github.com/neovim/nvim-lspconfig/blob/master/CONTRIBUTING.md#adding-a-server-to-lspconfig."
- exit 1
-fi
+ SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor|util\.get_lsp_clients|util\.get_active_client_by_name)'
-SEARCH_PATTERN='(util\.path\.dirname|util\.path\.sanitize|util\.path\.exists|util\.path\.is_file|util\.path\.is_dir|util\.path\.join|util\.path\.iterate_parents|util\.path\.traverse_parents|util\.find_mercurial_ancestor|util\.find_node_modules_ancestor|util\.find_package_json_ancestor|util\.find_git_ancestor|util\.get_lsp_clients|util\.get_active_client_by_name)'
+ if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
+ echo
+ echo 'Do not use deprecated util functions: '"${SEARCH_PATTERN}"
+ exit 1
+ fi
+}
-if git diff --pickaxe-all -U0 -G "${SEARCH_PATTERN}" "${REF_BRANCH}" "${PR_BRANCH}" -- '*.lua' | grep -Ev '\.lua$' | grep -E "^\+.*${SEARCH_PATTERN}" ; then
- echo
- echo 'Do not use deprecated util functions: '"${SEARCH_PATTERN}"
- exit 1
-fi
+_check_cmd_buflocal
+_check_lsp_cmd_prefix
+_check_deprecated_utils