Skip to content

Commit 0816064

Browse files
authored
chore: add stylua to format the codebase, and run on CI (#1055)
1 parent 76d181d commit 0816064

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+871
-732
lines changed

.github/workflows/luacheck.yml renamed to .github/workflows/ci.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
name: Linting and style checking
1+
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
push:
8+
branches:
9+
- master
410

511
jobs:
612
luacheck:
@@ -17,3 +23,12 @@ jobs:
1723
sudo luarocks install luacheck
1824
- name: Run luacheck
1925
run: luacheck .
26+
stylua:
27+
name: stylua
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v2
31+
- uses: JohnnyMorganz/stylua-action@1.0.0
32+
with:
33+
token: ${{ secrets.GITHUB_TOKEN }}
34+
args: --color always --check lua/

.stylua.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 120
2+
line_endings = "Unix"
3+
indent_type = "Spaces"
4+
indent_width = 2
5+
quote_style = "AutoPreferDouble"
6+
call_parentheses = "None"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A File Explorer For Neovim Written In Lua
22

3-
[![Linting and style checking](https://github.com/kyazdani42/nvim-tree.lua/actions/workflows/luacheck.yml/badge.svg)](https://github.com/kyazdani42/nvim-tree.lua/actions/workflows/luacheck.yml)
3+
[![CI](https://github.com/kyazdani42/nvim-tree.lua/actions/workflows/ci.yml/badge.svg)](https://github.com/kyazdani42/nvim-tree.lua/actions/workflows/ci.yml)
44

55
## Notice
66

lua/nvim-tree.lua

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
local luv = vim.loop
22
local api = vim.api
33

4-
local lib = require'nvim-tree.lib'
5-
local colors = require'nvim-tree.colors'
6-
local renderer = require'nvim-tree.renderer'
7-
local view = require'nvim-tree.view'
8-
local utils = require'nvim-tree.utils'
9-
local change_dir = require'nvim-tree.actions.change-dir'
10-
local legacy = require'nvim-tree.legacy'
4+
local lib = require "nvim-tree.lib"
5+
local colors = require "nvim-tree.colors"
6+
local renderer = require "nvim-tree.renderer"
7+
local view = require "nvim-tree.view"
8+
local utils = require "nvim-tree.utils"
9+
local change_dir = require "nvim-tree.actions.change-dir"
10+
local legacy = require "nvim-tree.legacy"
1111

1212
local _config = {}
1313

@@ -19,7 +19,7 @@ function M.focus()
1919
end
2020

2121
---@deprecated
22-
M.on_keypress = require'nvim-tree.actions'.on_keypress
22+
M.on_keypress = require("nvim-tree.actions").on_keypress
2323

2424
function M.toggle(find_file, no_focus)
2525
if view.is_visible() then
@@ -56,60 +56,59 @@ function M.open_replacing_current_buffer()
5656
return
5757
end
5858

59-
local cwd = vim.fn.fnamemodify(bufname, ':p:h')
59+
local cwd = vim.fn.fnamemodify(bufname, ":p:h")
6060
if not TreeExplorer or cwd ~= TreeExplorer.cwd then
6161
lib.init(cwd)
6262
end
63-
view.open_in_current_win({ hijack_current_buf = false, resize = false })
64-
require"nvim-tree.renderer".draw()
65-
require"nvim-tree.actions.find-file".fn(bufname)
63+
view.open_in_current_win { hijack_current_buf = false, resize = false }
64+
require("nvim-tree.renderer").draw()
65+
require("nvim-tree.actions.find-file").fn(bufname)
6666
end
6767

6868
function M.tab_change()
69-
if view.is_visible({ any_tabpage = true }) then
69+
if view.is_visible { any_tabpage = true } then
7070
local bufname = vim.api.nvim_buf_get_name(0)
71-
if bufname:match("Neogit") ~= nil or bufname:match("--graph") ~= nil then
71+
if bufname:match "Neogit" ~= nil or bufname:match "--graph" ~= nil then
7272
return
7373
end
74-
view.open({ focus_tree = false })
75-
require"nvim-tree.renderer".draw()
74+
view.open { focus_tree = false }
75+
require("nvim-tree.renderer").draw()
7676
end
7777
end
7878

7979
local function find_existing_windows()
80-
return vim.tbl_filter(
81-
function(win)
82-
local buf = api.nvim_win_get_buf(win)
83-
return api.nvim_buf_get_name(buf):match("NvimTree") ~= nil
84-
end,
85-
api.nvim_list_wins()
86-
)
80+
return vim.tbl_filter(function(win)
81+
local buf = api.nvim_win_get_buf(win)
82+
return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
83+
end, api.nvim_list_wins())
8784
end
8885

8986
local function is_file_readable(fname)
9087
local stat = luv.fs_stat(fname)
91-
return stat and stat.type == "file" and luv.fs_access(fname, 'R')
88+
return stat and stat.type == "file" and luv.fs_access(fname, "R")
9289
end
9390

9491
local function update_base_dir_with_filepath(filepath, bufnr)
95-
local ft = api.nvim_buf_get_option(bufnr, 'filetype') or ""
92+
local ft = api.nvim_buf_get_option(bufnr, "filetype") or ""
9693
for _, value in pairs(_config.update_focused_file.ignore_list) do
9794
if utils.str_find(filepath, value) or utils.str_find(ft, value) then
9895
return
9996
end
10097
end
10198

10299
if not vim.startswith(filepath, TreeExplorer.cwd) then
103-
change_dir.fn(vim.fn.fnamemodify(filepath, ':p:h'))
100+
change_dir.fn(vim.fn.fnamemodify(filepath, ":p:h"))
104101
end
105102
end
106103

107104
function M.find_file(with_open, bufnr)
108-
if not with_open and not TreeExplorer then return end
105+
if not with_open and not TreeExplorer then
106+
return
107+
end
109108

110109
bufnr = bufnr or api.nvim_get_current_buf()
111110
local bufname = api.nvim_buf_get_name(bufnr)
112-
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ':p'))
111+
local filepath = utils.canonical_path(vim.fn.fnamemodify(bufname, ":p"))
113112
if not is_file_readable(filepath) then
114113
return
115114
end
@@ -123,19 +122,19 @@ function M.find_file(with_open, bufnr)
123122
if _config.update_focused_file.update_cwd then
124123
update_base_dir_with_filepath(filepath, bufnr)
125124
end
126-
require"nvim-tree.actions.find-file".fn(filepath)
125+
require("nvim-tree.actions.find-file").fn(filepath)
127126
end)
128127
end
129128

130129
M.resize = view.resize
131130

132131
local function should_abort_auto_close()
133132
local buf = api.nvim_get_current_buf()
134-
local buftype = api.nvim_buf_get_option(buf, 'ft')
133+
local buftype = api.nvim_buf_get_option(buf, "ft")
135134
local modified = vim.tbl_filter(function(b)
136-
return api.nvim_buf_get_option(b, 'modified')
135+
return api.nvim_buf_get_option(b, "modified")
137136
end, api.nvim_list_bufs())
138-
return #modified > 0 or buftype:match('Telescope') ~= nil
137+
return #modified > 0 or buftype:match "Telescope" ~= nil
139138
end
140139

141140
function M.auto_close()
@@ -154,9 +153,9 @@ function M.auto_close()
154153
return api.nvim_win_get_tabpage(w) == curtab
155154
end, windows)
156155
if #windows == 1 then
157-
api.nvim_command(':silent qa!')
156+
api.nvim_command ":silent qa!"
158157
elseif #wins_in_tabpage == 1 then
159-
api.nvim_command(':tabclose')
158+
api.nvim_command ":tabclose"
160159
end
161160
end, 50)
162161
end
@@ -199,23 +198,23 @@ function M.place_cursor_on_node()
199198
local idx = vim.fn.stridx(line, node.name)
200199

