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

not_globals for custom standard doesn't seem to work #72

Open
eliw00d opened this issue Jul 9, 2022 · 4 comments
Open

not_globals for custom standard doesn't seem to work #72

eliw00d opened this issue Jul 9, 2022 · 4 comments

Comments

@eliw00d
Copy link

eliw00d commented Jul 9, 2022

I have a .luacheckrc that looks something like:

std = 'lua51'

stds.custom = {
    not_globals = {
        'package',
        'golua_default_msghandler',
        'os',
        'require',
        'io',
        'module',
        'unsafe_xpcall',
        'unsafe_pcall',
        'debug',
        'dofile',
    },
    read_globals = {
        -- custom read globals
    },
}

files['**/*.custom'] = {
    std = '+custom'
}

but when I try to set require in a file matching the glob and run luacheck I get: (W121) setting read-only global variable require

How can I remove read_globals set by std from a custom standard defined in stds?

❯ luacheck --version
Luacheck: 0.26.1
Lua: PUC-Rio Lua 5.1
Argparse: 0.7.1
LuaFileSystem: 1.8.0
LuaLanes: Not found
@arichard4
Copy link

(Sorry for the slow response!)

(1) It should be stds.custom, not std.custom
(2) std = '+custom' doesn't work; the plus sign is used to combine standards in a single string (i.e. for a single application). std = 'custom' will change the warning to "setting non-standard global variable require", which is the expected outcome of trying to assign to a non-local variable which you've explicitly set as not a global.
(3) To also fix the remaining error message, you should instead put 'require' under 'globals' (i.e. read-write globals, not read-only globals). Something like this works for me:

std = 'lua51'

stds.custom = {
    globals = {
    	'require'
    }
}

files['**/*.custom'] = {
    std = 'custom'
}

@eliw00d
Copy link
Author

eliw00d commented Aug 5, 2022

(1) It should be std_s_.custom, not std.custom

Oops! That was a typo when I created the issue. I have stds locally. I'll edit the comment to reflect that.

(2) std = '+custom' doesn't work; the plus sign is used to combine standards in a single string (i.e. for a single application). std = 'custom' will change the warning to "setting non-standard global variable require", which is the expected outcome of trying to assign to a non-local variable which you've explicitly set as not a global.

Oh, I thought using the + added onto the std, which is 'lua51'. If I set the file's std to 'custom' does that exclude 'lua51'? If so, would I need to do 'lua51+custom' for the file's std instead? Just want to make sure lua51 is used everywhere and then the custom changes on top.

(3) To also fix the remaining error message, you should instead put 'require' under 'globals' (i.e. read-write globals, not read-only globals).

I'm trying to remove require from the custom set, since it is not available for that type of file.

@arichard4
Copy link

I'm so very sorry, I've badly misunderstood what you were looking for; ignore my previous message, it was assuming that you wanted to be able to set require without a warning.

stds only supports globals and read_globals, not not_globals. So you original request isn't supported in the current code.

In the current code, not_globals should go outside the custom std, i.e. something like this:

std = 'lua51'

stds.custom = {
    read_globals = {
        -- custom read globals
    },
}

files['**/*.custom'] = {
    std = '+custom',
not_globals = {
        'package',
        'golua_default_msghandler',
        'os',
        'require',
        'io',
        'module',
        'unsafe_xpcall',
        'unsafe_pcall',
        'debug',
        'dofile',
    },
}

I can explore changing std's to also support not_globals.

@arichard4 arichard4 reopened this Aug 11, 2022
@eliw00d
Copy link
Author

eliw00d commented Aug 27, 2022

I'm so very sorry, I've badly misunderstood what you were looking for; ignore my previous message, it was assuming that you wanted to be able to set require without a warning.

stds only supports globals and read_globals, not not_globals. So you original request isn't supported in the current code.

In the current code, not_globals should go outside the custom std, i.e. something like this:

std = 'lua51'

stds.custom = {
    read_globals = {
        -- custom read globals
    },
}

files['**/*.custom'] = {
    std = '+custom',
not_globals = {
        'package',
        'golua_default_msghandler',
        'os',
        'require',
        'io',
        'module',
        'unsafe_xpcall',
        'unsafe_pcall',
        'debug',
        'dofile',
    },
}

I can explore changing std's to also support not_globals.

Oh, I see! I must have missed this:

This table can have two fields: globals and read_globals.

I do think that setting not_globals per std would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants