Merge pull request #2061 from hsanson/1910-add-support-for-bibclean-fixer

Add bibclean fixer support
This commit is contained in:
w0rp 2018-12-06 20:26:04 +00:00 committed by GitHub
commit 3db564f774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 208 additions and 3 deletions

View file

@ -104,6 +104,7 @@ formatting.
| AsciiDoc | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [write-good](https://github.com/btford/write-good), [vale](https://github.com/ValeLint/vale) | | AsciiDoc | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [redpen](http://redpen.cc/), [write-good](https://github.com/btford/write-good), [vale](https://github.com/ValeLint/vale) |
| Awk | [gawk](https://www.gnu.org/software/gawk/)| | Awk | [gawk](https://www.gnu.org/software/gawk/)|
| Bash | [language-server](https://github.com/mads-hartmann/bash-language-server), shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | | Bash | [language-server](https://github.com/mads-hartmann/bash-language-server), shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
| BibTeX | [bibclean](http://ftp.math.utah.edu/pub/bibclean/) |
| Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | | Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) |
| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) | | C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) |
| C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [clazy](https://github.com/KDE/clazy) !!, [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) | | C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [clazy](https://github.com/KDE/clazy) !!, [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/), [uncrustify](https://github.com/uncrustify/uncrustify), [ccls](https://github.com/MaskRay/ccls) |

View file

@ -0,0 +1,74 @@
" Author: Horacio Sanson - https://github.com/hsanson
" Description: Support for bibclean linter for BibTeX files.
call ale#Set('bib_bibclean_executable', 'bibclean')
function! ale_linters#bib#bibclean#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'bib_bibclean_executable')
return ale#Escape(l:executable) . ' -file-position '
endfunction
function! ale_linters#bib#bibclean#get_type(str) abort
if a:str is# '??'
return 'E'
else
return 'W'
endif
endfunction
function! ale_linters#bib#bibclean#match_msg(line) abort
return matchlist(a:line, '^\(.*\) "stdin", line \(.*\): \(.*\)$')
endfunction
function! ale_linters#bib#bibclean#match_entry(line) abort
return matchlist(a:line, 'Entry input byte=.* line=\(.*\) column=\(.*\) output .*$')
endfunction
function! ale_linters#bib#bibclean#match_value(line) abort
return matchlist(a:line, 'Value input byte=.* line=\(.*\) column=\(.*\) output .*$')
endfunction
function! ale_linters#bib#bibclean#Handle(buffer, lines) abort
let l:output = []
let l:type = 'E'
let l:msg = ''
for l:line in a:lines
if empty(l:msg)
let l:mlist = ale_linters#bib#bibclean#match_msg(l:line)
if !empty(l:mlist)
let l:msg = l:mlist[3]
let l:type = ale_linters#bib#bibclean#get_type(l:mlist[1])
endif
else
if l:type is# 'E'
let l:mlist = ale_linters#bib#bibclean#match_entry(l:line)
else
let l:mlist = ale_linters#bib#bibclean#match_value(l:line)
endif
if !empty(l:mlist)
call add(l:output, {
\ 'lnum': l:mlist[1],
\ 'col': l:mlist[2],
\ 'text': l:msg,
\ 'type': l:type
\})
let l:msg = ''
endif
endif
endfor
return l:output
endfunction
call ale#linter#Define('bib', {
\ 'name': 'bibclean',
\ 'executable_callback': ale#VarFunc('bib_bibclean_executable'),
\ 'command_callback': 'ale_linters#bib#bibclean#GetCommand',
\ 'output_stream': 'stderr',
\ 'callback': 'ale_linters#bib#bibclean#Handle',
\})

View file

