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

Support for .luacheckrc configuration file. #92

Open
Yakehira opened this issue Sep 26, 2019 · 9 comments
Open

Support for .luacheckrc configuration file. #92

Yakehira opened this issue Sep 26, 2019 · 9 comments
Labels
enhancement New feature or request priority.low A low priority topic question User has a question

Comments

@Yakehira
Copy link

Support for .luacheckrc configuration file so that errors/warnings/globals etc can also be disabled over it and shared with other users properly instead of the current only way via settings.

@sumneko sumneko added the question User has a question label Sep 26, 2019
@sumneko
Copy link
Collaborator

sumneko commented Sep 26, 2019

I don't use luacheck, so the configuration is not universal.
You could set Lua.diagnostics.enable to false, and use luacheck instead of built-in diagnostic feature.

@Stanzilla
Copy link

Would still be lovely to have as an option :)

@Stanzilla
Copy link

Any news about maybe reconsidering this?

@Stanzilla
Copy link

@sumneko thoughts? as an alternative maybe https://github.com/Kampfkarren/selene Kampfkarren/selene#22

@sumneko sumneko added the enhancement New feature or request label Jul 26, 2020
@sumneko
Copy link
Collaborator

sumneko commented Jul 26, 2020

.luacheckrc is a special configuration file for luacheck. The diagnosis in my extension is implemented by myself and does not use luacheck . Therefore, most of the configurations in .Luacheckrc cannot be recognized.

Maybe when I'm free, I can support a small number of them, such as "defined global variables.".

@figsoda
Copy link

figsoda commented Oct 10, 2022

I was able to implement some basics for .luacheckrc in neovim, perhaps you can try something like this

https://github.com/figsoda/dotfiles/blob/58e993c2949a29fe3af85a932726244266da3cff/lib/nvim/plugins.lua#L297

@SwissalpS
Copy link

I understand that a full implementation would be a project of its own. Especially considering the directives such as std = "<popularproject>+max".

A minimal support for looking up the tree to find a .luacheckrc file and at least respecting the globals and read_globals tables in a minimal maner would eliminate a huge number of false-positives.

Question: does your parser support a similar file that we could include in our projects?
That would also help a lot. I'm a bit overwhelmed finding out how exactly this project works
but I'm liking most of the results I get in my editor since I started using it.
Big thanks for all the work so far :D

@SwissalpS
Copy link

Would putting https://luals.github.io/wiki/settings/#diagnosticsglobals in a .luarc.json file in my projects base directory do the trick? If so maybe we can come up with a basic converter of .luacheckrc files to .luarc.json

@tomlau10
Copy link
Contributor

tomlau10 commented Jan 7, 2025

luacheck and luals are different tools

Clearly luacheck and lua-language-server (luals) are different tools.

  • luacheck uses .luacheckrc
  • luals uses .luarc.json

I don't think it is a good idea for luals to support .luacheckrc.
It's because the file format is maintained by luacheck, and is subject to change at anytime.
If you would like to use both luacheck and luals in your projects, (like what my team did: we uses both of them in our projects) you have to setup the correct .luacheckrc and .luarc.json which fits your projects.

maybe a generator tool?

I understand that a full implementation would be a project of its own.

Yeah, I agree with this point. 👍
Maybe you or others can come up with a tool that tries to generate a .luarc.json based on a .luacheckrc.
But definitely it will be a tool/project that's not part of luals. (luals still only reads .luarc.json)

global variable definition in luals

A minimal support for looking up the tree to find a .luacheckrc file and at least respecting the globals and read_globals tables in a minimal maner would eliminate a huge number of false-positives.
...
Would putting https://luals.github.io/wiki/settings/#diagnosticsglobals in a .luarc.json file in my projects base directory do the trick?

Considering only the globals related setting from .luacheckrc, yes I think putting them in diagnostics.globals key inside .luarc.json will do the trick.

  • However, this will just silence the undefined-globals diagnostics from luals.
  • And you will be missing the auto completion/suggsestion feature of luals when you write _G.<trigger completion>
    • because the type system doesn't know there is a global variable for it
    • that setting is for silencing diagnostic warnings only

luals-way to define globals

In a more luals-way to define globals, one would write definition files: https://luals.github.io/wiki/definition-files/

  • you can create a file meta/global.d.lua in your project
    (any filename is fine, can split to multiple files as well)
---@meta

myglobal1 = nil  ---@type string
myglobal2 = nil  ---@type integer

---@class GlobalClass
GlobalClass = {}

---@param a string
---@return boolean
function globalFunc(a) end
  • when luals is preloading your workspace, it will preload this unused file as well
  • then you can enjoy type hint / completion related to global variables in your project 🚀

disabling some luals diagnostics

Each diagnostic can be disabled independently using the diagnostics.disable or diagnostics.neededFileStatus.
For example, you can just disable the undefined-global in luals side

  • .luarc.jsonc
{
    "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",

    // will use luacheck to check for globals instead
    "diagnostics.disable": [
        "undefined-global"
    ]
}

=> no more undefined-global warnings generated from luals side in the codebase💆‍♂️
For more information, you may look up the wiki: https://luals.github.io/wiki/diagnostics/


I'm a bit overwhelmed finding out how exactly this project works

Hope this can give you some insights on how you can solve your problems 😄 @SwissalpS
Or if you have further questions, you may also consider posting to the discussion section: https://github.com/LuaLS/lua-language-server/discussions, where more people can see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority.low A low priority topic question User has a question
Projects
None yet
Development

No branches or pull requests

6 participants