Skip to content

Commit

Permalink
refactor(stylua): disable collapse_simple_statement
Browse files Browse the repository at this point in the history
  • Loading branch information
kawre committed Feb 29, 2024
1 parent b44c5e5 commit 144c5b6
Show file tree
Hide file tree
Showing 65 changed files with 971 additions and 385 deletions.
2 changes: 0 additions & 2 deletions .stylua.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ indent_type = "Spaces"
indent_width = 4
quote_style = "ForceDouble"
call_parentheses = "Always"
# collapse_simple_statement = "FunctionOnly"
collapse_simple_statement = "Always"
16 changes: 12 additions & 4 deletions lua/leetcode-plugins/cn/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ statistics.solved = function(cb) ---@diagnostic disable-line
utils.query(query, variables, {
endpoint = urls.solved,
callback = function(res, err)
if err then return cb(nil, err) end
if err then
return cb(nil, err)
end

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

utils.query(query, variables, {
callback = function(res, err)
if err then return cb(nil, err) end
if err then
return cb(nil, err)
end

local data = res.data
local session_progress = data["userProfileUserQuestionProgress"]["numAcceptedQuestions"]
Expand All @@ -57,7 +61,9 @@ statistics.calendar = function(cb) ---@diagnostic disable-line
utils.query(query, variables, {
endpoint = urls.calendar,
callback = function(res, err)
if err then return cb(nil, err) end
if err then
return cb(nil, err)
end

local data = res.data
local calendar = data["calendar"]
Expand All @@ -83,7 +89,9 @@ statistics.languages = function(cb) ---@diagnostic disable-line
utils.query(query, variables, {
endpoint = urls.languages,
callback = function(res, err)
if err then return cb(nil, err) end
if err then
return cb(nil, err)
end

local data = res.data
local lang_prob_count = data["languageProblemCount"]
Expand Down
4 changes: 3 additions & 1 deletion lua/leetcode-plugins/cn/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ local log = require("leetcode.logger")
local cn_utils = {}

---@param str string
local function capitalizeFirst(str) return str:lower():gsub("^%l", string.upper) end
local function capitalizeFirst(str)
return str:lower():gsub("^%l", string.upper)
end

---@return table
function cn_utils.calc_question_count(stats)
Expand Down
18 changes: 12 additions & 6 deletions lua/leetcode-plugins/non_standalone/leetcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ local prev_cwd = nil
---@param on_vimenter boolean
leetcode.should_skip = function(on_vimenter)
if on_vimenter then
if vim.fn.argc() ~= 1 then return true end
if vim.fn.argc() ~= 1 then
return true
end

local usr_arg, arg = vim.fn.argv()[1], config.user.arg
if usr_arg ~= arg then return true end
if usr_arg ~= arg then
return true
end

local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
if #lines > 1 or (#lines == 1 and lines[1]:len() > 0) then
Expand All @@ -21,7 +25,7 @@ leetcode.should_skip = function(on_vimenter)
else
for _, buf_id in pairs(vim.api.nvim_list_bufs()) do
local bufinfo = vim.fn.getbufinfo(buf_id)[1]
if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then --
if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then
return false, true
end
end
Expand All @@ -33,7 +37,7 @@ end
---@param on_vimenter boolean
leetcode.start = function(on_vimenter)
local skip, buflisted = leetcode.should_skip(on_vimenter)
if skip then --
if skip then
return false
end

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

if not on_vimenter then --
if not on_vimenter then
if buflisted then
prev_cwd = vim.fn.getcwd()
vim.cmd.tabe()
Expand All @@ -67,7 +71,9 @@ leetcode.start = function(on_vimenter)
end

leetcode.stop = vim.schedule_wrap(function()
if standalone then return vim.cmd("qa!") end
if standalone then
return vim.cmd("qa!")
end

_Lc_state.menu:unmount()

Expand Down
12 changes: 9 additions & 3 deletions lua/leetcode-ui/group/cases.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ function Cases:make_nav()
local nav = Lines({}, { padding = { top = 1 } })

for i, case in ipairs(self.cases) do
self.console.result:map("n", i, function() self:change(i) end, { clearable = true })
self.console.result:map("n", i, function()
self:change(i)
end, { clearable = true })

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

nav:append(msg, hl)
if i ~= #self.cases then nav:append(" ") end
if i ~= #self.cases then
nav:append(" ")
end
end

return nav
Expand All @@ -43,7 +47,9 @@ end

---@param idx integer
function Cases:change(idx)
if not self.cases[idx] or idx == self.idx then return end
if not self.cases[idx] or idx == self.idx then
return
end

self.idx = idx
self.console.result:draw()
Expand Down
22 changes: 16 additions & 6 deletions lua/leetcode-ui/group/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ function Group:contents()
local items = utils.shallowcopy(self._.items)

local contents = Group.super.contents(self)
if not vim.tbl_isempty(contents) then table.insert(items, Lines(contents)) end
if not vim.tbl_isempty(contents) then
table.insert(items, Lines(contents))
end

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

if toppad then Pad(toppad):draw(layout) end
if toppad then
Pad(toppad):draw(layout)
end

local items = self:contents()
for i, item in ipairs(items) do
item:draw(layout, options:get())
if i ~= #items and spacing then Pad(spacing):draw(layout) end
if i ~= #items and spacing then
Pad(spacing):draw(layout)
end
end

if botpad then Pad(botpad):draw(layout) end
if botpad then
Pad(botpad):draw(layout)
end
end

---@param item lc.ui.Lines
function Group:insert(item)
if not vim.tbl_isempty(Group.super.contents(self)) then self:endgrp() end
if not vim.tbl_isempty(Group.super.contents(self)) then
self:endgrp()
end
table.insert(self._.items, item)

return self
end

function Group:append(content, highlight)
if type(content) == "table" and O.is_instance(content, Group) then --
if type(content) == "table" and O.is_instance(content, Group) then
local items = content:contents()

for _, item in ipairs(items) do
Expand Down
4 changes: 3 additions & 1 deletion lua/leetcode-ui/group/page/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ page:insert(Title({ "Menu" }, "Cache"))
local update_btn = Button("Update", {
icon = "󱘴",
sc = "u",
on_press = function() cmd.cache_update() end,
on_press = function()
cmd.cache_update()
end,
})

local back_btn = BackButton("menu")
Expand Down
16 changes: 12 additions & 4 deletions lua/leetcode-ui/group/page/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,36 @@ page:insert(Title({}, "Menu"))
local problems = Button("Problems", {
icon = "",
sc = "p",
on_press = function() cmd.set_menu_page("problems") end,
on_press = function()
cmd.set_menu_page("problems")
end,
expandable = true,
})

local statistics = Button("Statistics", {
icon = "󰄪",
sc = "s",
on_press = function() cmd.set_menu_page("stats") end,
on_press = function()
cmd.set_menu_page("stats")
end,
expandable = true,
})

local cookie = Button("Cookie", {
icon = "󰆘",
sc = "i",
on_press = function() cmd.set_menu_page("cookie") end,
on_press = function()
cmd.set_menu_page("cookie")
end,
expandable = true,
})

local cache = Button("Cache", {
icon = "",
sc = "c",
on_press = function() cmd.set_menu_page("cache") end,
on_press = function()
cmd.set_menu_page("cache")
end,
expandable = true,
})

Expand Down
4 changes: 3 additions & 1 deletion lua/leetcode-ui/group/page/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ local skills = Button("Skills", {
sc = "s",
on_press = cmd.ui_skills,
})
if not config.is_cn then buttons:insert(skills) end
if not config.is_cn then
buttons:insert(skills)
end

local languages = Button("Languages", {
icon = "",
Expand Down
2 changes: 1 addition & 1 deletion lua/leetcode-ui/group/pre/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
function Pre:init(title, item)
Pre.super.init(self, {}, { spacing = 1, position = "left" })

if title then --
if title then
self:insert(title)
end

Expand Down
8 changes: 6 additions & 2 deletions lua/leetcode-ui/group/pre/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ function Input:init(title, input, params) --
local group = Group({}, { spacing = 1 })

for i, case in ipairs(input) do
local ok, param = pcall(function() return params[i].name end)
if ok then group:append(param .. " =", "leetcode_normal"):endl() end
local ok, param = pcall(function()
return params[i].name
end)
if ok then
group:append(param .. " =", "leetcode_normal"):endl()
end
group:append(case):endgrp()
end

Expand Down
8 changes: 6 additions & 2 deletions lua/leetcode-ui/group/tag/a.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ local log = require("leetcode.logger")
local A = Tag:extend("LeetTagA")

---@param url string
local function norm_url(url) return url:lower():gsub("/$", ""):gsub("#.-$", "") end
local function norm_url(url)
return url:lower():gsub("/$", ""):gsub("#.-$", "")
end

---@param u1 string
---@param u2 string
local function is_same_url(u1, u2) return norm_url(u1) == norm_url(u2) end
local function is_same_url(u1, u2)
return norm_url(u1) == norm_url(u2)
end

function A:contents()
local Group = require("leetcode-ui.group")
Expand Down
28 changes: 20 additions & 8 deletions lua/leetcode-ui/group/tag/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function Tag.normalize(text)
:gsub("\n", "&lcnl;")
:gsub("\t", "&lctab;")
:gsub("%s", " ")
:gsub("<[^>]*>", function(match) return match:gsub("&nbsp;", " ") end)
:gsub("<[^>]*>", function(match)
return match:gsub("&nbsp;", " ")
end)
-- :gsub("<a[^>]*>(.-)</a>", function(match) return match:gsub("&#?%w+;", utils.entity) end)

log.debug(text)
Expand All @@ -71,7 +73,9 @@ function Tag:add_indent(item, text)
end
end

function Tag:get_text(node) return ts.get_node_text(node, self.text) end
function Tag:get_text(node)
return ts.get_node_text(node, self.text)
end

---@param node TSNode
---
Expand All @@ -95,7 +99,9 @@ end
-- 1206
---@param node TSNode
function Tag:get_el_data(node)
if node:type() ~= "element" then return {} end
if node:type() ~= "element" then
return {}
end

local start_tag
for child in node:iter_children() do
Expand All @@ -107,7 +113,9 @@ function Tag:get_el_data(node)
end
end

if not start_tag then return {} end
if not start_tag then
return {}
end

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

function Tag.trim(lines) --
if not lines or vim.tbl_isempty(lines) then return {} end
if not lines or vim.tbl_isempty(lines) then
return {}
end

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

local function req_tag(str) return require("leetcode-ui.group.tag." .. str) end
local function req_tag(str)
return require("leetcode-ui.group.tag." .. str)
end

function Tag:contents()
local items = Tag.super.contents(self)
Expand Down Expand Up @@ -224,13 +236,13 @@ end
local LeetTag = Tag

---@param text string
function Tag.static:parse(text) --
function Tag.static:parse(text)
---@type string
local normalized = Normalizer:norm(text)

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

if not ok then --
if not ok then
local Plain = require("leetcode.parser.plain")
return Plain:parse(text)
end
Expand Down
Loading

0 comments on commit 144c5b6

Please sign in to comment.