mpeterv / luacheck

A tool for linting and static analysis of Lua code.
MIT License
1.92k stars 322 forks source link

erroneous 122 "mutating read-only global variable 'ngx'" on correct lua-nginx code #87

Closed bubaflub closed 7 years ago

bubaflub commented 7 years ago

When running against our lua-nginx codebase I have to add ignore = {"122/ngx"} to .luacheckrc since luacheck flags a number of valid lua-nginx calls as wrong.

Simple example:

$ cat lua/test.lua
ngx.status = ngx.HTTP_CREATED
$ luacheck --std ngx_lua lua/test.lua
Checking lua/test.lua                             1 warning

    lua/test.lua:1:1: mutating read-only global variable 'ngx'

Total: 1 warning / 0 errors in 1 file

But according to https://github.com/openresty/lua-nginx-module#ngxstatus this is completely valid lua-nginx code. It seems like having ngx as a read-only global isn't fine-grained enough or not quite accurate.

n1tehawk commented 7 years ago

Probably related to #46, as it would require the same refinement on checking table-type globals. Here, setting a specific (member) field obviously is okay, while other assignments might be undesired.

mpeterv commented 7 years ago

It's not fine-grained enough but for now as a temporary fix I'll remove remove read-only status of ngx global in ngx_lua std.