Add support for fortitude (fortran linter) #5004

* add support for fortitude fortran linter
* add fortitude fortran linter doc
* Add a fortitude linter test file
* docs listings are now alphabetically sorted

Co-Authored-By: gomfol12 <info@marekb.de>
This commit is contained in:
w0rp
2025-08-13 15:24:35 +01:00
parent 7df94447c1
commit 29f1ff2579
7 changed files with 148 additions and 1 deletions

View File

@@ -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,
\})

View File

@@ -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:

View File

@@ -205,6 +205,7 @@ Notes:
* `fish` (-n flag)
* `fish_indent`
* Fortran
* `fortitude`
* `gcc`
* `language_server`
* Fountain

View File

@@ -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|

View File

@@ -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

View File

@@ -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',
\ }),
\ ']',
\ ])

View File

@@ -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'