Skip to content

Instantly share code, notes, and snippets.

@peteryates
Created September 24, 2019 12:47
Show Gist options
  • Save peteryates/59fbd6ace8f12695ee2fe5d4df25999a to your computer and use it in GitHub Desktop.
Save peteryates/59fbd6ace8f12695ee2fe5d4df25999a to your computer and use it in GitHub Desktop.
A twist on the Rubocop linter customised to work with govuk-ruby-lint
" Author: ynonp - https://github.com/ynonp, Eddie Lebow https://github.com/elebow
" Description: RuboCop, a code style analyzer for Ruby files
call ale#Set('ruby_rubocop_executable', 'govuk-lint-ruby')
call ale#Set('ruby_rubocop_options', '')
function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
return ale#ruby#EscapeExecutable(l:executable, 'govuk-lint-ruby')
\ . ' --format json --force-exclusion '
\ . ale#Var(a:buffer, 'ruby_rubocop_options')
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
endfunction
function! ale_linters#ruby#rubocop#GetType(severity) abort
if a:severity is? 'convention'
\|| a:severity is? 'warning'
\|| a:severity is? 'refactor'
return 'W'
endif
return 'E'
endfunction
call ale#linter#Define('ruby', {
\ 'name': 'govuk-lint-ruby',
\ 'executable': {b -> ale#Var(b, 'ruby_rubocop_executable')},
\ 'command': function('ale_linters#ruby#rubocop#GetCommand'),
\ 'callback': 'ale#ruby#HandleRubocopOutput',
\})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment