Skip to content

Commit

Permalink
MISC: Improve the lua linter and shellchecker
Browse files Browse the repository at this point in the history
Shellcheck and lua linting now extends behond the tde directory.
It now also verifies the profiler and plugins.

The test suite should still need some linting perhaps
  • Loading branch information
F0xedb committed Mar 17, 2021
1 parent b2cbfc2 commit 420132b
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/shellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore: sidebar hooks
ignore: sidebar
4 changes: 3 additions & 1 deletion hooks/commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function log() {

function run_prepend_commit_msg() {
GREP_REGEX=""
# shellcheck disable=SC2068
for t in ${VALID_START_REGEX[@]}; do
GREP_REGEX="$GREP_REGEX|^$t: "
done
Expand All @@ -58,6 +59,7 @@ function run_prepend_commit_msg() {
log "$COMMIT_MSG_EXIT_CODE" "Commit message prepended"
else
COMMIT_MSG_EXIT_CODE="1"
# shellcheck disable=SC2068
for t in ${VALID_START_REGEX[@]}; do
echo -e "\e[32m$t:\e[39m \e[33m$1\e[39m"
done
Expand Down Expand Up @@ -109,7 +111,7 @@ function run_check_if_merge_commit {
fi
}

data="$(sed '/^ *#/d' "$1")"
data="$(sed '/^ *#/d' "$MSG")"

run_check_if_merge_commit "$data"
run_prepend_commit_msg "$data"
Expand Down
7 changes: 5 additions & 2 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function log() {
len="$((${#2} - 1))"
columns=$(tput cols)
echo -en "$2 "
printf '.%.0s' $(seq $(( $columns - $len - 15)))
printf '.%.0s' $(seq $(( columns - len - 15)))

if [[ "$1" == "$WARNING" ]]; then
_warning="${3:-WARNING}"
Expand Down Expand Up @@ -65,6 +65,7 @@ function run_linter_shell() {

SHELL_LINTING_OUT=""
SHELL_LINTING_EXIT_CODE=""
# shellcheck disable=SC2044
for file in $(find . -type f -name "*.sh" ! -name "rofi-spotlight.sh"); do
out="$(shellcheck "$file")"
code="$?"
Expand Down Expand Up @@ -105,6 +106,7 @@ function run_license_linter_lua() {
--SOFTWARE.
]]"
_LICENSE_LUA_OUT=""
# shellcheck disable=SC2044
for file in $(find . -type f -name "*.lua" ! -name "release.lua" -not -path "*lib-lua*"); do
out="$(head -n24 "$file")"
if [[ ! "$out" == "$_LICENSE" ]]; then
Expand Down Expand Up @@ -147,6 +149,7 @@ function run_license_linter_bash() {
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE."
_LICENSE_BASH_OUT=""
# shellcheck disable=SC2044
for file in $(find . -type f -name "*.sh"); do
out="$(head -n24 "$file")"
if [[ ! "$out" == "$_LICENSE" ]]; then
Expand All @@ -163,7 +166,7 @@ function run_license_linter_bash() {
}

function run_test_suite() {
if [[ "$(cat /etc/os-release | grep '^NAME' | cut -d'=' -f2 | tr -d '"')" == "TOS Linux" ]]; then
if [[ "$(grep '^NAME' /etc/os-release | cut -d'=' -f2 | tr -d '"')" == "TOS Linux" ]]; then
UNIT_TEST_OUT="$(bash test-runner.sh 2>/dev/null)"
UNIT_EXIT_CODE="$?"
else
Expand Down
2 changes: 1 addition & 1 deletion hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function log() {
len="$((${#2} - 1))"
columns=$(tput cols)
echo -en "$2 "
printf '.%.0s' $(seq $(($columns - $len - 15)))
printf '.%.0s' $(seq $((columns - len - 15)))

if [[ ! "$1" -eq "0" ]]; then
echo -e " \e[30m\e[41m FAILED \e[49m\e[39m"
Expand Down
2 changes: 1 addition & 1 deletion plugins/calendar-bare-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local cal =
}

-- generate a text widget that acts like the header
header =
local header =
wibox.widget {
text = "Calendar",
font = "SFNS Display Regular 14",
Expand Down
3 changes: 1 addition & 2 deletions plugins/desktop-widgets/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ local rounded = require("lib-tde.widget.rounded")
-- title is the text below the progress bar
-- timeout is an optional value that specifies how often to update the widget default to one second
-- bar_size is an optional value that specifies how thick the radial bar should be
local chart = function(x, y, width, height, title, fillFunc, timeout, bar_size)
local chart = function(x, y, width, height, title, fillFunc, timeout, _)
timeout = timeout or 1
bar_size = bar_size or 8

local margin_ratio = 0.10 -- in percentage
local bar_ratio = 0.75 -- in percentage
Expand Down
22 changes: 11 additions & 11 deletions plugins/docker-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ local status_to_icon_name = {
}

local function worker(args)
local args = args or {}
args = args or {}

local icon = args.icon or ICONS_DIR .. "docker.svg"
local number_of_containers = args.number_of_containers or -1
Expand Down Expand Up @@ -225,14 +225,14 @@ local function worker(args)

awful.spawn.easy_async(
"docker " .. command .. " " .. container["name"],
function(stdout, stderr)
if stderr ~= "" then
show_warning(stderr)
function(_, stderr_2)
if stderr_2 ~= "" then
show_warning(stderr_2)
end
spawn.easy_async(
string.format(LIST_CONTAINERS_CMD, number_of_containers),
function(stdout, stderr)
rebuild_widget(stdout, stderr)
function(stdout_3, stderr_3)
rebuild_widget(stdout_3, stderr_3)
end
)
end
Expand Down Expand Up @@ -293,14 +293,14 @@ local function worker(args)

awful.spawn.easy_async(
"docker " .. command .. " " .. container["name"],
function(stdout, stderr)
if stderr ~= "" then
show_warning(stderr)
function(_, stderr2)
if stderr2 ~= "" then
show_warning(stderr2)
end
spawn.easy_async(
string.format(LIST_CONTAINERS_CMD, number_of_containers),
function(stdout, stderr)
rebuild_widget(stdout, stderr)
function(stdout3, stderr3)
rebuild_widget(stdout3, stderr3)
end
)
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/error-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
--local wibox = require("wibox")

-- generate a text widget that acts like the header
header =
local header =
wibox.widget {
text = "Error",
font = "SFNS Display Regular 14",
Expand Down
15 changes: 6 additions & 9 deletions plugins/github-contributions-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ local dpi = require("beautiful").xresources.apply_dpi

local GET_CONTRIBUTIONS_CMD =
[[bash -c "curl -s https://github-contributions.now.sh/api/v1/%s | jq -r '[.contributions[] | select ( .date | strptime(\"%%Y-%%m-%%d\") | mktime < now)][:%s]| .[].color'"]]
-- in case github-contributions.now.sh stops working contributions can be scrapped from the github.com with the command below. Note that the order is reversed.
local GET_CONTRIBUTIONS_CMD_FALLBACK =
[[bash -c "curl -s https://github.com/users/%s/contributions | grep -o '\" fill=\"\#[0-9a-fA-F]\{6\}\" da' | grep -o '\#[0-9a-fA-F]\{6\}'"]]

local github_contributions_widget =
wibox.widget {
Expand All @@ -53,7 +50,7 @@ local github_contributions_widget =
}

local function worker(args)
local args = args or {}
args = args or {}

local username = args.username or "F0xedb"
local days = args.days or 60
Expand All @@ -77,10 +74,10 @@ local function worker(args)
local r, g, b = hex2rgb(color)

return wibox.widget {
fit = function(self, context, width, height)
fit = function(_, _, _, _)
return dpi(7), dpi(7)
end,
draw = function(self, context, cr, width, height)
draw = function(_, _, cr, _, _)
cr:set_source_rgb(r / 255, g / 255, b / 255)
cr:rectangle(0, 0, with_border and dpi(5) or dpi(7), with_border and dpi(5) or dpi(7))
cr:fill()
Expand All @@ -92,11 +89,11 @@ local function worker(args)
local col = {layout = wibox.layout.fixed.vertical}
local row = {layout = wibox.layout.fixed.horizontal}
local a = 5 - os.date("%w")
for i = 0, a do
for _ = 0, a do
table.insert(col, get_square("#ebedf0"))
end

local update_widget = function(widget, stdout, _, _, _)
local update_widget = function(_, stdout, _, _, _)
for colors in stdout:gmatch("[^\r\n]+") do
if a % 7 == 0 then
table.insert(row, col)
Expand All @@ -116,7 +113,7 @@ local function worker(args)

awful.spawn.easy_async(
string.format(GET_CONTRIBUTIONS_CMD, username, days),
function(stdout, stderr)
function(stdout, _)
update_widget(github_contributions_widget, stdout)
end
)
Expand Down
6 changes: 3 additions & 3 deletions plugins/hello-world-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ local beautiful = require("beautiful")
local PATH_TO_ICONS = os.getenv("HOME") .. "/.config/tde/hello-world-widget/icons/"

-- generate the icon widget
hello_icon_widget =
local hello_icon_widget =
wibox.widget {
{
id = "icon",
Expand All @@ -47,7 +47,7 @@ hello_icon_widget =
}

-- generate a text widget that acts like the header
hello_header =
local hello_header =
wibox.widget {
text = "Hello, World!",
font = "SFNS Display Regular 14",
Expand All @@ -57,7 +57,7 @@ hello_header =
}

-- generate a text widget that acts like a subtitle
hello_subtitle =
local hello_subtitle =
wibox.widget {
text = "Good to see you",
font = "SFNS Display Regular 16",
Expand Down
37 changes: 11 additions & 26 deletions plugins/jira-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ local naughty = require("naughty")
local gears = require("gears")
local beautiful = require("beautiful")
local gfs = require("gears.filesystem")
local color = require("gears.color")
local clickable_container = require("widget.material.clickable-container")
local dpi = require("beautiful").xresources.apply_dpi

Expand Down Expand Up @@ -76,23 +75,11 @@ local image =

local button = wibox.container.margin(image, 0, dpi(5), 0, 0)

local urgent_widget = {
id = "d",
draw = function(self, context, cr, width, height)
cr:set_source(color(beautiful.fg_urgent))
cr:arc(height / 4, height / 4, height / 4, 0, math.pi * 2)
cr:fill()
end,
visible = false,
layout = wibox.widget.base.make_widget
}

local jira_widget =
wibox.widget {
{
{
button,
urgent,
id = "b",
layout = wibox.layout.stack
},
Expand All @@ -108,17 +95,15 @@ local jira_widget =
set_text = function(self, new_value)
self.txt.text = new_value
end,
set_icon = function(self, path)
set_icon = function(_, path)
image:set_icon(path)
end,
is_everything_ok = function(self, is_ok)
if is_ok then
urgent_widget.visible = false
image:set_opacity(1)
image:emit_signal("widget:redraw_needed")
else
self.txt:set_text("")
urgent_widget.visible = true
image:set_opacity(0.2)
image:emit_signal("widget:redraw_needed")
end
Expand Down Expand Up @@ -162,7 +147,7 @@ local tooltip =
preferred_positions = {"bottom"}
}

local function createRow(issue, host, path_to_avatar)
local function createRow(issue, host_in, path_to_avatar)
local row =
wibox.widget {
{
Expand Down Expand Up @@ -224,7 +209,7 @@ local function createRow(issue, host, path_to_avatar)
{},
1,
function()
spawn.with_shell("xdg-open " .. host .. "/browse/" .. issue.key)
spawn.with_shell("xdg-open " .. host_in .. "/browse/" .. issue.key)
popup.visible = false
grabber:stop()
end
Expand All @@ -234,7 +219,7 @@ local function createRow(issue, host, path_to_avatar)
return row
end

local function createRowTable(issues, host)
local function createRowTable(issues, host_in)
local rows = {
{widget = wibox.widget.textbox},
layout = wibox.layout.fixed.vertical
Expand All @@ -255,34 +240,34 @@ local function createRowTable(issues, host)
)
end
end
table.insert(rows, createRow(issue, host, path_to_avatar))
table.insert(rows, createRow(issue, host_in, path_to_avatar))
end
return rows
end

local function createTable(result, host, maxelements)
local function createTable(result_in, host_in, maxelements)
if maxelements == nil then
maxelements = #result.issues
maxelements = #result_in.issues
end

-- the partial variable hold the result set of one vertical table set
local partialIssues = {}
local previousTableIndex = 1
-- arr holds the information about one vertical table set
local arr = {}
for index, issue in ipairs(result.issues) do
for index, issue in ipairs(result_in.issues) do
-- get the index in the table
local tableIndex = math.ceil(index / maxelements)
if not (previousTableIndex == tableIndex) then
table.insert(arr, createRowTable(partialIssues, host))
table.insert(arr, createRowTable(partialIssues, host_in))
-- reset variable for next vertical set
partialIssues = {}
previousTableIndex = tableIndex
end
table.insert(partialIssues, issue)
print("Inserting issue: " .. issue.key .. " into " .. tableIndex)
end
table.insert(arr, createRowTable(partialIssues, host))
table.insert(arr, createRowTable(partialIssues, host_in))
local table_widget =
wibox.widget {
arr[1],
Expand All @@ -301,7 +286,7 @@ local function createTable(result, host, maxelements)
end

local function worker(args)
local args = args or {}
args = args or {}

local icon = args.icon or HOME_DIR .. "/.config/tde/jira-widget/jira-mark-gradient-blue.svg"
host = args.host or show_warning("Jira host is unknown")
Expand Down
4 changes: 2 additions & 2 deletions plugins/jira-widget/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ local function escape_char(c)
return "\\" .. (escape_char_map[c] or string.format("u%04x", c:byte()))
end

local function encode_nil(val)
local function encode_nil(_)
return "null"
end

Expand Down Expand Up @@ -101,7 +101,7 @@ local function encode_table(val, stack)
error("invalid table: sparse array")
end
-- Encode
for i, v in ipairs(val) do
for _, v in ipairs(val) do
table.insert(res, encode(v, stack))
end
stack[val] = nil
Expand Down
2 changes: 1 addition & 1 deletion plugins/settings-app-widget/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ local function create()

local function decorate_cell(widget, flag, _)
local props = styles[flag] or {}
ret = widget
local ret = widget
if flag == "focus" then
ret =
wibox.container.margin(
Expand Down
Loading

0 comments on commit 420132b

Please sign in to comment.