Skip to content

Commit

Permalink
ci: add linting (#108)
Browse files Browse the repository at this point in the history
###### Description of changes

###### Things done

- [x] Tested, as applicable:
  - [ ] Manually
  - [x] Added lints
- [x] Updated
[CHANGELOG.md](https://github.com/MrcJkb/haskell-tools.nvim/blob/master/CHANGELOG.md)
(if applicable).
- [x] Fits
[CONTRIBUTING.md](https://github.com/MrcJkb/haskell-tools.nvim/blob/master/CONTRIBUTING.md)
  • Loading branch information
mrcjkb authored Jan 16, 2023
1 parent f0115cc commit bd9d6bc
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ignore = {
"631", -- max_line_length
"122", -- read-only field of global variable
}
read_globals = {
"vim",
"describe",
"it",
"assert"
}
11 changes: 11 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.workspace.checkThirdParty": false,
"Lua.diagnostics.globals": [
"vim",
"describe",
"it",
"assert"
],
"Lua.runtime.version": "LuaJIT"
}
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ This project uses [Conventional Commits](https://www.conventionalcommits.org/en/

## Development

I use [`nix`](https://nixos.org/download.html#download-nix) for development and testing.
I use

Formatting is done with [`stylua`](https://github.com/JohnnyMorganz/StyLua).
* [`nix`](https://nixos.org/download.html#download-nix) for development and testing.
* [`stylua`](https://github.com/JohnnyMorganz/StyLua) for formatting.
* [`luacheck`](https://github.com/mpeterv/luacheck) and [`sumneko-lua-language-server`](https://github.com/sumneko/lua-language-server/wiki/Diagnosis-Report#create-a-report) for linting.

To enter a development shell:

Expand Down
5 changes: 5 additions & 0 deletions doc/haskell-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ repl.setup() *repl.setup*
Set up this module. Called by the haskell-tools setup.


repl.toggle() *repl.toggle*
Toggle a GHCi REPL
@param filepath string?: optional file path


repl.paste() *repl.paste*
Paste from register `reg` to the REPL
@param reg string?: register (defaults to '"')
Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
test-overlay = import ./nix/test-overlay.nix {
inherit
(inputs)
self
packer-nvim
plenary-nvim
telescope-nvim
Expand Down Expand Up @@ -105,6 +106,7 @@
zlib
alejandra
stylua
lua51Packages.luacheck
];
};
in {
Expand Down Expand Up @@ -139,6 +141,7 @@
formatting = pre-commit-check-for system;
inherit
(checkPkgs)
lints
haskell-tools-test
haskell-tools-test-no-telescope
haskell-tools-test-no-telescope-with-hoogle
Expand Down
2 changes: 1 addition & 1 deletion lua/haskell-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ config.defaults = {
---@type HaskellLspClientOpts
hls = {
debug = false,
on_attach = function(...) end,
on_attach = function(_, _) end,
cmd = { 'haskell-language-server-wrapper', '--lsp', '--logfile', config.hls_log },
filetypes = { 'haskell', 'lhaskell', 'cabal', 'cabalproject' },
capabilities = capabilities,
Expand Down
2 changes: 1 addition & 1 deletion lua/haskell-tools/hoogle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local lsp_util = vim.lsp.util
---@field hoogle_signature function Hoogle search for a symbol's type signature
---@field setup function

local handler = function(...) end
local handler = function(_, _) end

---@type HaskellToolsHoogle
local hoogle = {}
Expand Down
6 changes: 4 additions & 2 deletions lua/haskell-tools/repl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end
--- Set up this module. Called by the haskell-tools setup.
function repl.setup()
local opts = ht.config.options.tools.repl
local handler = {}
local handler
if opts.handler == 'toggleterm' then
ht.log.info('handler = toggleterm')
local toggleterm = require('haskell-tools.repl.toggleterm')
Expand All @@ -139,7 +139,9 @@ function repl.setup()

--- Toggle a GHCi REPL
--- @param filepath string?: optional file path
repl.toggle = handler.toggle
function repl.toggle(filepath, ...)
handler.toggle(filepath, ...)
end

--- Quit the REPL
repl.quit = handler.quit
Expand Down
5 changes: 2 additions & 3 deletions lua/haskell-tools/repl/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,8 @@ function builtin.setup(mk_repl_cmd, options)
ht.log.debug { 'repl.builtin setup', options }
builtin.go_back = options.auto_focus ~= true
---@param filepath string path of the file to load into the repl
---@param opts table?
function builtin.toggle(filepath, opts)
opts = opts or vim.empty_dict()
---@param _ table?
function builtin.toggle(filepath, _)
local cur_win = vim.api.nvim_get_current_win()
if filepath and not vim.endswith(filepath, '.hs') then
local err_msg = 'haskell-tools.repl.builtin: Not a Haskell file: ' .. filepath
Expand Down
45 changes: 45 additions & 0 deletions nix/test-overlay.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
self,
packer-nvim,
plenary-nvim,
nvim-lspconfig,
Expand All @@ -8,6 +9,48 @@
with final.lib;
with final.lib.strings;
with final.stdenv; let
lints = mkDerivation {
name = "haskell-tools-lints";

src = self;

phases = [
"unpackPhase"
"buildPhase"
"checkPhase"
];

doCheck = true;

buildInputs = with final; [
lua51Packages.luacheck
sumneko-lua-language-server
];

buildPhase = ''
mkdir -p $out
cp -r lua $out/lua
cp -r tests $out/tests
cp .luacheckrc $out
cp .luarc.json $out
'';

checkPhase = ''
export HOME=$(realpath .)
cd $out
luacheck lua
luacheck tests
lua-language-server --check "$out/lua" \
--configpath "$out/.luarc.json" \
--logpath "$out" \
--checklevel="Warning"
if [[ -f $out/check.json ]]; then
cat $out/check.json
exit 1
fi
'';
};

nvim-nightly = final.neovim-nightly;

mkPlenaryTest = {
Expand Down Expand Up @@ -53,6 +96,8 @@ with final.stdenv; let
'';
};
in {
inherit lints;

haskell-tools-test = mkPlenaryTest {name = "haskell-tools";};

haskell-tools-test-no-telescope = mkPlenaryTest {
Expand Down

0 comments on commit bd9d6bc

Please sign in to comment.