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

Add optional diagnostic warning about any global element #2040

Merged
merged 8 commits into from Mar 31, 2023

Conversation

AndreaWalchshoferSCCH
Copy link
Contributor

@AndreaWalchshoferSCCH AndreaWalchshoferSCCH commented Mar 29, 2023

This PR adds a new diagnostic global-element and a new diagnostic group strict-conventions.

In our coding, we want to avoid the usage of global elements almost completely, except for specific, configured elements. As it's easy to forget about the local keyword and create global variables/functions/..., we implemented this diagnostic.
As this is probably not a convention/guideline everyone wants to follow, we put the diagnostic in a separate group, which will be disabled by default and therefore not affect any existing configurations.

In short, this PR includes

  • the diagnostic global-element that identifies any non-local element in the code that is not listed in the existing setting diagnostics.globals
  • the group strict-conventions, with default severity Warning and default fileStatus None, so it's disabled by default
  • isolated unit tests for this diagnostic

* Add warning for any global variable via diagnostic
* Add messages in en-US
  TODO: add messages in languages other than en-us as well
* fallback: enable/disable diagnostics w/ annotation
* Add tests for the new diagnostic
* Add diagnostic and group to config.md
test/diagnostics/init.lua Outdated Show resolved Hide resolved
test/diagnostics/global-element.lua Outdated Show resolved Hide resolved
test/diagnostics/global-element.lua Outdated Show resolved Hide resolved
@AndreaWalchshoferSCCH AndreaWalchshoferSCCH marked this pull request as draft March 30, 2023 13:16
* add newlines to end of files
* change the group name to `conventions`
@AndreaWalchshoferSCCH AndreaWalchshoferSCCH marked this pull request as ready for review March 30, 2023 14:10
@sumneko
Copy link
Collaborator

sumneko commented Mar 31, 2023

Thanks for your work!

@sumneko sumneko merged commit ac3d06d into LuaLS:master Mar 31, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants