diff --git a/ale_linters/fortran/fortitude.vim b/ale_linters/fortran/fortitude.vim new file mode 100644 index 00000000..2f28f862 --- /dev/null +++ b/ale_linters/fortran/fortitude.vim @@ -0,0 +1,47 @@ +" Author: gomfol12 +" Desciption: A linter for fortran using fortitude. + +call ale#Set('fortran_fortitude_executable', 'fortitude') +call ale#Set('fortran_fortitude_options', '') + +let s:severity_map = { +\ 'E': 'E', +\ 'C': 'W', +\ 'OB': 'I', +\ 'MOD': 'I', +\ 'S': 'I', +\ 'PORT': 'I', +\ 'FORT': 'I', +\} + +function! ale_linters#fortran#fortitude#Handle(buffer, lines) abort + let l:output = [] + + for l:error in ale#util#FuzzyJSONDecode(a:lines, []) + let l:prefix = matchstr(l:error['code'], '^\a\+') + let l:type = get(s:severity_map, l:prefix, 'I') + + call add(l:output, { + \ 'lnum': l:error['location']['row'], + \ 'end_lnum': l:error['end_location']['row'], + \ 'col': l:error['location']['column'], + \ 'end_col': l:error['end_location']['column'], + \ 'text': l:error['message'], + \ 'type': l:type, + \ 'code': l:error['code'], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('fortran', { +\ 'name': 'fortitude', +\ 'output_stream': 'stdout', +\ 'executable': {b -> ale#Var(b, 'fortran_fortitude_executable')}, +\ 'command': {b -> +\ '%e' . ' check --output-format json' . ale#Pad(ale#Var(b, 'fortran_fortitude_options')) . ' %s' +\ }, +\ 'callback': 'ale_linters#fortran#fortitude#Handle', +\ 'lint_file': 1, +\}) diff --git a/doc/ale-fortran.txt b/doc/ale-fortran.txt index 9ef1f387..37ac73f1 100644 --- a/doc/ale-fortran.txt +++ b/doc/ale-fortran.txt @@ -2,6 +2,29 @@ ALE Fortran Integration *ale-fortran-options* +=============================================================================== +fortitude *ale-fortran-fortitude* + + *ale-options.fortran_fortitude_executable* + *g:fortran_fortitude_executable* + *b:fortran_fortitude_executable* +fortran_fortitude_executable +g:fortran_fortitude_executable + Type: |String| + Default: 'fortitude' + + This variable can be changed to modify the executable used for fortitude. + + *ale-options.fortran_fortitude_options* + *g:fortran_fortitude_options* + *b:fortran_fortitude_options* +fortran_fortitude_options +g:fortran_fortitude_options + Type: |String| + Default: '' + + This variable can be changed to modify options given to fortitude check. + =============================================================================== gcc *ale-fortran-gcc* @@ -63,6 +86,5 @@ g:ale_fortran_language_server_use_global See |ale-integrations-local-executables| - =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index 363d4ff5..39b24295 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -205,6 +205,7 @@ Notes: * `fish` (-n flag) * `fish_indent` * Fortran + * `fortitude` * `gcc` * `language_server` * Fountain diff --git a/doc/ale.txt b/doc/ale.txt index 5606754a..64969a2f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3509,6 +3509,7 @@ documented in additional help files. fish....................................|ale-fish-options| fish_indent...........................|ale-fish-fish_indent| fortran.................................|ale-fortran-options| + fortitude.............................|ale-fortran-fortitude| gcc...................................|ale-fortran-gcc| language_server.......................|ale-fortran-language-server| fountain................................|ale-fountain-options| diff --git a/supported-tools.md b/supported-tools.md index 08079e52..bf0e729e 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -215,6 +215,7 @@ formatting. * fish [-n flag](https://linux.die.net/man/1/fish) * [fish_indent](https://fishshell.com/docs/current/cmds/fish_indent.html) * Fortran + * [fortitude](https://github.com/PlasmaFAIR/fortitude) * [gcc](https://gcc.gnu.org/) * [language_server](https://github.com/hansec/fortran-language-server) :speech_balloon: * Fountain diff --git a/test/handler/test_fortitude_handler.vader b/test/handler/test_fortitude_handler.vader new file mode 100644 index 00000000..d70d72f3 --- /dev/null +++ b/test/handler/test_fortitude_handler.vader @@ -0,0 +1,59 @@ +Before: + runtime ale_linters/fortran/fortitude.vim + +After: + call ale#linter#Reset() + +Execute(Simple fortitude handler run): + AssertEqual + \ [ + \ { + \ 'lnum': 3, + \ 'end_lnum': 3, + \ 'col': 5, + \ 'end_col': 18, + \ 'text': '''implicit none'' missing ''external''', + \ 'type': 'W', + \ 'code': 'C003', + \ }, + \ { + \ 'col': 13, + \ 'end_col': 14, + \ 'end_lnum': 7, + \ 'lnum': 7, + \ 'text': 'Syntax error', + \ 'type': 'E', + \ 'code': 'E001', + \ }, + \ ], + \ ale_linters#fortran#fortitude#Handle(bufnr(''), [ + \ '[', + \ json_encode({ + \ 'code': 'C003', + \ 'end_location': {'column': 18, 'row': 3}, + \ 'filename': '/home/user/documents/somefortranfile.f90', + \ 'fix': { + \ 'applicability': 'unsafe', + \ 'edits': [ + \ { + \ 'content': ' (type, external)', + \ 'end_location': {'column': 18, 'row': 3}, + \ 'location': {'column': 18, 'row': 3}, + \ }, + \ ], + \ 'message': 'Add `(external)` to ''implicit none''', + \ }, + \ 'location': {'column': 5, 'row': 3}, + \ 'message': '''implicit none'' missing ''external''' + \ }), + \ ',', + \ json_encode({ + \ 'code': 'E001', + \ 'end_location': {'column': 14, 'row': 7}, + \ 'filename': '/home/user/documents/somefortranfile.f90', + \ 'fix': v:null, + \ 'location': {'column': 13, 'row': 7}, + \ 'message': 'Syntax error', + \ }), + \ ']', + \ ]) diff --git a/test/linter/test_fortitude.vader b/test/linter/test_fortitude.vader new file mode 100644 index 00000000..bdbb6d83 --- /dev/null +++ b/test/linter/test_fortitude.vader @@ -0,0 +1,16 @@ +Before: + call ale#assert#SetUpLinterTest('fortran', 'fortitude') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default fortitude command should be correct): + AssertLinter 'fortitude', ale#Escape('fortitude') + \ . ' check --output-format json %s' + +Execute(fortitude should be configurable): + let b:ale_fortran_fortitude_executable = 'custom-exe' + let b:ale_fortran_fortitude_options = '--foobar' + + AssertLinter 'custom-exe', ale#Escape('custom-exe') + \ . ' check --output-format json --foobar %s'