AstroNvim / astrocommunity

A community repository of common plugin specifications
GNU General Public License v3.0
1.21k stars 240 forks source link

pack/lua: luacheck warns about accesing undefined variable 'vim' #302

Closed paxet closed 1 year ago

paxet commented 1 year ago

Starting with a base config from: https://github.com/AstroNvim/user_example Set up lua "pluging" from astrocommunity like so:

$ cat lua/user/plugins/community.lua
return {
  "AstroNvim/astrocommunity",
  { import = "astrocommunity.pack.lua" },
}

Start nvim and wait for plugins to be installed, and then quit. Open file lua/user/init.lua and use global "vim" variable like

  polish = function()
    -- Map 'Q' to force quit without saving files
    vim.cmd "cmap Q qa!"
  end,

luacheck will :warning: you with:

accessing undefined variable 'vim'

I've seen it can be added to diagnostics -> globals when setting up the lua_ls language server, but don't now how we can achieve it in our "plugin" for lua

mehalter commented 1 year ago

I went ahead and added a luacheck configuration from AstroNvim into the user example: https://github.com/AstroNvim/user_example/commit/8b8a9a035f3f409c95135d93abdada88d3a1ce3c

You can go ahead and create that file manually in your configuration to remove those errors. Hopefully this is better for future users :D

mehalter commented 1 year ago

Thanks for reporting this :)

mehalter commented 1 year ago

@windowsrefund if you are using ~/.config/astronvim you just want to make sure your luacheck file is in the workspace root of your project. So you probably want to put it in ~/.config/astronvim and not in the lua/user folder