From 44ba712bc3015cce9b599d18f947d85a630e512b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 21 Apr 2025 13:43:00 -0700 Subject: ci(lint): use client:exec_cmd() #3755 Use `client:exec_cmd()` instead of calling `request("workspace/executeCommand")` directly. --- .github/ci/lint.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++ .github/ci/run_sanitizer.sh | 53 -------------------------------------- .github/workflows/lint.yml | 2 +- 3 files changed, 64 insertions(+), 54 deletions(-) create mode 100644 .github/ci/lint.sh delete mode 100644 .github/ci/run_sanitizer.sh (limited to '.github') diff --git a/.github/ci/lint.sh b/.github/ci/lint.sh new file mode 100644 index 00000000..38ea57eb --- /dev/null +++ b/.github/ci/lint.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# USAGE: To run locally: +# bash .github/ci/lint.sh origin/master HEAD + +set -e + +REF_BRANCH="$1" +PR_BRANCH="$2" + +# 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 +} + +# Enforce client:exec_cmd(). +_check_exec_cmd() { + if git grep -P 'workspace.executeCommand' -- 'lsp/*.lua' ; then + echo + echo 'Use client:exec_cmd() instead of calling request("workspace/executeCommand") directly. Example: lsp/pyright.lua' + 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 + + 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 +} + +_check_cmd_buflocal +_check_lsp_cmd_prefix +_check_exec_cmd +_check_deprecated_utils diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh deleted file mode 100644 index 6f1577da..00000000 --- a/.github/ci/run_sanitizer.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/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" - -# 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 - - 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 -} - -_check_cmd_buflocal -_check_lsp_cmd_prefix -_check_deprecated_utils diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 346ad478..20b9b6ae 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 ref: ${{ github.event.pull_request.head.sha }} - run: | - if ! bash .github/ci/run_sanitizer.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}; then + if ! bash .github/ci/lint.sh ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}; then exit 1 fi -- cgit v1.2.3-70-g09d2