Skip to content

Commit

Permalink
Merge pull request #21 from PMassicotte/fix-selene-warnings
Browse files Browse the repository at this point in the history
Fix selene warnings
  • Loading branch information
jalvesaq authored Feb 8, 2024
2 parents 5850a11 + 5be050f commit de260c1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 52 deletions.
1 change: 0 additions & 1 deletion .github/workflows/selene.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
# selene arguments
args: . --config selene.toml
version: 0.26.1
81 changes: 36 additions & 45 deletions lua/r/job.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
local M = {}
local jobs = {}
local incomplete_input = {size = 0, received = 0, str = ''}
local incomplete_input = { size = 0, received = 0, str = "" }
local waiting_more_input = false
local warn = require("r").warn

local stop_waiting_nsr = function (_)
local stop_waiting_nsr = function(_)
if waiting_more_input then
waiting_more_input = false
warn('Incomplete string received. Expected ' ..
incomplete_input.size .. ' bytes; received ' ..
incomplete_input.received .. '.')
warn(
"Incomplete string received. Expected "
.. incomplete_input.size
.. " bytes; received "
.. incomplete_input.received
.. "."
)
end
incomplete_input = {size = 0, received = 0, str = ''}
incomplete_input = { size = 0, received = 0, str = "" }
end

M.on_stdout = function (job_id, data, _)
M.on_stdout = function(job_id, data, _)
local cmd
for _, v in pairs(data) do
cmd = v:gsub('\r', '')
cmd = v:gsub("\r", "")
if #cmd > 0 then
if cmd:sub(1, 1) == "\017" then
local cmdsplt = vim.fn.split(cmd, "\017")
Expand All @@ -43,51 +47,46 @@ M.on_stdout = function (job_id, data, _)
else
incomplete_input.str = incomplete_input.str .. cmd
if incomplete_input.received > incomplete_input.size then
warn('Received larger than expected message.')
warn("Received larger than expected message.")
end
goto continue
end
end

if cmd:match("^lua ") or cmd:match("^call ") or cmd:match("^let ") or cmd:match("^unlet ") then
if
cmd:match("^lua ")
or cmd:match("^call ")
or cmd:match("^let ")
or cmd:match("^unlet ")
then
vim.fn.execute(cmd)
else
if cmd:len() > 128 then
cmd = cmd:sub(1, 128) .. ' [...]'
end
if cmd:len() > 128 then cmd = cmd:sub(1, 128) .. " [...]" end
warn("[" .. M.get_title(job_id) .. "] Unknown command: " .. cmd)
end
end
::continue::
end
end

M.on_stderr = function (job_id, data, _)
local msg = table.concat(data):gsub('\r', '')
if not msg:match("^%s*$") then
warn("[" .. M.get_title(job_id) .. "] " .. msg)
end
M.on_stderr = function(job_id, data, _)
local msg = table.concat(data):gsub("\r", "")
if not msg:match("^%s*$") then warn("[" .. M.get_title(job_id) .. "] " .. msg) end
end

M.on_exit = function (job_id, data, _)
M.on_exit = function(job_id, data, _)
local key = M.get_title(job_id)
if key ~= "Job" then
jobs[key] = 0
end
if data ~= 0 then
warn('"' .. key .. '"' .. ' exited with status ' .. data)
end
if key == 'R' or key == 'RStudio' then
if key ~= "Job" then jobs[key] = 0 end
if data ~= 0 then warn('"' .. key .. '"' .. " exited with status " .. data) end
if key == "R" or key == "RStudio" then
if M.is_running("Server") then
vim.g.R_Nvim_status = 3
else
vim.g.R_Nvim_status = 1
end
require("r.run").clear_R_info()
end
if key == 'Server' then
vim.g.R_Nvim_status = 1
end
if key == "Server" then vim.g.R_Nvim_status = 1 end
end

local default_handlers = {
Expand All @@ -98,9 +97,7 @@ local default_handlers = {

M.start = function(nm, cmd, opt)
local h = default_handlers
if opt then
h = opt
end
if opt then h = opt end
local jobid = vim.fn.jobstart(cmd, h)
if jobid == 0 then
warn("Invalid arguments in: " .. tostring(cmd))
Expand All @@ -122,29 +119,23 @@ M.R_term_open = function(cmd)
end
end

M.get_title = function (job_id)
M.get_title = function(job_id)
for key, value in pairs(jobs) do
if value == job_id then
return key
end
if value == job_id then return key end
end
return "Job"
end

M.stdin = function (job, cmd)
vim.fn.chansend(jobs[job], cmd)
end
M.stdin = function(job, cmd) vim.fn.chansend(jobs[job], cmd) end

M.is_running = function (key)
if jobs[key] and jobs[key] ~= 0 then
return true
end
M.is_running = function(key)
if jobs[key] and jobs[key] ~= 0 then return true end
return false
end

M.stop_nrs = function ()
M.stop_nrs = function()
for k, v in pairs(jobs) do
if M.is_running(k) and k == 'Server' then
if M.is_running(k) and k == "Server" then
-- Avoid warning of exit status 141
vim.fn.chansend(v, "9\n")
vim.wait(20)
Expand Down
2 changes: 1 addition & 1 deletion lua/r/send.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end

-- Send the current paragraph to R. If m == 'down', move the cursor to the
-- first line of the next paragraph.
M.paragraph = function(e, m)
M.paragraph = function(m)
local start_line, end_line = paragraph.get_current()

local lines = vim.api.nvim_buf_get_lines(0, start_line, end_line, false)
Expand Down
7 changes: 4 additions & 3 deletions selene.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
std="vim"
std="lua52+vim"

[config]
multiple_statements = { one_line_if = "allow" }
[rules]
multiple_statements = "allow"
parse_error = "allow"
5 changes: 3 additions & 2 deletions tests/r/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
--# selene: allow(incorrect_standard_library_use)
---@diagnostic disable: undefined-global
local utils = require("r.utils")

--- See tests/init/lua
local function root(root)
local function root(root_folder)
local f = debug.getinfo(1, "S").source:sub(2)
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root_folder or "")
end

describe("normalize_windows_path", function()
Expand Down

0 comments on commit de260c1

Please sign in to comment.