Skip to content

Instantly share code, notes, and snippets.

@SuperSpyTX
Last active February 20, 2022 12:10
Show Gist options
  • Save SuperSpyTX/887922786834aa8e1914cfb0ee0d4177 to your computer and use it in GitHub Desktop.
Save SuperSpyTX/887922786834aa8e1914cfb0ee0d4177 to your computer and use it in GitHub Desktop.
42 Norminette linter for ALE.

Norminette Linter for ALE (Asynchronous Linting Engine)

https://github.com/w0rp/ale

Installation

Install this in your ale plugin directory (For Vundle + NeoVim that may be ~/.config/nvim/bundle/ale/ale_linters/c/norminette.vim)

You will of course, need the norminette ruby gem in your PATH. gem install --user --pre norminette

Configuration

This is how I configure it:

let g:ale_linters = {
\	'c': ['clang', 'norminette'],
\   'cpp': ['clang', 'norminette'],
\   'h': ['clang', 'norminette'],
\   'hpp': ['clang', 'norminette']
\}

But the default behavior of ALE is to use every possible linter.

Norme errors will now show up as errors for C files.

I have been unable to get it working for header files.

" Author: Joe <[email protected]>
" Description: norminette linter for C files.
call ale#Set('c_norminette_executable', 'norminette')
call ale#Set('c_norminette_options', '')
function! ale_linters#c#norminette#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'c_norminette_executable')
endfunction
function! ale_linters#c#norminette#GetCommand(buffer) abort
return ale#Escape(ale_linters#c#norminette#GetExecutable(a:buffer))
\ . ale#Var(a:buffer, 'c_norminette_options')
\ . ' %t'
endfunction
function! ale_linters#c#norminette#Opscript(buffer, lines) abort
" Look for lines like the following.
"
" Error (line 27): multiple empty lines
let l:pattern = '\v^(Norme|Error|Warning)( \(line (\d+)(, col (\d+))?\))?\:(.+)$'
let l:output = []
let l:curr_file = ''
let l:lel = ale#util#GetMatches(a:lines, l:pattern)
for l:match in ale#util#GetMatches(a:lines, l:pattern)
if l:match[1] == "Norme"
let l:curr_file = l:match[6]
endif
" if ale#path#IsBufferPath(a:buffer, l:curr_file) && l:match[1] == "Error"
if l:match[1] == "Error" || l:match[1] == "Warning"
call add(l:output, {
\ 'lnum': str2nr(l:match[3]),
\ 'col': l:match[5] is# '' ? 0 : str2nr(l:match[5]),
\ 'type': l:match[1] is# 'Error' ? 'E' : 'W',
\ 'text': l:match[0],
\})
endif
endfor
return l:output
endfunction
call ale#linter#Define('c', {
\ 'name': 'norminette',
\ 'output_stream': 'both',
\ 'executable_callback': 'ale_linters#c#norminette#GetExecutable',
\ 'command_callback': 'ale_linters#c#norminette#GetCommand',
\ 'callback': 'ale_linters#c#norminette#Opscript',
\})
@cassepipe
Copy link

This above should be functional with the new norminette.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment