fix(python): Check for assignment to non-attributes in class (#107)
This commit is contained in:
@@ -224,15 +224,23 @@ return {
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Deliberately check inside the init function for assignments to "self"
|
||||||
results[i.ClassAttribute] = {}
|
results[i.ClassAttribute] = {}
|
||||||
for _, assignment in pairs(nodes["assignment"]) do
|
for _, assignment in pairs(nodes["assignment"]) do
|
||||||
local left_side = assignment:field("left")[1]
|
-- Getting left side in assignment
|
||||||
local left_attribute = left_side:field("attribute")[1]
|
local left = assignment:field("left")
|
||||||
|
|
||||||
|
-- Checking if left side is an "attribute", which means assigning to an attribute to the function
|
||||||
|
if not vim.tbl_isempty(left) and not vim.tbl_isempty(left[1]:field("attribute")) then
|
||||||
|
--Adding it to the list
|
||||||
|
local left_attribute = assignment:field("left")[1]:field("attribute")[1]
|
||||||
left_attribute = helpers.get_node_text(left_attribute)[1]
|
left_attribute = helpers.get_node_text(left_attribute)[1]
|
||||||
if left_attribute and not vim.startswith(left_attribute, "_") then
|
|
||||||
|
if not vim.startswith(left_attribute, "_") then
|
||||||
table.insert(results[i.ClassAttribute], left_attribute)
|
table.insert(results[i.ClassAttribute], left_attribute)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if vim.tbl_isempty(results[i.ClassAttribute]) then
|
if vim.tbl_isempty(results[i.ClassAttribute]) then
|
||||||
results[i.ClassAttribute] = nil
|
results[i.ClassAttribute] = nil
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user