add .luacheckrc and fix linter issues

This commit is contained in:
kyazdani42 2020-06-08 11:23:30 +02:00
parent 1e67a7c6f4
commit 18dac0ed84
7 changed files with 40 additions and 24 deletions

13
.luacheckrc Normal file
View File

@ -0,0 +1,13 @@
-- vim: ft=lua tw=80
-- Don't report unused self arguments of methods.
self = false
ignore = {
"631", -- max_line_length
}
-- Global objects defined by the C code
read_globals = {
"vim",
}

View File

@ -25,7 +25,7 @@ local function get_colors()
}
end
local function get_hl_groups()
local function get_hl_groups()
local colors = get_colors()
return {
@ -96,7 +96,7 @@ M.hl_groups = {
['ejs'] = 'HtmlIcon';
}
local function get_links()
local function get_links()
return {
FolderName = 'Directory',
Normal = 'Normal',

View File

@ -28,7 +28,7 @@ local function create_file(file)
end
local function get_num_entries(iter)
i = 0
local i = 0
for _ in iter do
i = i + 1
end
@ -37,7 +37,7 @@ end
function M.create(node)
if node.name == '..' then return end
local add_into
if node.entries ~= nil then
add_into = node.absolute_path..'/'

View File

@ -51,8 +51,8 @@ local function create_root(cwd)
return true
end
function M.update_status(entries, cwd)
local cwd = cwd:gsub(' ', '\\ ')
function M.update_status(entries, _cwd)
local cwd = _cwd:gsub(' ', '\\ ')
local git_root, git_status = get_git_root(cwd)
if not git_root then
if not create_root(cwd) then

View File

@ -125,7 +125,7 @@ function M.refresh_entries(entries, cwd)
if not named_entries[name] then
local n = e.fn(cwd, name)
local idx = 1
idx = 1
if prev then
idx = entries_idx[prev] + 1
end

View File

@ -11,8 +11,8 @@ local namespace_id = api.nvim_create_namespace('LuaTreeHighlights')
local icon_state = config.get_icon_state()
local get_folder_icon = function() return "" end
local set_folder_hl = function(index, depth, git_icon_len)
table.insert(hl, {'LuaTreeFolderName', index, depth+git_icon_len, -1})
local set_folder_hl = function(line, depth, git_icon_len)
table.insert(hl, {'LuaTreeFolderName', line, depth+git_icon_len, -1})
end
if icon_state.show_folder_icon then
@ -23,9 +23,9 @@ if icon_state.show_folder_icon then
return icon_state.icons.folder_icons.default .. " "
end
end
set_folder_hl = function(index, depth, icon_len, name_len)
table.insert(hl, {'LuaTreeFolderName', index, depth+icon_len, depth+icon_len+name_len})
table.insert(hl, {'LuaTreeFolderIcon', index, depth, depth+icon_len})
set_folder_hl = function(line, depth, icon_len, name_len)
table.insert(hl, {'LuaTreeFolderName', line, depth+icon_len, depth+icon_len+name_len})
table.insert(hl, {'LuaTreeFolderIcon', line, depth, depth+icon_len})
end
end
@ -33,8 +33,9 @@ local get_file_icon = function() return "" end
if icon_state.show_file_icon then
local web_devicons = require'nvim-web-devicons'
get_file_icon = function(fname, extension, index, depth)
local icon, hl_group = web_devicons.get_icon(fname, extension)
get_file_icon = function(fname, extension, line, depth)
local hl_group
local icon, _ = web_devicons.get_icon(fname, extension)
-- TODO: remove this hl_group and make this in nvim-web-devicons
if #extension == 0 then
hl_group = colors.hl_groups[fname]
@ -42,7 +43,7 @@ if icon_state.show_file_icon then
hl_group = colors.hl_groups[extension]
end
if hl_group and icon then
table.insert(hl, { 'LuaTree'..hl_group, index, depth, depth + #icon })
table.insert(hl, { 'LuaTree'..hl_group, line, depth, depth + #icon })
return icon.." "
else
return icon_state.icons.default and icon_state.icons.default.." " or ""
@ -52,10 +53,8 @@ if icon_state.show_file_icon then
end
local get_git_icons = function() return "" end
local git_icon_state = {}
if icon_state.show_git_icon then
git_icon_state = {
local git_icon_state = {
["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } },
[" M"] = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
["MM"] = {
@ -77,14 +76,14 @@ if icon_state.show_git_icon then
dirty = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
}
get_git_icons = function(node, index, depth, icon_len)
get_git_icons = function(node, line, depth, icon_len)
local git_status = node.git_status
if not git_status then return "" end
local icon = ""
local icons = git_icon_state[git_status]
for _, v in ipairs(icons) do
table.insert(hl, { v.hl, index, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon })
table.insert(hl, { v.hl, line, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon })
icon = icon..v.icon.." "
end
@ -166,7 +165,7 @@ function M.draw(tree, reload)
update_draw_data(tree, 0)
end
api.nvim_buf_set_lines(tree.bufnr, 0, -1, false, lines)
api.nvim_buf_set_lines(tree.bufnr, 0, -1, false, lines)
M.render_hl(tree.bufnr)
if #lines > cursor[1] then
api.nvim_win_set_cursor(tree.winnr, cursor)

View File

@ -21,8 +21,12 @@ M.Tree = {
bufnr = nil,
winnr = nil,
buf_options = {
'sidescroll=5', 'noswapfile', 'splitbelow',
'noruler', 'noshowmode', 'noshowcmd'
'sidescroll=5',
'noswapfile',
'splitbelow',
'noruler',
'noshowmode',
'noshowcmd'
},
win_options = {
relativenumber = false,
@ -114,7 +118,7 @@ local function refresh_nodes(node)
end
function M.refresh_tree()
local stat = luv.fs_stat(M.Tree.cwd)
-- local stat = luv.fs_stat(M.Tree.cwd)
-- if stat.mtime.sec ~= M.Tree.last_modified then
refresh_nodes(M.Tree)
-- end