summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--ale_linters/slim/slimlint.vim33
-rw-r--r--doc/ale.txt1
-rw-r--r--test/handler/test_slim_handler.vader34
4 files changed, 69 insertions, 0 deletions
diff --git a/README.md b/README.md
index efaad69a..b88c7fe5 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 00000000..8613951b
--- /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:
+ " <path>: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 12df2b4e..b6e7a108 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 00000000..12bd8183
--- /dev/null
+++ b/test/handler/test_slim_handler.vader
@@ -0,0 +1,34 @@
+" Author: Markus Doits <markus.doits@googlemail.com>
+
+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()