luacheck icon indicating copy to clipboard operation
luacheck copied to clipboard

Check if module was required to a local variable

Open keeprocking opened this issue 7 years ago • 3 comments

According to https://luacheck.readthedocs.io/en/stable/warnings.html, there's no warnings for cases when a module being required is not assigned to a local variable, e.g.

require 'foo.bar'

instead of

local bar = require 'foo.bar'

Is it possible to add one? I would love to have a separate warning code for this because I need to differ such cases from "113 - Accessing an undefined global variable".

Thank you.

keeprocking avatar Oct 17 '18 14:10 keeprocking

This can be added, yes. In case require argument is a literal it could use it as the warning "name" for filtering, so that something like ignore = {"xxx"}; only = {"xxx/foo%.bar"} enabled the warning only for foo.bar module (where xxx is the new warning code). Or perhaps the warning should be disabled by default, then the ignore option is not needed.

mpeterv avatar Oct 17 '18 17:10 mpeterv

Sorry, I don't understand. If I want to spot all the places (without knowing which modules are actually being required) where require is called without saving its result to a local variable, how do I do that? Is it possible with existing config options?

keeprocking avatar Oct 18 '18 09:10 keeprocking

Petya? Some help would be much appreciated!

keeprocking avatar Oct 25 '18 18:10 keeprocking