Skip to content

Commit

Permalink
Merge pull request #2865 from lewis6991/lint/cleanup
Browse files Browse the repository at this point in the history
lint: cleanup unused code and redefined locals
  • Loading branch information
sumneko authored Sep 25, 2024
2 parents b9373fd + f0d0be3 commit 575d607
Show file tree
Hide file tree
Showing 75 changed files with 181 additions and 241 deletions.
3 changes: 2 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"unused": "Any"
},
"ignoredFiles": "Opened",
"libraryFiles": "Opened"
"libraryFiles": "Opened",
"unusedLocalExclude": [ "_*" ]
},
"runtime": {
"version": "Lua 5.4",
Expand Down
10 changes: 4 additions & 6 deletions script/core/code-action.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
local files = require 'files'
local lang = require 'language'
local util = require 'utility'
local sp = require 'bee.subprocess'
local guide = require "parser.guide"
local converter = require 'proto.converter'
local autoreq = require 'core.completion.auto-require'
local rpath = require 'workspace.require-path'
local furi = require 'file-uri'
local undefined = require 'core.diagnostics.undefined-global'
local vm = require 'vm'

---@param uri uri
Expand Down Expand Up @@ -51,7 +49,7 @@ local function checkDisableByLuaDocExits(uri, row, mode, code)
return nil
end

local function checkDisableByLuaDocInsert(uri, row, mode, code)
local function checkDisableByLuaDocInsert(_uri, row, mode, code)
return {
start = guide.positionOf(row, 0),
finish = guide.positionOf(row, 0),
Expand Down Expand Up @@ -242,7 +240,7 @@ local function solveSyntaxByFix(uri, err, results)
}
end

local function solveSyntaxUnicodeName(uri, err, results)
local function solveSyntaxUnicodeName(uri, _err, results)
results[#results+1] = {
title = lang.script('ACTION_RUNTIME_UNICODE_NAME'),
kind = 'quickfix',
Expand Down Expand Up @@ -321,7 +319,7 @@ local function solveAmbiguity1(uri, diag, results)
}
end

local function solveTrailingSpace(uri, diag, results)
local function solveTrailingSpace(uri, _diag, results)
results[#results+1] = {
title = lang.script.ACTION_REMOVE_SPACE,
kind = 'quickfix',
Expand Down Expand Up @@ -697,7 +695,7 @@ local function checkMissingRequire(results, uri, start, finish)
end

local function addRequires(global, endpos)
autoreq.check(state, global, endpos, function(moduleFile, stemname, targetSource)
autoreq.check(state, global, endpos, function(moduleFile, _stemname, _targetSource)
local visiblePaths = rpath.getVisiblePath(uri, furi.decode(moduleFile))
if not visiblePaths or #visiblePaths == 0 then return end

Expand Down
1 change: 0 additions & 1 deletion script/core/command/autoRequire.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local files = require 'files'
local furi = require 'file-uri'
local config = require 'config'
local rpath = require 'workspace.require-path'
local client = require 'client'
local lang = require 'language'
Expand Down
1 change: 0 additions & 1 deletion script/core/command/exportDocument.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ local doc = require 'cli.doc'
local client = require 'client'
local furi = require 'file-uri'
local lang = require 'language'
local ws = require 'workspace'
local files = require 'files'

---@async
Expand Down
2 changes: 1 addition & 1 deletion script/core/command/reloadFFIMeta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ return function (uri)
return
end

for i, v in ipairs(refs) do
for _, v in ipairs(refs) do
local target_uri = v.uri
local codes = searchCode(refs, target_uri)
if not codes then
Expand Down
20 changes: 9 additions & 11 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ local function checkModule(state, word, position, results)
end)
end

local function checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position)
local function checkFieldFromFieldToIndex(state, name, parent, word, position)
if name:match(guide.namePatternFull) then
if not name:match '[\x80-\xff]'
or config.get(state.uri, 'Lua.runtime.unicodeName') then
Expand Down Expand Up @@ -499,7 +499,7 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP
return textEdit, additionalTextEdits
end

local function checkFieldThen(state, name, src, word, startPos, position, parent, oop, results)
local function checkFieldThen(state, name, src, word, position, parent, oop, results)
local value = vm.getObjectFunctionValue(src) or src
local kind = define.CompletionItemKind.Field
if (value.type == 'function' and not vm.isVarargFunctionWithOverloads(value))
Expand Down Expand Up @@ -542,7 +542,7 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent
newText = name:sub(#str[2] + 1, - #str[2] - 1),
}
else
textEdit, additionalTextEdits = checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position)
textEdit, additionalTextEdits = checkFieldFromFieldToIndex(state, name, parent, word, position)
end
results[#results+1] = {
label = name,
Expand Down Expand Up @@ -632,7 +632,7 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o
local fieldResults = {}
for name, src in util.sortPairs(fields) do
if src then
checkFieldThen(state, name, src, word, startPos, position, parent, oop, fieldResults)
checkFieldThen(state, name, src, word, position, parent, oop, fieldResults)
await.delay()
end
end
Expand Down Expand Up @@ -1256,12 +1256,10 @@ local function insertDocEnum(state, pos, doc, enums)
return enums
end

---@param state parser.state
---@param pos integer
---@param doc vm.node.object
---@param enums table[]
---@return table[]?
local function insertDocEnumKey(state, pos, doc, enums)
local function insertDocEnumKey(doc, enums)
local tbl = doc.bindSource
if not tbl then
return nil
Expand Down Expand Up @@ -1357,12 +1355,12 @@ local function insertEnum(state, pos, src, enums, isInArray, mark)
elseif src.type == 'doc.enum' then
---@cast src parser.object
if vm.docHasAttr(src, 'key') then
insertDocEnumKey(state, pos, src, enums)
insertDocEnumKey(src, enums)
else
insertDocEnum(state, pos, src, enums)
end
elseif isInArray and src.type == 'doc.type.array' then
for i, d in ipairs(vm.getDefs(src.node)) do
for _, d in ipairs(vm.getDefs(src.node)) do
insertEnum(state, pos, d, enums, isInArray, mark)
end
elseif src.type == 'global' and src.cate == 'type' then
Expand Down Expand Up @@ -2082,7 +2080,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
end
local label = {}
local insertText = {}
for i, arg in ipairs(func.args) do
for _, arg in ipairs(func.args) do
if arg[1] and arg.type ~= 'self' then
label[#label+1] = arg[1]
if #label == 1 then
Expand All @@ -2098,7 +2096,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
insertTextFormat = 2,
insertText = table.concat(insertText, '\n'),
}
for i, arg in ipairs(func.args) do
for _, arg in ipairs(func.args) do
if arg[1] then
results[#results+1] = {
label = arg[1],
Expand Down
1 change: 0 additions & 1 deletion script/core/completion/keyword.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local define = require 'proto.define'
local files = require 'files'
local guide = require 'parser.guide'
local config = require 'config'
local util = require 'utility'
Expand Down
8 changes: 4 additions & 4 deletions script/core/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ local accept = {
['doc.field.name'] = true,
}

local function checkRequire(source, offset)
local function checkRequire(source)
if source.type ~= 'string' then
return nil
end
Expand Down Expand Up @@ -141,14 +141,14 @@ return function (uri, offset)
local results = {}
local uris = checkRequire(source)
if uris then
for i, uri in ipairs(uris) do
for _, uri0 in ipairs(uris) do
results[#results+1] = {
uri = uri,
uri = uri0,
source = source,
target = {
start = 0,
finish = 0,
uri = uri,
uri = uri0,
}
}
end
Expand Down
1 change: 0 additions & 1 deletion script/core/diagnostics/cast-type-mismatch.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local vm = require 'vm'
local await = require 'await'
Expand Down
1 change: 0 additions & 1 deletion script/core/diagnostics/different-requires.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local config = require 'config'
local vm = require 'vm'
local rpath = require 'workspace.require-path'

Expand Down
2 changes: 0 additions & 2 deletions script/core/diagnostics/duplicate-set-field.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local files = require 'files'
local lang = require 'language'
local define = require 'proto.define'
local guide = require 'parser.guide'
local vm = require 'vm'
local await = require 'await'
Expand All @@ -24,7 +23,6 @@ local function getTopFunctionOfIf(source)
end
source = source.parent
end
return nil
end

---@async
Expand Down
6 changes: 3 additions & 3 deletions script/core/diagnostics/missing-fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ return function (uri, callback)
return
end
end

local myKeys
local warnings = {}
for className, samedefs in pairs(sortedDefs) do
Expand All @@ -44,7 +44,7 @@ return function (uri, callback)
if not def.fields or #def.fields == 0 then
goto continue
end

if not myKeys then
myKeys = {}
for _, field in ipairs(src) do
Expand Down Expand Up @@ -82,7 +82,7 @@ return function (uri, callback)
if #missedKeys == 0 then
return
end

warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', className, table.concat(missedKeys, ', '))
end

Expand Down
2 changes: 1 addition & 1 deletion script/core/diagnostics/missing-local-export-doc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ return function (uri, callback)
await.delay()
--table

for i, ret in ipairs(source) do
for _, ret in ipairs(source) do
if ret.type == 'getlocal' then
if ret.node.value and ret.node.value.type == 'table' then
findSetField(state.ast, ret[1], callback)
Expand Down
5 changes: 2 additions & 3 deletions script/core/diagnostics/param-type-mismatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ end

---@param funcNode vm.node
---@param i integer
---@param uri uri
---@return vm.node?
local function getDefNode(funcNode, i, uri)
local function getDefNode(funcNode, i)
local defNode = vm.createNode()
for src in funcNode:eachObject() do
if src.type == 'function'
Expand Down Expand Up @@ -93,7 +92,7 @@ return function (uri, callback)
if not refNode then
goto CONTINUE
end
local defNode = getDefNode(funcNode, i, uri)
local defNode = getDefNode(funcNode, i)
if not defNode then
goto CONTINUE
end
Expand Down
3 changes: 1 addition & 2 deletions script/core/diagnostics/unbalanced-assignments.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local files = require 'files'
local define = require 'proto.define'
local lang = require 'language'
local guide = require 'parser.guide'
local await = require 'await'
Expand All @@ -13,7 +12,7 @@ local types = {
}

---@async
return function (uri, callback, code)
return function (uri, callback)
local ast = files.getState(uri)
if not ast then
return
Expand Down
3 changes: 0 additions & 3 deletions script/core/diagnostics/undefined-global.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
local files = require 'files'
local vm = require 'vm'
local lang = require 'language'
local config = require 'config'
local guide = require 'parser.guide'
local await = require 'await'
local util = require 'utility'

local requireLike = {
['include'] = true,
Expand Down
1 change: 0 additions & 1 deletion script/core/diagnostics/unknown-cast-variable.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local vm = require 'vm'
local await = require 'await'
Expand Down
3 changes: 0 additions & 3 deletions script/core/diagnostics/unknown-operator.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local vm = require 'vm'
local await = require 'await'
local util = require 'utility'

---@async
return function (uri, callback)
Expand Down
Loading

0 comments on commit 575d607

Please sign in to comment.