Skip to content

Commit 144c5b6

Browse files
committed
refactor(stylua): disable collapse_simple_statement
1 parent b44c5e5 commit 144c5b6

Some content is hidden

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

65 files changed

+971
-385
lines changed

.stylua.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ indent_type = "Spaces"
44
indent_width = 4
55
quote_style = "ForceDouble"
66
call_parentheses = "Always"
7-
# collapse_simple_statement = "FunctionOnly"
8-
collapse_simple_statement = "Always"

lua/leetcode-plugins/cn/api.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ statistics.solved = function(cb) ---@diagnostic disable-line
1717
utils.query(query, variables, {
1818
endpoint = urls.solved,
1919
callback = function(res, err)
20-
if err then return cb(nil, err) end
20+
if err then
21+
return cb(nil, err)
22+
end
2123

2224
local data = res.data
2325
local submit_stats = data["submit_stats"]
@@ -38,7 +40,9 @@ statistics.session_progress = function(cb)
3840

3941
utils.query(query, variables, {
4042
callback = function(res, err)
41-
if err then return cb(nil, err) end
43+
if err then
44+
return cb(nil, err)
45+
end
4246

4347
local data = res.data
4448
local session_progress = data["userProfileUserQuestionProgress"]["numAcceptedQuestions"]
@@ -57,7 +61,9 @@ statistics.calendar = function(cb) ---@diagnostic disable-line
5761
utils.query(query, variables, {
5862
endpoint = urls.calendar,
5963
callback = function(res, err)
60-
if err then return cb(nil, err) end
64+
if err then
65+
return cb(nil, err)
66+
end
6167

6268
local data = res.data
6369
local calendar = data["calendar"]
@@ -83,7 +89,9 @@ statistics.languages = function(cb) ---@diagnostic disable-line
8389
utils.query(query, variables, {
8490
endpoint = urls.languages,
8591
callback = function(res, err)
86-
if err then return cb(nil, err) end
92+
if err then
93+
return cb(nil, err)
94+
end
8795

8896
local data = res.data
8997
local lang_prob_count = data["languageProblemCount"]

lua/leetcode-plugins/cn/utils.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ local log = require("leetcode.logger")
33
local cn_utils = {}
44

55
---@param str string
6-
local function capitalizeFirst(str) return str:lower():gsub("^%l", string.upper) end
6+
local function capitalizeFirst(str)
7+
return str:lower():gsub("^%l", string.upper)
8+
end
79

810
---@return table
911
function cn_utils.calc_question_count(stats)

lua/leetcode-plugins/non_standalone/leetcode.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ local prev_cwd = nil
77
---@param on_vimenter boolean
88
leetcode.should_skip = function(on_vimenter)
99
if on_vimenter then
10-
if vim.fn.argc() ~= 1 then return true end
10+
if vim.fn.argc() ~= 1 then
11+
return true
12+
end
1113

1214
local usr_arg, arg = vim.fn.argv()[1], config.user.arg
13-
if usr_arg ~= arg then return true end
15+
if usr_arg ~= arg then
16+
return true
17+
end
1418

1519
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
1620
if #lines > 1 or (#lines == 1 and lines[1]:len() > 0) then
@@ -21,7 +25,7 @@ leetcode.should_skip = function(on_vimenter)
2125
else
2226
for _, buf_id in pairs(vim.api.nvim_list_bufs()) do
2327
local bufinfo = vim.fn.getbufinfo(buf_id)[1]
24-
if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then --
28+
if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then
2529
return false, true
2630
end
2731
end
@@ -33,7 +37,7 @@ end
3337
---@param on_vimenter boolean
3438
leetcode.start = function(on_vimenter)
3539
local skip, buflisted = leetcode.should_skip(on_vimenter)
36-
if skip then --
40+
if skip then
3741
return false
3842
end
3943

@@ -44,7 +48,7 @@ leetcode.start = function(on_vimenter)
4448
local theme = require("leetcode.theme")
4549
theme.setup()
4650

47-
if not on_vimenter then --
51+
if not on_vimenter then
4852
if buflisted then
4953
prev_cwd = vim.fn.getcwd()
5054
vim.cmd.tabe()
@@ -67,7 +71,9 @@ leetcode.start = function(on_vimenter)
6771
end
6872

6973
leetcode.stop = vim.schedule_wrap(function()
70-
if standalone then return vim.cmd("qa!") end
74+
if standalone then
75+
return vim.cmd("qa!")
76+
end
7177

7278
_Lc_state.menu:unmount()
7379

lua/leetcode-ui/group/cases.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ function Cases:make_nav()
2020
local nav = Lines({}, { padding = { top = 1 } })
2121

2222
for i, case in ipairs(self.cases) do
23-
self.console.result:map("n", i, function() self:change(i) end, { clearable = true })
23+
self.console.result:map("n", i, function()
24+
self:change(i)
25+
end, { clearable = true })
2426

2527
local hl = self:nav_case_hl(case, i)
2628
local msg = (" Case (%d) "):format(i)
2729

2830
nav:append(msg, hl)
29-
if i ~= #self.cases then nav:append(" ") end
31+
if i ~= #self.cases then
32+
nav:append(" ")
33+
end
3034
end
3135

3236
return nav
@@ -43,7 +47,9 @@ end
4347

4448
---@param idx integer
4549
function Cases:change(idx)
46-
if not self.cases[idx] or idx == self.idx then return end
50+
if not self.cases[idx] or idx == self.idx then
51+
return
52+
end
4753

4854
self.idx = idx
4955
self.console.result:draw()

lua/leetcode-ui/group/init.lua

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ function Group:contents()
3636
local items = utils.shallowcopy(self._.items)
3737

3838
local contents = Group.super.contents(self)
39-
if not vim.tbl_isempty(contents) then table.insert(items, Lines(contents)) end
39+
if not vim.tbl_isempty(contents) then
40+
table.insert(items, Lines(contents))
41+
end
4042

4143
return items
4244
end
@@ -51,27 +53,35 @@ function Group:draw(layout, opts)
5153
local toppad = padding and padding.top
5254
local botpad = padding and padding.bot
5355

54-
if toppad then Pad(toppad):draw(layout) end
56+
if toppad then
57+
Pad(toppad):draw(layout)
58+
end
5559

5660
local items = self:contents()
5761
for i, item in ipairs(items) do
5862
item:draw(layout, options:get())
59-
if i ~= #items and spacing then Pad(spacing):draw(layout) end
63+
if i ~= #items and spacing then
64+
Pad(spacing):draw(layout)
65+
end
6066
end
6167

62-
if botpad then Pad(botpad):draw(layout) end
68+
if botpad then
69+
Pad(botpad):draw(layout)
70+
end
6371
end
6472

6573
---@param item lc.ui.Lines
6674
function Group:insert(item)
67-
if not vim.tbl_isempty(Group.super.contents(self)) then self:endgrp() end
75+
if not vim.tbl_isempty(Group.super.contents(self)) then
76+
self:endgrp()
77+
end
6878
table.insert(self._.items, item)
6979

7080
return self
7181
end
7282

7383
function Group:append(content, highlight)
74-
if type(content) == "table" and O.is_instance(content, Group) then --
84+
if type(content) == "table" and O.is_instance(content, Group) then
7585
local items = content:contents()
7686

7787
for _, item in ipairs(items) do

lua/leetcode-ui/group/page/cache.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ page:insert(Title({ "Menu" }, "Cache"))
1818
local update_btn = Button("Update", {
1919
icon = "󱘴",
2020
sc = "u",
21-
on_press = function() cmd.cache_update() end,
21+
on_press = function()
22+
cmd.cache_update()
23+
end,
2224
})
2325

2426
local back_btn = BackButton("menu")

lua/leetcode-ui/group/page/menu.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,36 @@ page:insert(Title({}, "Menu"))
1818
local problems = Button("Problems", {
1919
icon = "",
2020
sc = "p",
21-
on_press = function() cmd.set_menu_page("problems") end,
21+
on_press = function()
22+
cmd.set_menu_page("problems")
23+
end,
2224
expandable = true,
2325
})
2426

2527
local statistics = Button("Statistics", {
2628
icon = "󰄪",
2729
sc = "s",
28-
on_press = function() cmd.set_menu_page("stats") end,
30+
on_press = function()
31+
cmd.set_menu_page("stats")
32+
end,
2933
expandable = true,
3034
})
3135

3236
local cookie = Button("Cookie", {
3337
icon = "󰆘",
3438
sc = "i",
35-
on_press = function() cmd.set_menu_page("cookie") end,
39+
on_press = function()
40+
cmd.set_menu_page("cookie")
41+
end,
3642
expandable = true,
3743
})
3844

3945
local cache = Button("Cache", {
4046
icon = "",
4147
sc = "c",
42-
on_press = function() cmd.set_menu_page("cache") end,
48+
on_press = function()
49+
cmd.set_menu_page("cache")
50+
end,
4351
expandable = true,
4452
})
4553

lua/leetcode-ui/group/page/stats.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ local skills = Button("Skills", {
3838
sc = "s",
3939
on_press = cmd.ui_skills,
4040
})
41-
if not config.is_cn then buttons:insert(skills) end
41+
if not config.is_cn then
42+
buttons:insert(skills)
43+
end
4244

4345
local languages = Button("Languages", {
4446
icon = "",

lua/leetcode-ui/group/pre/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
function Pre:init(title, item)
2424
Pre.super.init(self, {}, { spacing = 1, position = "left" })
2525

26-
if title then --
26+
if title then
2727
self:insert(title)
2828
end
2929

lua/leetcode-ui/group/pre/input.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ function Input:init(title, input, params) --
1313
local group = Group({}, { spacing = 1 })
1414

1515
for i, case in ipairs(input) do
16-
local ok, param = pcall(function() return params[i].name end)
17-
if ok then group:append(param .. " =", "leetcode_normal"):endl() end
16+
local ok, param = pcall(function()
17+
return params[i].name
18+
end)
19+
if ok then
20+
group:append(param .. " =", "leetcode_normal"):endl()
21+
end
1822
group:append(case):endgrp()
1923
end
2024

lua/leetcode-ui/group/tag/a.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ local log = require("leetcode.logger")
66
local A = Tag:extend("LeetTagA")
77

88
---@param url string
9-
local function norm_url(url) return url:lower():gsub("/$", ""):gsub("#.-$", "") end
9+
local function norm_url(url)
10+
return url:lower():gsub("/$", ""):gsub("#.-$", "")
11+
end
1012

1113
---@param u1 string
1214
---@param u2 string
13-
local function is_same_url(u1, u2) return norm_url(u1) == norm_url(u2) end
15+
local function is_same_url(u1, u2)
16+
return norm_url(u1) == norm_url(u2)
17+
end
1418

1519
function A:contents()
1620
local Group = require("leetcode-ui.group")

lua/leetcode-ui/group/tag/init.lua

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ function Tag.normalize(text)
5151
:gsub("\n", "&lcnl;")
5252
:gsub("\t", "&lctab;")
5353
:gsub("%s", " ")
54-
:gsub("<[^>]*>", function(match) return match:gsub("&nbsp;", " ") end)
54+
:gsub("<[^>]*>", function(match)
55+
return match:gsub("&nbsp;", " ")
56+
end)
5557
-- :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end)
5658

5759
log.debug(text)
@@ -71,7 +73,9 @@ function Tag:add_indent(item, text)
7173
end
7274
end
7375

74-
function Tag:get_text(node) return ts.get_node_text(node, self.text) end
76+
function Tag:get_text(node)
77+
return ts.get_node_text(node, self.text)
78+
end
7579

7680
---@param node TSNode
7781
---
@@ -95,7 +99,9 @@ end
9599
-- 1206
96100
---@param node TSNode
97101
function Tag:get_el_data(node)
98-
if node:type() ~= "element" then return {} end
102+
if node:type() ~= "element" then
103+
return {}
104+
end
99105

100106
local start_tag
101107
for child in node:iter_children() do
@@ -107,7 +113,9 @@ function Tag:get_el_data(node)
107113
end
108114
end
109115

110-
if not start_tag then return {} end
116+
if not start_tag then
117+
return {}
118+
end
111119

112120
local tag, attrs = nil, {}
113121
for child in start_tag:iter_children() do
@@ -147,7 +155,9 @@ function Tag:parse_node() --
147155
end
148156

149157
function Tag.trim(lines) --
150-
if not lines or vim.tbl_isempty(lines) then return {} end
158+
if not lines or vim.tbl_isempty(lines) then
159+
return {}
160+
end
151161

152162
while not vim.tbl_isempty(lines) and lines[1]:content() == "" do
153163
table.remove(lines, 1)
@@ -160,7 +170,9 @@ function Tag.trim(lines) --
160170
return lines
161171
end
162172

163-
local function req_tag(str) return require("leetcode-ui.group.tag." .. str) end
173+
local function req_tag(str)
174+
return require("leetcode-ui.group.tag." .. str)
175+
end
164176

165177
function Tag:contents()
166178
local items = Tag.super.contents(self)
@@ -224,13 +236,13 @@ end
224236
local LeetTag = Tag
225237

226238
---@param text string
227-
function Tag.static:parse(text) --
239+
function Tag.static:parse(text)
228240
---@type string
229241
local normalized = Normalizer:norm(text)
230242

231243
local ok, parser = pcall(ts.get_string_parser, normalized, "html")
232244

233-
if not ok then --
245+
if not ok then
234246
local Plain = require("leetcode.parser.plain")
235247
return Plain:parse(text)
236248
end

0 commit comments

Comments
 (0)