Skip to content

Commit

Permalink
chore(#2931): stylua -> EmmyLuaCodeStyle (#2932)
Browse files Browse the repository at this point in the history
* stylua -> EmmyLuaCodeStyle: config and doc

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle: CI

* stylua -> EmmyLuaCodeStyle

* stylua -> EmmyLuaCodeStyle: call_arg_parentheses = always

* stylua -> EmmyLuaCodeStyle

* stylua -> EmmyLuaCodeStyle
  • Loading branch information
alex-courtis authored Sep 29, 2024
1 parent 9650e73 commit 1ae1c33
Show file tree
Hide file tree
Showing 80 changed files with 593 additions and 586 deletions.
12 changes: 10 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ root = true
insert_final_newline = true
end_of_line = lf

[nvim-tree-lua.txt]
max_line_length = 78

[*.lua]
indent_style = space
max_line_length = 140
indent_size = 2

[nvim-tree-lua.txt]
max_line_length = 78
# EmmyLuaCodeStyle specific, see
# https://github.com/CppCXY/EmmyLuaCodeStyle/blob/master/lua.template.editorconfig
continuation_indent = 2
quote_style = double
call_arg_parentheses = always
space_before_closure_open_parenthesis = false
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ jobs:
runs-on: ubuntu-latest

concurrency:
group: ${{ github.workflow }}-${{ matrix.stylua_version }}-${{ github.head_ref || github.ref_name }}
group: ${{ github.workflow }}-${{ matrix.emmy_lua_code_style_version }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

strategy:
matrix:
stylua_version: [ 0.19.1 ]
emmy_lua_code_style_version: [ 1.5.6 ]

steps:
- uses: actions/checkout@v4

- name: stylua
uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ matrix.stylua_version }}
args: --check lua
- name: install emmy_lua_code_style
run: |
mkdir -p CodeFormat
curl -L "https://github.com/CppCXY/EmmyLuaCodeStyle/releases/download/${{ matrix.emmy_lua_code_style_version }}/linux-x64.tar.gz" | tar zx --directory CodeFormat
- run: echo "CodeFormat/linux-x64/bin" >> "$GITHUB_PATH"

- run: make style

- run: make style-doc

Expand Down
6 changes: 0 additions & 6 deletions .stylua.toml

This file was deleted.

