Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: check for deprecated util functions #3462

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading