Skip to content

Commit

Permalink
ci: check for deprecated util functions neovim#3462
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk authored Nov 26, 2024
1 parent 3eaab29 commit 16008a6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
12 changes: 10 additions & 2 deletions .github/ci/run_sanitizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/sanitizer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 1 addition & 3 deletions lua/lspconfig/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16008a6

Please sign in to comment.