From fae26369d415a14ce10739513c7f78273993a827 Mon Sep 17 00:00:00 2001 From: Markus Doits Date: Tue, 14 Mar 2017 00:21:59 +0100 Subject: [PATCH] add slim-lint (#388) * add slim-lint * add slim readme entry * add slim entry to doc * add slimlint vader test --- README.md | 1 + ale_linters/slim/slimlint.vim | 33 +++++++++++++++++++++++++++ doc/ale.txt | 1 + test/handler/test_slim_handler.vader | 34 ++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 ale_linters/slim/slimlint.vim create mode 100644 test/handler/test_slim_handler.vader diff --git a/README.md b/README.md index efaad69..b88c7fe 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ name. That seems to be the fairest way to arrange this table. | SASS | [sass-lint](https://www.npmjs.com/package/sass-lint), [stylelint](https://github.com/stylelint/stylelint) | | SCSS | [sass-lint](https://www.npmjs.com/package/sass-lint), [scss-lint](https://github.com/brigade/scss-lint), [stylelint](https://github.com/stylelint/stylelint) | | Scala | [scalac](http://scala-lang.org) | +| Slim | [slim-lint](https://github.com/sds/slim-lint) | SML | [smlnj](http://www.smlnj.org/) | | Swift | [swiftlint](https://swift.org/) | | Tex | [proselint](http://proselint.com/) | diff --git a/ale_linters/slim/slimlint.vim b/ale_linters/slim/slimlint.vim new file mode 100644 index 0000000..8613951 --- /dev/null +++ b/ale_linters/slim/slimlint.vim @@ -0,0 +1,33 @@ +" Author: Markus Doits - https://github.com/doits +" Description: slim-lint for Slim files, based on hamllint.vim + +function! ale_linters#slim#slimlint#Handle(buffer, lines) abort + " Matches patterns like the following: + " :5 [W] LineLength: Line is too long. [150/120] + let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[1] + 0, + \ 'type': l:match[2], + \ 'text': l:match[3] + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('slim', { +\ 'name': 'slimlint', +\ 'executable': 'slim-lint', +\ 'command': 'slim-lint %t', +\ 'callback': 'ale_linters#slim#slimlint#Handle' +\}) diff --git a/doc/ale.txt b/doc/ale.txt index 12df2b4..b6e7a10 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -118,6 +118,7 @@ The following languages and tools are supported. * SASS: 'sasslint', 'stylelint' * SCSS: 'sasslint', 'scsslint', 'stylelint' * Scala: 'scalac' +* Slim: 'slim-lint' * SML: 'smlnj' * Swift: 'swiftlint' * Tex: 'proselint' diff --git a/test/handler/test_slim_handler.vader b/test/handler/test_slim_handler.vader new file mode 100644 index 0000000..12bd818 --- /dev/null +++ b/test/handler/test_slim_handler.vader @@ -0,0 +1,34 @@ +" Author: Markus Doits + +Execute(The slim handler should parse lines correctly): + runtime ale_linters/slim/slimlint.vim + + AssertEqual + \ [ + \ { + \ 'bufnr': 347, + \ 'lnum': 1, + \ 'text': 'RedundantDiv: `div` is redundant when class attribute shortcut is present', + \ 'type': 'W', + \ }, + \ { + \ 'bufnr': 347, + \ 'lnum': 2, + \ 'text': 'LineLength: Line is too long. [136/80]', + \ 'type': 'W', + \ }, + \ { + \ 'bufnr': 347, + \ 'lnum': 3, + \ 'text': 'Invalid syntax', + \ 'type': 'E', + \ }, + \ ], + \ ale_linters#slim#slimlint#Handle(347, [ + \ 'inv.slim:1 [W] RedundantDiv: `div` is redundant when class attribute shortcut is present', + \ 'inv.slim:2 [W] LineLength: Line is too long. [136/80]', + \ 'inv.slim:3 [E] Invalid syntax', + \ ]) + +After: + call ale#linter#Reset()