From 8d7317bd574d75d842ffb36adbda03a18977c9d2 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Mon, 20 Jul 2020 18:03:08 -0600 Subject: [PATCH] kakoune: fix nix linting by using `nix-linter` --- profiles/develop/kakoune/default.nix | 1 + profiles/develop/kakoune/lint/nix.kak | 10 +--------- profiles/develop/kakoune/lint/nix.sh | 13 +++++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100755 profiles/develop/kakoune/lint/nix.sh diff --git a/profiles/develop/kakoune/default.nix b/profiles/develop/kakoune/default.nix index a6350e4..24e941f 100644 --- a/profiles/develop/kakoune/default.nix +++ b/profiles/develop/kakoune/default.nix @@ -9,6 +9,7 @@ nixfmt python3Packages.python-language-server rustup + nix-linter ]; environment.etc = { diff --git a/profiles/develop/kakoune/lint/nix.kak b/profiles/develop/kakoune/lint/nix.kak index 2deb99f..7b5c1fd 100644 --- a/profiles/develop/kakoune/lint/nix.kak +++ b/profiles/develop/kakoune/lint/nix.kak @@ -2,15 +2,7 @@ hook -group lint global WinSetOption filetype=nix %{ # remove '' for nix, annoying for string literals set buffer auto_pairs ( ) { } [ ] '"' '"' ` ` - set buffer lintcmd ' - run () { - nix-instantiate --parse $1 2>&1 >&- > /dev/null | - awk '' - {printf $NF ":" " "} - !($NF="") !($(NF-1)="") {sub(/, $/, "")}1 - '' - } && run \ - ' + set buffer lintcmd '/etc/xdg/kak/autoload/lint/nix.sh $1' lint-enable set buffer formatcmd "nixfmt" hook buffer BufWritePre .* %{ diff --git a/profiles/develop/kakoune/lint/nix.sh b/profiles/develop/kakoune/lint/nix.sh new file mode 100755 index 0000000..93a50dc --- /dev/null +++ b/profiles/develop/kakoune/lint/nix.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env zsh + +nix-linter $1 2>&1 | < /dev/stdin > /tmp/lint.out +if head -1 /tmp/lint.out | grep Failure &> /dev/null; then + sed -n 2p /tmp/lint.out | tr '\n' ' ' + printf "error: " + awk 'NR>5 {printf "%s; ", $0}' /tmp/lint.out +else + awk '{$(NF-1)=""; print $NF ": warning: " $0}' /tmp/lint.out > /tmp/lint.2 + awk '{$NF="";gsub(/-[0-9]*:[0-9]*:*/, ":"); print $0}' /tmp/lint.2 +fi +rm -f /tmp/lint.out +rm -f /tmp/lint.2