From e2d3dca48644136d62346d45d8b031a138e18700 Mon Sep 17 00:00:00 2001 From: Niraj Thapaliya Date: Mon, 25 Dec 2017 23:50:08 -0600 Subject: [PATCH 1/3] Support for fish file linting --- ale_linters/fish/fish.vim | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ale_linters/fish/fish.vim diff --git a/ale_linters/fish/fish.vim b/ale_linters/fish/fish.vim new file mode 100644 index 0000000..19158cb --- /dev/null +++ b/ale_linters/fish/fish.vim @@ -0,0 +1,36 @@ +" Author: Niraj Thapaliya - https://github.com/nthapaliya +" Description: Lints fish files using fish -n + +function! ale_linters#fish#fish#Handle(buffer, lines) abort + " Matches patterns such as: + " + " home/.config/fish/functions/foo.fish (line 1): Missing end to balance this function definition + " function foo + " ^ + " fish: Error while reading file .config/fish/functions/foo.fish + let l:pattern = '^.* (line \(\d\+\)): \(.*\)$' + let l:output = [] + + let l:i = 0 + while l:i < len(a:lines) + let l:match = matchlist(a:lines[l:i], l:pattern) + if len(l:match) && len(l:match[2]) + call add(l:output, { + \ 'col': len(a:lines[l:i + 2]), + \ 'lnum': str2nr(l:match[1]), + \ 'text': l:match[2], + \}) + endif + let l:i += 1 + endwhile + + return l:output +endfunction + +call ale#linter#Define('fish', { +\ 'name': 'fish', +\ 'output_stream': 'stderr', +\ 'executable': 'fish', +\ 'command': 'fish -n %t', +\ 'callback': 'ale_linters#fish#fish#Handle', +\}) From c90b45c559342f22fdeee9e8ace0927406aa4b0b Mon Sep 17 00:00:00 2001 From: Niraj Thapaliya Date: Tue, 26 Dec 2017 12:00:28 -0600 Subject: [PATCH 2/3] Edit README and help --- README.md | 1 + doc/ale-fish.txt | 14 ++++++++++++++ doc/ale.txt | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 doc/ale-fish.txt diff --git a/README.md b/README.md index 129033c..c8d44ff 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ formatting. | Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | | Erb | [erb](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | | Erlang | [erlc](http://erlang.org/doc/man/erlc.html), [SyntaxErl](https://github.com/ten0s/syntaxerl) | +| Fish | fish [-n flag](https://linux.die.net/man/1/fish) | Fortran | [gcc](https://gcc.gnu.org/) | | FusionScript | [fusion-lint](https://github.com/RyanSquared/fusionscript) | | Git Commit Messages | [gitlint](https://github.com/jorisroovers/gitlint) | diff --git a/doc/ale-fish.txt b/doc/ale-fish.txt new file mode 100644 index 0000000..8450b38 --- /dev/null +++ b/doc/ale-fish.txt @@ -0,0 +1,14 @@ +=============================================================================== +ALE Fish Integration *ale-fish-options* + +Lints fish files using `fish -n`. + +Note that `fish -n` is not foolproof: it sometimes gives false positives or +errors that are difficult to parse without more context. This integration skips +displaying errors if an error message is not found. + +If ALE is not showing any errors but your file does not run as expected, run +`fish -n ` from the command line. + +=============================================================================== + vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index bec086d..ce6ae6b 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -64,6 +64,7 @@ CONTENTS *ale-contents* erlc................................|ale-erlang-erlc| syntaxerl...........................|ale-erlang-syntaxerl| eruby.................................|ale-eruby-options| + fish..................................|ale-fish-options| fortran...............................|ale-fortran-options| gcc.................................|ale-fortran-gcc| fusionscript..........................|ale-fuse-options| @@ -300,6 +301,7 @@ Notes: * Elm: `elm-format, elm-make` * Erb: `erb`, `erubis` * Erlang: `erlc`, `SyntaxErl` +* Fish: `fish` (-n flag) * Fortran: `gcc` * FusionScript: `fusion-lint` * Git Commit Messages: `gitlint` From 3b0c67e42c4bffbe90edb98a181497a9791d9de4 Mon Sep 17 00:00:00 2001 From: Niraj Thapaliya Date: Tue, 26 Dec 2017 13:04:06 -0600 Subject: [PATCH 3/3] Add handler test --- test/handler/test_fish_handler.vader | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/handler/test_fish_handler.vader diff --git a/test/handler/test_fish_handler.vader b/test/handler/test_fish_handler.vader new file mode 100644 index 0000000..567952e --- /dev/null +++ b/test/handler/test_fish_handler.vader @@ -0,0 +1,39 @@ +Before: + runtime ale_linters/fish/fish.vim + +After: + call ale#linter#Reset() + +Execute(The fish handler should handle basic warnings and syntax errors): + AssertEqual + \ [ + \ { + \ 'lnum': 20, + \ 'col': 23, + \ 'text': "Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'.", + \ }, + \ { + \ 'lnum': 26, + \ 'col': 7, + \ 'text': "Illegal command name '(prompt_pwd)'", + \ }, + \ { + \ 'lnum': 36, + \ 'col': 1, + \ 'text': "'end' outside of a block", + \ }, + \ ], + \ ale_linters#fish#fish#Handle(1, [ + \ "fish_prompt.fish (line 20): Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'.", + \ 'if set -q SSH_CLIENT || set -q SSH_TTY', + \ ' ^', + \ "fish_prompt.fish (line 26): Illegal command name '(prompt_pwd)'", + \ ' (prompt_pwd) \', + \ ' ^', + \ "fish_prompt.fish (line 36): 'end' outside of a block", + \ 'end', + \ '^', + \ 'config.fish (line 45):', + \ "abbr --add p 'cd ~/Projects'", + \ '^', + \ ])