Page MenuHomePhabricator

Luacheck doesn't recognize mw.wikibase
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Edit a Scribunto script with CodeMirror on a WMF Wiki (in my case, enwiki)
  • Reference mw.wikibase in the Lua code

What happens?:

  • The Luacheck linter produces an info message "Accessing an undefined field of a global variable"

What should have happened instead?:

  • wikibase, if loaded, should be recognized as part of the mw library, the same standard scribunto libraries such as ustring and html are

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

image.png (347×76 px, 6 KB)

Not sure if this would require T394964 to be resolved first, or if there is another way of implementing this only on wikis where wikibase is enabled.

Event Timeline

Bhsd moved this task from Backlog to Improvement on the MediaWiki-extensions-CodeMirror board.
Bhsd subscribed.

I can think of two options:

  1. Always add mw.wikibase to Luacheck globals. This is less accurate but can be done immediately.
  2. Register a CodeMirror hook in Wikibase-Lua to modify Luacheck configuration, which may require some complicated PHP work.

I suggest going with the first option for now and creating a separate task to explore the possibility of extensions extending the list of recognized globals.

Change #1227760 had a related patch set uploaded (by Bhsd; author: Bhsd):

[mediawiki/extensions/CodeMirror@master] lua-worker: upgrade luacheck-browserify to 0.10.0

https://gerrit.wikimedia.org/r/1227760

Change #1227760 merged by jenkins-bot:

[mediawiki/extensions/CodeMirror@master] lua-worker: upgrade luacheck-browserify to 0.10.0

https://gerrit.wikimedia.org/r/1227760

Bhsd moved this task from Improvement to Done on the MediaWiki-extensions-CodeMirror board.