201200
if idx >= 0 then
202-
api.nvim_win_set_cursor(0, {cursor[1], idx})
201+
api.nvim_win_set_cursor(0, { cursor[1], idx })
203202
end
204203
end
205204

206205
function M.on_enter(netrw_disabled)
207206
local bufnr = api.nvim_get_current_buf()
208207
local bufname = api.nvim_buf_get_name(bufnr)
209-
local buftype = api.nvim_buf_get_option(bufnr, 'filetype')
208+
local buftype = api.nvim_buf_get_option(bufnr, "filetype")
210209
local ft_ignore = _config.ignore_ft_on_setup
211210

212211
local stats = luv.fs_stat(bufname)
213-
local is_dir = stats and stats.type == 'directory'
212+
local is_dir = stats and stats.type == "directory"
214213
local cwd
215214
if is_dir then
216215
cwd = vim.fn.expand(bufname)
217216
-- INFO: could potentially conflict with rooter plugins
218-
vim.cmd("noautocmd cd "..cwd)
217+
vim.cmd("noautocmd cd " .. cwd)
219218
end
220219

221220
local lines = not is_dir and api.nvim_buf_get_lines(bufnr, 0, -1, false) or {}
@@ -236,7 +235,10 @@ function M.on_enter(netrw_disabled)
236235
end
237236
end
238237

239-
local should_hijack = _config.hijack_directories.enable and _config.hijack_directories.auto_open and is_dir and not should_be_preserved
238+
local should_hijack = _config.hijack_directories.enable
239+
and _config.hijack_directories.auto_open
240+
and is_dir
241+
and not should_be_preserved
240242

241243
-- Session that left a NvimTree Buffer opened, reopen with it
242244
local existing_tree_wins = find_existing_windows()
@@ -249,7 +251,7 @@ function M.on_enter(netrw_disabled)
249251
lib.open()
250252

