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

[openwisp-config] Add luacheck to runtests script and fix all warnings #77

Closed
nemesifier opened this issue Oct 21, 2018 · 13 comments · Fixed by #80 or #96
Closed

[openwisp-config] Add luacheck to runtests script and fix all warnings #77

nemesifier opened this issue Oct 21, 2018 · 13 comments · Fixed by #80 or #96

Comments

@nemesifier
Copy link
Member

Reserved for GCI

Luacheck is a static analyzer and a linter for Lua.

It is possible to integrate luacheck in many popular editors, like atom, vim, VS Code.

Prepend the luacheck test in the openwisp-config runtests script (add right after cd openwisp-config/tests/) and fix all warnings and errors luacheck reports.

@nemesifier
Copy link
Member Author

@okraits I merged the two tasks into one becuase it would be time-consuming to enforce having two tasks in which one is dependent on the other (we may get two students claiming both tasks concurrently) so in this case it made sense to merge the two in one

@okraits
Copy link
Member

okraits commented Oct 22, 2018

👍

1 similar comment
@okraits
Copy link
Member

okraits commented Oct 22, 2018

👍

vishalx360 added a commit to vishalx360/openwisp-config that referenced this issue Nov 11, 2018
openwisp#77

- added travis.yml with dependencies installation script.
- added luacheck test command in runtests script.
- fixed accessing undefined variable `uci` warning

Fixes openwisp#77
@okraits
Copy link
Member

okraits commented Dec 6, 2018

@nemesisdesign I had a look at this and noticed some things:

  • Only the tests are checked by luacheck, not the actual module code
  • Warnings about redefined variables, implicitly defined variables and unused arguments and loop variables are suppressed - but those can still lead to bugs and unused code
  • No warnings and errors have been fixed in the actual module code
  • thus luacheck integration in editors still reports many warnings and errors as those warnings mentioned above are not suppressed normally

I'm not sure if this is wanted. But maybe I'm wrong.

@nemesifier
Copy link
Member Author

@okraits no I think it was just not under my radar, I'm totally in favour of making the check stricter and keep the code cleaner

@okraits
Copy link
Member

okraits commented Dec 7, 2018

So let's reopen this issue so that things can get improved.

@okraits okraits reopened this Dec 7, 2018
@nemesifier
Copy link
Member Author

@okraits is this still relevant?

@okraits
Copy link
Member

okraits commented Nov 27, 2019

@nemesisdesign Yes, of course.

@talha-p
Copy link
Contributor

talha-p commented Dec 5, 2019

Was planning on working on this, just had a few queries:

  • Only the tests are checked by luacheck, not the actual module code

Is this something that needs to be fixed (I couldn't tell if this was wanted or not)
Also, are there any lints that you still wish to skip (currently -d -a -r flags are set)?

@okraits
Copy link
Member

okraits commented Dec 5, 2019

  • Only the tests are checked by luacheck, not the actual module code
    Is this something that needs to be fixed (I couldn't tell if this was wanted or not)

This is not wanted and needs to be fixed.

Also, are there any lints that you still wish to skip (currently -d -a -r flags are set)?

I would remove all three flags if possible.

@okraits
Copy link
Member

okraits commented Dec 5, 2019

For convenience, you can keep the -a flag for now.

@talha-p
Copy link
Contributor

talha-p commented Dec 6, 2019

@okraits
I've come up with the following notes whilst working on this issue:

  • Old Modules
    The modules "uci" and "lfs" etc. are based on the old Lua 5.0/5.1 way of creating modules (modules("*", package.seeall)) - Is this something that should be updated?
    This also triggers luacheck errors as these modules rely on importing the functions into a global namespace

  • Tests require globals definitions
    The unit tests require the testing table be a global variable, however this triggers a fail with Luacheck (See below for resolution)

Idea:
I was thinking, how about introducing a .luacheckrc file in regards to fixing a few of these problems, and also allowing us to remove the -a flag?

The file could be set out as such:

ignore = {"213/_.*"} -- unused Loop Variables beginning with underscore will be ignored, keeping readability
files["openwisp-config/tests"] = {
    ignore = {"11./Test.*"} -- globals relating to defining unittests are ignored
}

This will ensure a strict code linting, whilst also working around the issues we currently have.

@okraits
Copy link
Member

okraits commented Dec 7, 2019

* Old Modules
  The modules "uci" and "lfs" etc. are based on the old Lua 5.0/5.1 way of creating modules (`modules("*", package.seeall)`) - Is this something that should be updated?
  This also triggers luacheck errors as these modules rely on importing the functions into a global namespace

This means that those reported luacheck errors are in the external modules we use, not in our code, right? That would mean that those errors have to be fixed upstream. This has to be done, but it is out of scope of this PR:

* Tests require globals definitions
  The unit tests require the testing table be a global variable, however this triggers a fail with Luacheck (See below for resolution)

Idea:
I was thinking, how about introducing a .luacheckrc file in regards to fixing a few of these problems, and also allowing us to remove the -a flag?

The file could be set out as such:

ignore = {"213/_.*"} -- unused Loop Variables beginning with underscore will be ignored, keeping readability
files["openwisp-config/tests"] = {
    ignore = {"11./Test.*"} -- globals relating to defining unittests are ignored
}

This will ensure a strict code linting, whilst also working around the issues we currently have.

A very good idea! Go ahead! 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
3 participants