Add a linter for clojure using clj-kondo (#2377)

This commit is contained in:
Masashi Iizuka 2019-04-11 04:59:58 +09:00 committed by w0rp
parent 16b43a5708
commit 4813165614
6 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,34 @@
" Author: Masashi Iizuka <liquidz.uo@gmail.com>
" Description: linter for clojure using clj-kondo https://github.com/borkdude/clj-kondo
function! ale_linters#clojure#clj_kondo#HandleCljKondoFormat(buffer, lines) abort
" output format
" <filename>:<line>:<column>: <issue type>: <message>
let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+):(\d+):? ((Exception|error|warning): ?(.+))$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:type = 'E'
if l:match[4] is? 'warning'
let l:type = 'W'
endif
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[3],
\ 'type': l:type,
\})
endfor
return l:output
endfunction
call ale#linter#Define('clojure', {
\ 'name': 'clj-kondo',
\ 'output_stream': 'stdout',
\ 'executable': 'clj-kondo',
\ 'command': 'clj-kondo --lint %t',
\ 'callback': 'ale_linters#clojure#clj_kondo#HandleCljKondoFormat',
\})

View File

@ -2,6 +2,13 @@
ALE Clojure Integration *ale-clojure-options* ALE Clojure Integration *ale-clojure-options*
===============================================================================
clj-kondo *ale-clojure-clj-kondo*
A minimal and opinionated linter for code that sparks joy.
https://github.com/borkdude/clj-kondo
=============================================================================== ===============================================================================
joker *ale-clojure-joker* joker *ale-clojure-joker*

View File

@ -74,6 +74,7 @@ Notes:
* `cookstyle` * `cookstyle`
* `foodcritic` * `foodcritic`
* Clojure * Clojure
* `clj-kondo`
* `joker` * `joker`
* CloudFormation * CloudFormation
* `cfn-python-lint` * `cfn-python-lint`

View File

@ -1867,6 +1867,7 @@ documented in additional help files.
cookstyle.............................|ale-chef-cookstyle| cookstyle.............................|ale-chef-cookstyle|
foodcritic............................|ale-chef-foodcritic| foodcritic............................|ale-chef-foodcritic|
clojure.................................|ale-clojure-options| clojure.................................|ale-clojure-options|
clj-kondo.............................|ale-clojure-clj-kondo|
joker.................................|ale-clojure-joker| joker.................................|ale-clojure-joker|
cloudformation..........................|ale-cloudformation-options| cloudformation..........................|ale-cloudformation-options|
cfn-python-lint.......................|ale-cloudformation-cfn-python-lint| cfn-python-lint.......................|ale-cloudformation-cfn-python-lint|

View File

@ -83,6 +83,7 @@ formatting.
* [cookstyle](https://docs.chef.io/cookstyle.html) * [cookstyle](https://docs.chef.io/cookstyle.html)
* [foodcritic](http://www.foodcritic.io/) * [foodcritic](http://www.foodcritic.io/)
* Clojure * Clojure
* [clj-kondo](https://github.com/borkdude/clj-kondo)
* [joker](https://github.com/candid82/joker) * [joker](https://github.com/candid82/joker)
* CloudFormation * CloudFormation
* [cfn-python-lint](https://github.com/awslabs/cfn-python-lint) * [cfn-python-lint](https://github.com/awslabs/cfn-python-lint)

View File

@ -0,0 +1,75 @@
Before:
runtime ale_linters/clojure/clj_kondo.vim
After:
call ale#linter#Reset()
Execute(the clojure clj-kondo handler should be able to handle errors):
AssertEqual
\ [
\ {
\ 'lnum': 123,
\ 'col': 44,
\ 'type': 'E',
\ 'text': 'error: Unexpected )',
\ },
\ ],
\ ale_linters#clojure#clj_kondo#HandleCljKondoFormat(0, [
\ 'test.clj:123:44: error: Unexpected )',
\ ])
Execute(the clojure clj-kondo handler should be able to handle warnings):
AssertEqual
\ [
\ {
\ 'lnum': 654,
\ 'col': 321,
\ 'type': 'W',
\ 'text': 'warning: inline def',
\ }
\ ],
\ ale_linters#clojure#clj_kondo#HandleCljKondoFormat(0, [
\ 'test.clj:654:321: warning: inline def'
\ ])
Execute(the clojure clj-kondo handler should be able to handle exceptions):
AssertEqual
\ [
\ {
\ 'lnum': 123,
\ 'col': 321,
\ 'type': 'E',
\ 'text': 'Exception: something horrible happen',
\ }
\ ],
\ ale_linters#clojure#clj_kondo#HandleCljKondoFormat(0, [
\ 'test.clj:123:321: Exception: something horrible happen'
\ ])
Execute(the clojure clj-kondo handler should be able to handle errors from stdin):
AssertEqual
\ [
\ {
\ 'lnum': 16,
\ 'col': 1,
\ 'type': 'E',
\ 'text': 'error: Unexpected )',
\ },
\ ],
\ ale_linters#clojure#clj_kondo#HandleCljKondoFormat(0, [
\ '<stdin>:16:1: error: Unexpected )',
\ ])
Execute(the clojure clj-kondo handler should be able to handle windows files):
AssertEqual
\ [
\ {
\ 'lnum': 123,
\ 'col': 44,
\ 'type': 'E',
\ 'text': 'error: Unexpected )',
\ }
\ ],
\ ale_linters#clojure#clj_kondo#HandleCljKondoFormat(0, [
\ 'C:\my\operating\system\is\silly\core.clj:123:44: error: Unexpected )',
\ ])