10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ See [Development](https://github.com/nvim-tree/nvim-tree.lua/wiki/Development) f

Following are used during CI and strongly recommended during local development.

Language server: [luals](https://luals.github.io)

Lint: [luacheck](https://github.com/lunarmodules/luacheck/)

Style: [StyLua](https://github.com/JohnnyMorganz/StyLua)
Style: [EmmyLuaCodeStyle](https://github.com/CppCXY/EmmyLuaCodeStyle): `CodeCheck`

Language server: [luals](https://luals.github.io)
nvim-tree.lua migrated from stylua to EmmyLuaCodeStyle ~2024/10. `vim.lsp.buf.format()` may be used as it is the default formatter for luals

You can install them via you OS package manager e.g. `pacman`, `brew` or other via other package managers such as `cargo` or `luarocks`

Expand All @@ -34,14 +36,14 @@ make lint

## style

1. Runs stylua using `.stylua.toml` settings
1. Runs CodeCheck using `.editorconfig` settings
1. Runs `scripts/doc-comments.sh` to validate annotated documentation

```sh
make style
```

You can automatically fix stylua issues via:
You can automatically fix `CodeCheck` issues via:

```sh
make style-fix
Expand Down
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ all: lint style check
#
lint: luacheck

style: stylua style-doc
style: style-check style-doc

check: luals

Expand All @@ -15,8 +15,9 @@ check: luals
luacheck:
luacheck -q lua

stylua:
stylua lua --check
# --diagnosis-as-error does not function for workspace, hence we post-process the output
style-check:
CodeFormat check --config .editorconfig --diagnosis-as-error --workspace lua

style-doc:
scripts/doc-comments.sh
Expand All @@ -28,7 +29,7 @@ luals:
# fixes
#
style-fix:
stylua lua
CodeFormat format --config .editorconfig --workspace lua

#
# utility
Expand All @@ -43,5 +44,5 @@ help-check: help-update
git diff --exit-code doc/nvim-tree-lua.txt


.PHONY: all lint style check luacheck stylua style-doc luals style-fix help-update help-check
.PHONY: all lint style check luacheck style-check style-doc luals style-fix help-update help-check

36 changes: 18 additions & 18 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local lib = require "nvim-tree.lib"
local log = require "nvim-tree.log"
local appearance = require "nvim-tree.appearance"
local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local actions = require "nvim-tree.actions"
local core = require "nvim-tree.core"
local notify = require "nvim-tree.notify"
local lib = require("nvim-tree.lib")
local log = require("nvim-tree.log")
local appearance = require("nvim-tree.appearance")
local view = require("nvim-tree.view")
local utils = require("nvim-tree.utils")
local actions = require("nvim-tree.actions")
local core = require("nvim-tree.core")
local notify = require("nvim-tree.notify")

local _config = {}

Expand All @@ -21,7 +21,7 @@ function M.change_root(path, bufnr)
if type(bufnr) == "number" then
local ft

if vim.fn.has "nvim-0.10" == 1 then
if vim.fn.has("nvim-0.10") == 1 then
ft = vim.api.nvim_get_option_value("filetype", { buf = bufnr }) or ""
else
ft = vim.api.nvim_buf_get_option(bufnr, "filetype") or "" ---@diagnostic disable-line: deprecated
Expand Down Expand Up @@ -76,11 +76,11 @@ function M.change_root(path, bufnr)
end

function M.tab_enter()
if view.is_visible { any_tabpage = true } then
if view.is_visible({ any_tabpage = true }) then
local bufname = vim.api.nvim_buf_get_name(0)

local ft
if vim.fn.has "nvim-0.10" == 1 then
if vim.fn.has("nvim-0.10") == 1 then
ft = vim.api.nvim_get_option_value("filetype", { buf = 0 }) or ""
else
ft = vim.api.nvim_buf_get_option(0, "ft") ---@diagnostic disable-line: deprecated
Expand All @@ -91,7 +91,7 @@ function M.tab_enter()
return
end
end
view.open { focus_tree = false }
view.open({ focus_tree = false })

local explorer = core.get_explorer()
if explorer then
Expand Down Expand Up @@ -145,8 +145,8 @@ end
---@param hijack_netrw boolean
local function manage_netrw(disable_netrw, hijack_netrw)
if hijack_netrw then
vim.cmd "silent! autocmd! FileExplorer *"
vim.cmd "autocmd VimEnter * ++once silent! autocmd! FileExplorer *"
vim.cmd("silent! autocmd! FileExplorer *")
vim.cmd("autocmd VimEnter * ++once silent! autocmd! FileExplorer *")
end
if disable_netrw then
vim.g.loaded_netrw = 1
Expand Down Expand Up @@ -316,7 +316,7 @@ local function setup_autocommands(opts)
callback = function()
vim.schedule(function()
vim.api.nvim_buf_call(0, function()
vim.cmd [[norm! zz]]
vim.cmd([[norm! zz]])
end)
end)
end,
Expand Down Expand Up @@ -811,8 +811,8 @@ end

---@param conf table|nil
function M.setup(conf)
if vim.fn.has "nvim-0.9" == 0 then
notify.warn "nvim-tree.lua requires Neovim 0.9 or higher"
if vim.fn.has("nvim-0.9") == 0 then
notify.warn("nvim-tree.lua requires Neovim 0.9 or higher")
return
end

Expand Down Expand Up @@ -840,7 +840,7 @@ function M.setup(conf)
require("nvim-tree.notify").setup(opts)
require("nvim-tree.log").setup(opts)

if log.enabled "config" then
if log.enabled("config") then
log.line("config", "default config + user")
log.raw("config", "%s\n", vim.inspect(opts))
end
Expand Down
12 changes: 6 additions & 6 deletions lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local log = require "nvim-tree.log"
local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local Iterator = require "nvim-tree.iterators.node-iterator"
local log = require("nvim-tree.log")
local view = require("nvim-tree.view")
local utils = require("nvim-tree.utils")
local core = require("nvim-tree.core")
local Iterator = require("nvim-tree.iterators.node-iterator")

local M = {}

Expand Down Expand Up @@ -76,7 +76,7 @@ function M.fn(path)

if found and view.is_visible() then
explorer.renderer:draw()
view.set_cursor { line, 0 }
view.set_cursor({ line, 0 })
end

running[path_real] = false
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/actions/finders/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local M = {}

M.find_file = require "nvim-tree.actions.finders.find-file"
M.search_node = require "nvim-tree.actions.finders.search-node"
M.find_file = require("nvim-tree.actions.finders.find-file")
M.search_node = require("nvim-tree.actions.finders.search-node")

return M
8 changes: 4 additions & 4 deletions lua/nvim-tree/actions/finders/search-node.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local core = require "nvim-tree.core"
local core = require("nvim-tree.core")
local find_file = require("nvim-tree.actions.finders.find-file").fn

local M = {}
Expand Down Expand Up @@ -75,7 +75,7 @@ function M.fn()
local bufnr = vim.api.nvim_get_current_buf()

local path_existed, path_opt
if vim.fn.has "nvim-0.10" == 1 then
if vim.fn.has("nvim-0.10") == 1 then
path_existed, path_opt = pcall(vim.api.nvim_get_option_value, "path", { buf = bufnr })
vim.api.nvim_set_option_value("path", core.get_cwd() .. "/**", { buf = bufnr })
else
Expand All @@ -89,13 +89,13 @@ function M.fn()
end
-- reset &path
if path_existed then
if vim.fn.has "nvim-0.10" == 1 then
if vim.fn.has("nvim-0.10") == 1 then
vim.api.nvim_set_option_value("path", path_opt, { buf = bufnr })
else
vim.api.nvim_buf_set_option(bufnr, "path", path_opt) ---@diagnostic disable-line: deprecated
end
else
if vim.fn.has "nvim-0.10" == 1 then
if vim.fn.has("nvim-0.10") == 1 then
vim.api.nvim_set_option_value("path", nil, { buf = bufnr })
else
vim.api.nvim_buf_set_option(bufnr, "path", nil) ---@diagnostic disable-line: deprecated
Expand Down
22 changes: 11 additions & 11 deletions lua/nvim-tree/actions/fs/clipboard.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local lib = require "nvim-tree.lib"
local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local events = require "nvim-tree.events"
local notify = require "nvim-tree.notify"
local lib = require("nvim-tree.lib")
local log = require("nvim-tree.log")
local utils = require("nvim-tree.utils")
local core = require("nvim-tree.core")
local events = require("nvim-tree.events")
local notify = require("nvim-tree.notify")

local find_file = require("nvim-tree.actions.finders.find-file").fn

Expand Down Expand Up @@ -89,8 +89,8 @@ local function do_copy(source, destination)
break
end

local new_name = utils.path_join { source, name }
local new_destination = utils.path_join { destination, name }
local new_name = utils.path_join({ source, name })
local new_destination = utils.path_join({ destination, name })
success, errmsg = do_copy(new_name, new_destination)
if not success then
return false, errmsg
Expand Down Expand Up @@ -191,7 +191,7 @@ end
function Clipboard:clear_clipboard()
self.data[ACTION.copy] = {}
self.data[ACTION.cut] = {}
notify.info "Clipboard has been emptied."
notify.info("Clipboard has been emptied.")
self.explorer.renderer:draw()
end

Expand Down Expand Up @@ -240,7 +240,7 @@ function Clipboard:do_paste(node, action, action_fn)
end

for _, _node in ipairs(clip) do
local dest = utils.path_join { destination, _node.name }
local dest = utils.path_join({ destination, _node.name })
do_single_paste(_node.absolute_path, dest, action, action_fn)
end

Expand Down Expand Up @@ -361,7 +361,7 @@ function Clipboard:copy_path(node)

if node.name == ".." then
-- root
content = utils.path_add_trailing ""
content = utils.path_add_trailing("")
else
-- node
local absolute_path = node.absolute_path
Expand Down
18 changes: 9 additions & 9 deletions lua/nvim-tree/actions/fs/create-file.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local utils = require "nvim-tree.utils"
local events = require "nvim-tree.events"
local lib = require "nvim-tree.lib"
local core = require "nvim-tree.core"
local notify = require "nvim-tree.notify"
local utils = require("nvim-tree.utils")
local events = require("nvim-tree.events")
local lib = require("nvim-tree.lib")
local core = require("nvim-tree.core")
local notify = require("nvim-tree.notify")

local find_file = require("nvim-tree.actions.finders.find-file").fn

Expand Down Expand Up @@ -72,7 +72,7 @@ function M.fn(node)
end

if utils.file_exists(new_file_path) then
notify.warn "Cannot create: file already exists"
notify.warn("Cannot create: file already exists")
return
end

Expand All @@ -87,10 +87,10 @@ function M.fn(node)
for path in utils.path_split(new_file_path) do
idx = idx + 1
local p = utils.path_remove_trailing(path)
if #path_to_create == 0 and vim.fn.has "win32" == 1 then
path_to_create = utils.path_join { p, path_to_create }
if #path_to_create == 0 and vim.fn.has("win32") == 1 then
path_to_create = utils.path_join({ p, path_to_create })
else
path_to_create = utils.path_join { path_to_create, p }
path_to_create = utils.path_join({ path_to_create, p })
end
if is_last_path_file and idx == num_nodes then
create_and_notify(path_to_create)
Expand Down
8 changes: 4 additions & 4 deletions lua/nvim-tree/actions/fs/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local M = {}

M.create_file = require "nvim-tree.actions.fs.create-file"
M.remove_file = require "nvim-tree.actions.fs.remove-file"
M.rename_file = require "nvim-tree.actions.fs.rename-file"
M.trash = require "nvim-tree.actions.fs.trash"
M.create_file = require("nvim-tree.actions.fs.create-file")
M.remove_file = require("nvim-tree.actions.fs.remove-file")
M.rename_file = require("nvim-tree.actions.fs.rename-file")
M.trash = require("nvim-tree.actions.fs.trash")

function M.setup(opts)
M.remove_file.setup(opts)
Expand Down
Loading

0 comments on commit 1ae1c33

Please sign in to comment.