Kampfkarren / selene

A blazing-fast modern Lua linter written in Rust

Home Page:https://kampfkarren.github.io/selene/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`manual_table_clone` false positive

LastTalon opened this issue · comments

There's a case where a manual_table_clone is identified that in some cases may not be the same as table.clone. The following case, for instance, if intended to continually add and overwrite items, is not the same as table.clone.

local items = {}

local function addToItems(newItems)
	for key, value in newItems do
		items[key] = value
	end
end

One option is to warn only when the declaration and loop are in the same lexical scope. This would false negative in cases where this is truly a manual table clone:

local items = {}

if a then
    for key, value in b do
        items[key] = value
    end
else
    for key, value in c do
        items[key] = value
    end
end

I'm not too sure which case is more common, but I lean towards false negatives over false positives.