From 16008a64f6ab9309641f30b8a7c9a432f1649b9a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 26 Nov 2024 07:34:16 -0800 Subject: [PATCH] ci: check for deprecated util functions #3462 --- .github/ci/run_sanitizer.sh | 12 ++++++++++-- .github/workflows/lint.yml | 12 ++++++++++++ .github/workflows/sanitizer.yml | 14 -------------- CONTRIBUTING.md | 2 +- lua/lspconfig/util.lua | 4 +--- 5 files changed, 24 insertions(+), 20 deletions(-) delete mode 100644 .github/workflows/sanitizer.yml diff --git a/.github/ci/run_sanitizer.sh b/.github/ci/run_sanitizer.sh index 8630de3fb1..1f148ba25d 100644 --- a/.github/ci/run_sanitizer.sh +++ b/.github/ci/run_sanitizer.sh @@ -5,12 +5,20 @@ REF_BRANCH="$1" PR_BRANCH="$2" # checks for added lines that contain search pattern and prints them -SEARCH_PATTERN="(path\.dirname|fn\.cwd)" +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 add vim.fn.cwd or util.path.dirname in root_dir".' + 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)' + +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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7ee1244db8..def839e9c7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,18 @@ on: - master jobs: + deprecated-functions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + 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 + exit 1 + fi + luacheck: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml deleted file mode 100644 index 89fd51e3b5..0000000000 --- a/.github/workflows/sanitizer.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: "Dirname Checker" -on: [pull_request] -jobs: - disallowed-root-checker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - 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 - exit 1 - fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 212788a0be..e18932cbd8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,7 @@ reading your `config` source code, so the less indirection in your code, the mor * `root_dir`: function which returns the root of the project, used to decide if lspconfig should launch a new language server, or attach a previously launched server when you open a new buffer matching the filetype of the server. * See `:help lspconfig-new`. * See `vim.fs.root()` - * Do not use `vim.fn.cwd` or `util.path.dirname`. + * Do not use `vim.fn.cwd` or `vim.fs.dirname`. Additionally, these options are often useful: diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index dd6c57cfb9..041f56e65f 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -151,9 +151,7 @@ M.path = (function() end end - --- @generic T: string? - --- @param path T - --- @return T + ---@deprecated use `vim.fs.dirname` instead local function dirname(path) return vim.fs.dirname(path) end