DICE PACKS BUNDLE
Page 2 of 2 First 12

Thread: luacheckrc

  1. #11
    With luacheck, how does one prevent the warnings about "setting non-standard global variable" for every FGU function override defined? Do I need to add each one to the globals list in the .luacheckrc file?

    Examples are onClickDown(), sourceupdate(), onSourceUpdate(), and onFirstLayout(). They all get flagged as non-standard global variable definitions by luacheck. I was assuming I need to make these global to override the existing functions for the same windowclass. Should I actually declare them local?

    What's the actual scope of scripts that override/merge with an existing windowsclass or are loaded via tags in the XML? Are they really global, or is there some implied scope/block boundary created by the windowclass that includes them and its a limitation that luacheck can't detect the implied scope because that's way out of context of how the tool operates? Not sure if that is really a lua question or more of a question about an implementation detail with how FGU integrates lua and provides support for extensions.

    Thanks for any clarification,
    Brian

  2. #12
    Quote Originally Posted by MostTornBrain View Post
    With luacheck, how does one prevent the warnings about "setting non-standard global variable" for every FGU function override defined? Do I need to add each one to the globals list in the .luacheckrc file?

    Examples are onClickDown(), sourceupdate(), onSourceUpdate(), and onFirstLayout(). They all get flagged as non-standard global variable definitions by luacheck. I was assuming I need to make these global to override the existing functions for the same windowclass. Should I actually declare them local?

    What's the actual scope of scripts that override/merge with an existing windowsclass or are loaded via tags in the XML? Are they really global, or is there some implied scope/block boundary created by the windowclass that includes them and its a limitation that luacheck can't detect the implied scope because that's way out of context of how the tool operates? Not sure if that is really a lua question or more of a question about an implementation detail with how FGU integrates lua and provides support for extensions.

    Thanks for any clarification,
    Brian
    Ah, those should be added here for now: https://github.com/bmos/FG-luacheck/...checkrc_header
    I don't have a comprehensive list, so please add whatever you find Or just post them here and I can add them.
    Eventually I need to revise my parser to auto-whitelist globals based on the templates they inherit.

  3. #13
    Made some progress today toward getting templates working.
    At this point they're included in definitions, but they don't append themselves to objects that use them.
    Coming soon, hopefully. The number of lines has actually decreased since adding this, so I have left the luacheckrc file alone and just saved the new one on a public testing branch. Use whichever works best for you (probably the main branch for now).

    The other big problem I have realized is that many very low-level/core FG functions are written in <script> tags in xml files. At the moment my code doesn't handle these at all. That one is a big less straightforward to solve, so I'm going to try and finish the parsing of templates whose scripts are in discrete lua files first.
    Last edited by bmos; March 27th, 2022 at 01:24.

  4. #14
    Lots of changes since the 26th.

    In-xml interface scripts are now parsed.
    Templates are now handled, both for script files and in-xml scripts.

    https://raw.githubusercontent.com/bm...in/.luacheckrc

    The remaining primary issue is that adding items to ruleset global tables produces a warning from luacheckrc.
    Last edited by bmos; April 7th, 2022 at 00:04.

  5. #15
    I'd love to hear suggestions on this issue:

    When running luacheck on a lua file attached to an interface object, luacheck doesn't know what the parent template of the file is (so it doesn't know about the functions whitelisted in that template). Since this is not a function of my parser script, but rather of luacheck, I would have to fork luacheck iteself to add some feature for scope detection (which would be FG specific) if I wanted to actually 'fix' this.

    One easier option is to add all functions to a global definition table which would resolve those errors. The downside is that luacheckrc would not know if you're calling a function that doesn't exist in that interface object. For example, using "setComboBoxReadOnly" would not show an error if used in a script that was attached to a numbercontrol. Effectively it would be whitelisting all functions of all interface objects for use in all interface scripts.

    Another option is to add per-file definitions via a lua comment such as "-- luacheck: globals getName" which would allow use of that function in the file. This is a significant task for each developer, but would preserve much more linting functionality.


    I'm feeling kind of stumped.

    EDIT:
    There might be a solution built into luacheck.
    It would require generating a luacheck file for each project it's used in (something I was already considering that could be a big improvement for execution speed and flexibility).
    * Parse project to create an array linking script filenames to their interface object names.
    * Run current parsing logic on the inherited dataset (such as CoreRPG and Moon Tracker extension).
    * Use inherited dataset to add per-file whitelists for any files found in project.

    The downside is that you would have to re-run this program on the project directory whenever you created a new file.
    Last edited by bmos; April 10th, 2022 at 15:17.

  6. #16
    Updated the luacheck_headers file to specifically whitelist all API functions listed in the customer portal/documentation. This allows for typo-detection for things like "DB.getVaalue".

    Also, for insight into how I personally use this:
    I use VSCodium for development along with the LuaCoderAssist extension. Setting it up is a bit goofy ("config file path" means path to directory, not path to file -- this of course means the file must have the expected name of ".luacheckrc" -- and you also need to disable "define the luacheck cli options automatically"), but it has a bunch of very neat features to help with lua development and encourage use of slim functions.

    By using my luacheckrc config file in this way, it automatically underlines MANY common code errors in real-time as you're editing scripts.

    For people who want to use global functions without being warned or having to create specific exemptions, add "allow_defined_top = true" to the top of the .luacheckrc file. (suggested by MeAndUnique)
    Last edited by bmos; May 30th, 2022 at 21:39.

  7. #17
    Love it!

  8. #18
    action-generate-luacheck v1.8 - enable all detected global definitions
    * std global definitions are now automatically added to the std string based on scanned packages
    * if encountering empty xml <script> tags, post a warning message and continue. previously, an error was encountered.
    * package names and authors are now parsed differently. previously, author tags with a colon would not be read correctly. suggested author format is a comma-separated list with the primary maintainer at the beginning.

    action-generate-luacheck v1.9 - nil error fixes, sorting improvements, more error messaging
    * Definitions are now sorted using a more consistent ordering function to prevent uneccessary changes to the output config. This makes it much easier to tell what has changed in the output between runs.
    * Most missing values will add an error to the output to assist in diagnosing missing global definitions.
    * Most missing values will no longer cause script to fail with nil error.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in