From 732d8e3ed6deb1b16bf47e21ce1a823e5e23228b Mon Sep 17 00:00:00 2001 From: Marcus Zanona Date: Thu, 9 Nov 2017 09:49:44 -0200 Subject: [PATCH] Add support for linting less files with lessc --- README.md | 1 + ale_linters/less/lessc.vim | 36 ++++++++++++++++++++++++++++++++++++ doc/ale-less.txt | 11 +++++++++++ doc/ale.txt | 2 ++ 4 files changed, 50 insertions(+) create mode 100755 ale_linters/less/lessc.vim diff --git a/README.md b/README.md index 9c5bc5a..7c6488c 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,7 @@ formatting. | JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) | | Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions | | LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | +| Less | [lessc](https://www.npmjs.com/package/less) | | LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) | | Lua | [luacheck](https://github.com/mpeterv/luacheck) | | Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) | diff --git a/ale_linters/less/lessc.vim b/ale_linters/less/lessc.vim new file mode 100755 index 0000000..3f6e265 --- /dev/null +++ b/ale_linters/less/lessc.vim @@ -0,0 +1,36 @@ +" Author: zanona , w0rp +" Description: This file adds support for checking Less code with lessc. + +call ale#Set('less_lessc_options', '') + +function! ale_linters#less#lessc#GetCommand(buffer) abort + return 'lessc' + \ . ' --no-color --lint ' + \ . ale#Var(a:buffer, 'less_lessc_options') + \ . ' %t' +endfunction + +function! ale_linters#less#lessc#Handle(buffer, lines) abort + " Matches patterns like the following: + let l:pattern = '^\(\w\+\): \(.\{-}\) in \(.\{-}\) on line \(\d\+\), column \(\d\+\):$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[4] + 0, + \ 'col': l:match[5] + 0, + \ 'text': l:match[2], + \ 'type': 'E', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('less', { +\ 'name': 'lessc', +\ 'executable': 'lessc', +\ 'output_stream': 'stderr', +\ 'command_callback': 'ale_linters#less#lessc#GetCommand', +\ 'callback': 'ale_linters#less#lessc#Handle', +\}) diff --git a/doc/ale-less.txt b/doc/ale-less.txt index a6b5998..cac9c9a 100644 --- a/doc/ale-less.txt +++ b/doc/ale-less.txt @@ -2,6 +2,17 @@ ALE Less Integration *ale-less-options* +=============================================================================== +lessc *ale-less-lessc* + +g:ale_less_lessc_options *g:ale_less_lessc_options* + *b:ale_less_lessc_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to lessc. + + =============================================================================== prettier *ale-less-prettier* diff --git a/doc/ale.txt b/doc/ale.txt index 2ee2c2d..ffe7ac7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -105,6 +105,7 @@ CONTENTS *ale-contents* latex.................................|ale-latex-options| write-good..........................|ale-latex-write-good| less..................................|ale-less-options| + lessc...............................|ale-less-lessc-options| prettier............................|ale-less-prettier| llvm..................................|ale-llvm-options| llc.................................|ale-llvm-llc| @@ -293,6 +294,7 @@ Notes: * JSON: `jsonlint`, `prettier` * Kotlin: `kotlinc`, `ktlint` * LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good` +* Less: `lessc` * LLVM: `llc` * Lua: `luacheck` * Mail: `proselint`, `vale`