@ -17,6 +17,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'], \ 'suggested_filetypes': ['python'],
\ 'description': 'Fix PEP8 issues with autopep8.', \ 'description': 'Fix PEP8 issues with autopep8.',
\ }, \ },
\ 'bibclean': {
\ 'function': 'ale#fixers#bibclean#Fix',
\ 'suggested_filetypes': ['bib'],
\ 'description': 'Format bib files using bibclean.',
\ },
\ 'black': { \ 'black': {
\ 'function': 'ale#fixers#black#Fix', \ 'function': 'ale#fixers#black#Fix',
\ 'suggested_filetypes': ['python'], \ 'suggested_filetypes': ['python'],

View file

@ -0,0 +1,15 @@
" Author: Horacio Sanson - https://github.com/hsanson
" Description: Support for bibclean fixer for BibTeX files.
call ale#Set('bib_bibclean_executable', 'bibclean')
call ale#Set('bib_bibclean_options', '-align-equals')
function! ale#fixers#bibclean#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'bib_bibclean_options')
let l:executable = ale#Var(a:buffer, 'bib_bibclean_executable')
return {
\ 'command': ale#Escape(l:executable)
\ . ' ' . (empty(l:options) ? '' : l:options),
\}
endfunction

19
doc/ale-bib.txt Normal file
View file

@ -0,0 +1,19 @@
===============================================================================
ALE BibTeX Integration *ale-bib-options*
===============================================================================
bibclean *ale-bib-bibclean*
g:ale_bib_bibclean_executable *g:ale_bib_bibclean_executable*
Type: |String|
Default: `'bibclean'`
g:ale_bib_bibclean_options *g:ale_bib_bibclean_options*
Type: |String|
Default: `'-align-equals'`
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -31,6 +31,8 @@ CONTENTS *ale-contents*
gcc.................................|ale-asm-gcc| gcc.................................|ale-asm-gcc|
awk...................................|ale-awk-options| awk...................................|ale-awk-options|
gawk................................|ale-awk-gawk| gawk................................|ale-awk-gawk|
bib...................................|ale-bib-options|
bibclean............................|ale-bib-bibclean|
c.....................................|ale-c-options| c.....................................|ale-c-options|
clang...............................|ale-c-clang| clang...............................|ale-c-clang|
clangd..............................|ale-c-clangd| clangd..............................|ale-c-clangd|
@ -406,6 +408,7 @@ Notes:
* AsciiDoc: `alex`!!, `proselint`, `redpen`, `write-good`, `vale` * AsciiDoc: `alex`!!, `proselint`, `redpen`, `write-good`, `vale`
* Awk: `gawk` * Awk: `gawk`
* Bash: `language-server`, `shell` (-n flag), `shellcheck`, `shfmt` * Bash: `language-server`, `shell` (-n flag), `shellcheck`, `shfmt`
* BibTeX: `bibclean`
* Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt` * Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt`
* C: `cppcheck`, `cpplint`!!, `clang`, `clangd`, `clangtidy`!!, `clang-format`, `cquery`, `flawfinder`, `gcc`, `uncrustify`, `ccls` * C: `cppcheck`, `cpplint`!!, `clang`, `clangd`, `clangtidy`!!, `clang-format`, `cquery`, `flawfinder`, `gcc`, `uncrustify`, `ccls`
* C++ (filetype cpp): `clang`, `clangd`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `clazy`!!, `cppcheck`, `cpplint`!!, `cquery`, `flawfinder`, `gcc`, `uncrustify`, `ccls` * C++ (filetype cpp): `clang`, `clangd`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `clazy`!!, `cppcheck`, `cpplint`!!, `cquery`, `flawfinder`, `gcc`, `uncrustify`, `ccls`

View file

@ -0,0 +1,24 @@
Before:
call ale#assert#SetUpLinterTest('bib', 'bibclean')
let g:ale_ruby_rubocop_executable = 'bibclean'
let g:ale_ruby_rubocop_options = ''
After:
call ale#assert#TearDownLinterTest()
Execute(Executable should default to bibclean):
AssertLinter 'bibclean', ale#Escape('bibclean')
\ . ' -file-position '
Execute(Should be able to set a custom executable):
let g:ale_bib_bibclean_executable = 'bin/bibclean'
AssertLinter 'bin/bibclean' , ale#Escape('bin/bibclean')
\ . ' -file-position '
Execute(Should not include custom options):
let g:ale_bib_bibclean_options = '-no-prettryprint'
AssertLinter 'bibclean' , ale#Escape('bibclean')
\ . ' -file-position '

View file

@ -0,0 +1,30 @@
Before:
Save g:ale_bib_bibclean_executable
Save g:ale_bib_bibclean_options
let g:ale_bib_bibclean_executable = 'xxxinvalid'
let g:ale_bib_bibclean_options = '-align-equals'
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The bibclean callback should return the correct default values):
call ale#test#SetFilename('../command_callback/bib_paths/dummy.bib')
AssertEqual
\ {'command': ale#Escape(g:ale_bib_bibclean_executable) . ' -align-equals'},
\ ale#fixers#bibclean#Fix(bufnr(''))
Execute(The bibclean callback should include custom bibclean options):
let g:ale_bib_bibclean_options = '-author -check-values'
call ale#test#SetFilename('../command_callback/bib_paths/dummy.bib')
AssertEqual
\ {
\ 'command': ale#Escape(g:ale_bib_bibclean_executable) . ' -author -check-values'
\ },
\ ale#fixers#bibclean#Fix(bufnr(''))

View file

@ -4,9 +4,7 @@ Before:
" Use an invalid global executable, so we don't match it. " Use an invalid global executable, so we don't match it.
let g:ale_ruby_rufo_executable = 'xxxinvalid' let g:ale_ruby_rufo_executable = 'xxxinvalid'
call ale#test#SetDirectory('/testplugin/test/fixers') call ale#test#SetDirectory('/testplugin/test/command_callback')
silent cd ..
silent cd command_callback
let g:dir = getcwd() let g:dir = getcwd()
After: After:

View file

@ -0,0 +1,35 @@
Before:
runtime ale_linters/bib/bibclean.vim
After:
call ale#linter#Reset()
Execute(The bibclean handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': '60',
\ 'type': 'W',
\ 'text': 'Unexpected value in ``month = "09"''''.',
\ 'col': '17'
\ },
\ {
\ 'lnum': '63',
\ 'type': 'E',
\ 'text': 'Expected comma after last field ``keywords''''.',
\ 'col': ' 1'
\ }
\ ],
\ ale_linters#bib#bibclean#Handle(255, [
\ "%% \"stdin\", line 60: Unexpected value in ``month = \"09\"''.",
\ "%% File positions: input [main.bib] output [stdout]",
\ "%% Entry input byte=1681 line=50 column= 1 output byte=1680 line=50 column= 0",
\ "%% Value input byte=2137 line=60 column=17 output byte=2137 line=60 column=17",
\ "%% Current input byte=2139 line=60 column=19 output byte=2137 line=60 column=17",
\ "?? \"stdin\", line 71: Expected comma after last field ``keywords''.",
\ "?? File positions: input [main.bib] output [stdout]",
\ "?? Entry input byte=2145 line=63 column= 1 output byte=2146 line=63 column= 0",
\ "?? Value input byte=2528 line=71 column= 2 output byte=2527 line=70 column=49",
\ "?? Current input byte=2529 line=71 column= 3 output byte=2528 line=70 column=50"
\ ])

View file

@ -36,6 +36,7 @@ doc_files="$(/bin/ls -1v doc | grep ^ale- | sed 's/^/doc\//' | paste -sd ' ' -)"
grep -h '\*ale-.*-options\|^[a-z].*\*ale-.*\*$' $doc_files \ grep -h '\*ale-.*-options\|^[a-z].*\*ale-.*\*$' $doc_files \
| sed 's/^/ /' \ | sed 's/^/ /' \
| sed 's/ALE Shell Integration/ALE sh Integration/' \ | sed 's/ALE Shell Integration/ALE sh Integration/' \
| sed 's/ALE BibTeX Integration/ALE bib Integration/' \
| sed 's/ ALE \(.*\) Integration/\1/' \ | sed 's/ ALE \(.*\) Integration/\1/' \
| sed 's/ *\*\(..*\)\*$/, \1/' \ | sed 's/ *\*\(..*\)\*$/, \1/' \
| tr '[:upper:]' '[:lower:]' \ | tr '[:upper:]' '[:lower:]' \