Go to file
Kunal Mehta d433cae33a Add strict.lua to replace "Module:No globals"
This is being backported because many users copy lua modules from
Wikipedia, and thus benefit from forwards-compatibility.

For the most part, it is a good idea to avoid global variables and use
`local` variables instead. Quoting from the ScopeTutorial[1], "The
general rule is to always use local variables, unless it's necessary for
every part of your program to be able to access the variable (which is
very rare)."

Wikimedia module authors have written "Module:No globals", which errors
on the use of any global variable. On the English Wikipedia, this is
used on 32% of pages (18 million). Wikidata[2] indicates that it's been
copied to 334 other wikis.

Lua itself distributes an extra named "strict.lua"[3], which is what
this is based off of. Similar to bit32.lua, this is a pure-Lua library
that can be imported/enabled with `require( "strict" )` at the top of a
module.

The two changes I made from Lua's strict is to exempt the `arg` key,
which is used internally by Scribunto, and remove `what()`, since we
don't enable access to `debug.getinfo()` for security reasons.

[1] https://lua-users.org/wiki/ScopeTutorial
[2] https://www.wikidata.org/wiki/Q16748603
[3] http://www.lua.org/extras/5.1/strict.lua

(Cherry-picked from 829c53ef05)

Bug: T209310
Change-Id: I46ee6f630ac6b26c68c31becd1f3b9d961bcab29
2022-11-07 06:04:50 +00:00
.phan build: Load pcntl stub to pass phan on windows 2020-06-06 13:58:24 +02:00
i18n Localisation updates from https://translatewiki.net. 2022-10-31 07:37:54 +01:00
includes Add strict.lua to replace "Module:No globals" 2022-11-07 06:04:50 +00:00
modules build: Update eslint-config-wikimedia from 0.8.1 to 0.11.0 2019-04-12 13:00:29 -07:00
tests Add strict.lua to replace "Module:No globals" 2022-11-07 06:04:50 +00:00
.eslintrc.json build: Remove unneeded exclude from .eslintrc.json 2020-01-08 16:54:09 +00:00
.gitignore build: Upgrade eslint-config-wikimedia 0.12.0, drop grunt-jsonlint 2019-05-07 10:40:41 -07:00
.gitreview Whoops, track not trace 2016-10-24 17:03:31 -07:00
.phpcs.xml build: Updating dependencies 2022-04-15 22:25:30 +00:00
.stylelintrc.json Use json extension for .stylelintrc 2017-08-19 10:27:54 +02:00
CODE_OF_CONDUCT.md build: Updating mediawiki/mediawiki-codesniffer to 22.0.0 2018-09-03 21:33:35 +00:00
composer.json build: Updating dependencies 2022-04-15 22:25:30 +00:00
COPYING Add strict.lua to replace "Module:No globals" 2022-11-07 06:04:50 +00:00
extension.json Don't use deprecated Parser::OutputType() 2020-04-17 00:47:42 +00:00
Gruntfile.js build: Updating npm dependencies 2020-01-08 07:46:47 +00:00
package-lock.json build: Updating minimatch to 3.0.8 2022-10-24 03:56:55 +00:00
package.json build: Updating grunt to 1.5.3 2022-05-24 00:45:35 +00:00
Scribunto.constants.php Remove PHP entry point 2019-06-21 00:02:08 +00:00
Scribunto.magic.php Add namespace and magic word translations for mnw and my 2019-10-18 20:03:05 +00:00
Scribunto.namespaces.php Add Northern Sámi namespace translation for Scribunto 2020-06-18 22:42:04 +02:00