251253
if should_focus_other_window then
252-
vim.cmd("noautocmd wincmd p")
254+
vim.cmd "noautocmd wincmd p"
253255
end
254256
end
255257
M.initialized = true
@@ -345,15 +347,15 @@ local DEFAULT_OPTS = {
345347
enable = true,
346348
auto_open = true,
347349
},
348-
update_focused_file = {
350+
update_focused_file = {
349351
enable = false,
350352
update_cwd = false,
351-
ignore_list = {}
353+
ignore_list = {},
352354
},
353355
ignore_ft_on_setup = {},
354356
system_open = {
355-
cmd = nil,
356-
args = {}
357+
cmd = nil,
358+
args = {},
357359
},
358360
diagnostics = {
359361
enable = false,
@@ -363,12 +365,12 @@ local DEFAULT_OPTS = {
363365
info = "",
364366
warning = "",
365367
error = "",
366-
}
368+
},
367369
},
368370
filters = {
369371
dotfiles = false,
370372
custom = {},
371-
exclude = {}
373+
exclude = {},
372374
},
373375
git = {
374376
enable = true,
@@ -385,8 +387,8 @@ local DEFAULT_OPTS = {
385387
resize_window = false,
386388
window_picker = {
387389
enable = true,
388-
}
389-
}
390+
},
391+
},
390392
},
391393
}
392394

@@ -395,7 +397,7 @@ local function merge_options(conf)
395397
conf.hijack_directories = conf.update_to_buf_dir
396398
conf.update_to_buf_dir = nil
397399
end
398-
return vim.tbl_deep_extend('force', DEFAULT_OPTS, conf or {})
400+
return vim.tbl_deep_extend("force", DEFAULT_OPTS, conf or {})
399401
end
400402

401403
function M.setup(conf)
@@ -413,13 +415,13 @@ function M.setup(conf)
413415

414416
manage_netrw(opts.disable_netrw, opts.hijack_netrw)
415417

416-
require'nvim-tree.actions'.setup(opts)
417-
require'nvim-tree.colors'.setup()
418-
require'nvim-tree.diagnostics'.setup(opts)
419-
require'nvim-tree.explorer'.setup(opts)
420-
require'nvim-tree.git'.setup(opts)
421-
require'nvim-tree.view'.setup(opts)
422-
require'nvim-tree.lib'.setup(opts)
418+
require("nvim-tree.actions").setup(opts)
419+
require("nvim-tree.colors").setup()
420+
require("nvim-tree.diagnostics").setup(opts)
421+
require("nvim-tree.explorer").setup(opts)
422+
require("nvim-tree.git").setup(opts)
423+
require("nvim-tree.view").setup(opts)
424+
require("nvim-tree.lib").setup(opts)
423425

424426
setup_vim_commands()
425427
setup_autocommands(opts)

lua/nvim-tree/actions/change-dir.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
local a = vim.api
2-
local utils = require'nvim-tree.utils'
2+
local utils = require "nvim-tree.utils"
33

44
local M = {
55
current_tab = a.nvim_get_current_tabpage(),
66
options = {
77
global = false,
88
change_cwd = true,
9-
}
9+
},
1010
}
1111

1212
function M.fn(name, with_open)
13-
if not TreeExplorer then return end
13+
if not TreeExplorer then
14+
return
15+
end
1416

15-
local foldername = name == '..' and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ':h') or name
17+
local foldername = name == ".." and vim.fn.fnamemodify(utils.path_remove_trailing(TreeExplorer.cwd), ":h") or name
1618
local no_cwd_change = vim.fn.expand(foldername) == TreeExplorer.cwd
1719
local new_tab = a.nvim_get_current_tabpage()
1820
local is_window = (vim.v.event.scope == "window" or vim.v.event.changed_window) and new_tab == M.current_tab
@@ -26,16 +28,16 @@ end
2628
function M.force_dirchange(foldername, with_open)
2729
if M.options.change_cwd and vim.tbl_isempty(vim.v.event) then
2830
if M.options.global then
29-
vim.cmd('cd '..vim.fn.fnameescape(foldername))
31+
vim.cmd("cd " .. vim.fn.fnameescape(foldername))
3032
else
31-
vim.cmd('lcd '..vim.fn.fnameescape(foldername))
33+
vim.cmd("lcd " .. vim.fn.fnameescape(foldername))
3234
end
3335
end
34-
require'nvim-tree.lib'.init(foldername)
36+
require("nvim-tree.lib").init(foldername)
3537
if with_open then
36-
require"nvim-tree.lib".open()
38+
require("nvim-tree.lib").open()
3739
else
38-
require"nvim-tree.renderer".draw()
40+
require("nvim-tree.renderer").draw()
3941
end
4042
end
4143

lua/nvim-tree/actions/collapse-all.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local renderer = require"nvim-tree.renderer"
1+
local renderer = require "nvim-tree.renderer"
22

33
local M = {}
44

0 commit comments

Comments
 (0)