Merge pull request #1850 from rrosenblum/ruby_linters
Update all Ruby linters to work consistently with bundler
This commit is contained in:
commit
7f1c411b5e
@ -1,8 +1,9 @@
|
|||||||
" Author: Eddie Lebow https://github.com/elebow
|
" Author: Eddie Lebow https://github.com/elebow
|
||||||
" Description: Brakeman, a static analyzer for Rails security
|
" Description: Brakeman, a static analyzer for Rails security
|
||||||
|
|
||||||
let g:ale_ruby_brakeman_options =
|
call ale#Set('ruby_brakeman_options', '')
|
||||||
\ get(g:, 'ale_ruby_brakeman_options', '')
|
call ale#Set('ruby_brakeman_executable', 'brakeman')
|
||||||
|
call ale#Set('ruby_brakeman_options', '')
|
||||||
|
|
||||||
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
function! ale_linters#ruby#brakeman#Handle(buffer, lines) abort
|
||||||
let l:output = []
|
let l:output = []
|
||||||
@ -33,14 +34,17 @@ function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 'brakeman -f json -q '
|
let l:executable = ale#Var(a:buffer, 'ruby_brakeman_executable')
|
||||||
|
|
||||||
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'brakeman')
|
||||||
|
\ . ' -f json -q '
|
||||||
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
|
||||||
\ . ' -p ' . ale#Escape(l:rails_root)
|
\ . ' -p ' . ale#Escape(l:rails_root)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call ale#linter#Define('ruby', {
|
call ale#linter#Define('ruby', {
|
||||||
\ 'name': 'brakeman',
|
\ 'name': 'brakeman',
|
||||||
\ 'executable': 'brakeman',
|
\ 'executable_callback': ale#VarFunc('ruby_brakeman_executable'),
|
||||||
\ 'command_callback': 'ale_linters#ruby#brakeman#GetCommand',
|
\ 'command_callback': 'ale_linters#ruby#brakeman#GetCommand',
|
||||||
\ 'callback': 'ale_linters#ruby#brakeman#Handle',
|
\ 'callback': 'ale_linters#ruby#brakeman#Handle',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
|
@ -22,26 +22,18 @@ function! ale_linters#ruby#rails_best_practices#Handle(buffer, lines) abort
|
|||||||
return l:output
|
return l:output
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#ruby#rails_best_practices#GetExecutable(buffer) abort
|
|
||||||
return ale#Var(a:buffer, 'ruby_rails_best_practices_executable')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! ale_linters#ruby#rails_best_practices#GetCommand(buffer) abort
|
function! ale_linters#ruby#rails_best_practices#GetCommand(buffer) abort
|
||||||
let l:executable = ale_linters#ruby#rails_best_practices#GetExecutable(a:buffer)
|
|
||||||
let l:exec_args = l:executable =~? 'bundle$'
|
|
||||||
\ ? ' exec rails_best_practices'
|
|
||||||
\ : ''
|
|
||||||
|
|
||||||
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
let l:rails_root = ale#ruby#FindRailsRoot(a:buffer)
|
||||||
|
|
||||||
if l:rails_root is? ''
|
if l:rails_root is? ''
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let l:executable = ale#Var(a:buffer, 'ruby_rails_best_practices_executable')
|
||||||
let l:output_file = ale#Has('win32') ? '%t ' : '/dev/stdout '
|
let l:output_file = ale#Has('win32') ? '%t ' : '/dev/stdout '
|
||||||
let l:cat_file = ale#Has('win32') ? '; type %t' : ''
|
let l:cat_file = ale#Has('win32') ? '; type %t' : ''
|
||||||
|
|
||||||
return ale#Escape(l:executable) . l:exec_args
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'rails_best_practices')
|
||||||
\ . ' --silent -f json --output-file ' . l:output_file
|
\ . ' --silent -f json --output-file ' . l:output_file
|
||||||
\ . ale#Var(a:buffer, 'ruby_rails_best_practices_options')
|
\ . ale#Var(a:buffer, 'ruby_rails_best_practices_options')
|
||||||
\ . ale#Escape(l:rails_root)
|
\ . ale#Escape(l:rails_root)
|
||||||
@ -50,7 +42,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('ruby', {
|
call ale#linter#Define('ruby', {
|
||||||
\ 'name': 'rails_best_practices',
|
\ 'name': 'rails_best_practices',
|
||||||
\ 'executable_callback': 'ale_linters#ruby#rails_best_practices#GetExecutable',
|
\ 'executable_callback': ale#VarFunc('ruby_rails_best_practices_executable'),
|
||||||
\ 'command_callback': 'ale_linters#ruby#rails_best_practices#GetCommand',
|
\ 'command_callback': 'ale_linters#ruby#rails_best_practices#GetCommand',
|
||||||
\ 'callback': 'ale_linters#ruby#rails_best_practices#Handle',
|
\ 'callback': 'ale_linters#ruby#rails_best_practices#Handle',
|
||||||
\ 'lint_file': 1,
|
\ 'lint_file': 1,
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
call ale#Set('ruby_reek_show_context', 0)
|
call ale#Set('ruby_reek_show_context', 0)
|
||||||
call ale#Set('ruby_reek_show_wiki_link', 0)
|
call ale#Set('ruby_reek_show_wiki_link', 0)
|
||||||
|
call ale#Set('ruby_reek_options', '')
|
||||||
|
call ale#Set('ruby_reek_executable', 'reek')
|
||||||
|
|
||||||
function! ale_linters#ruby#reek#VersionCheck(buffer) abort
|
function! ale_linters#ruby#reek#VersionCheck(buffer) abort
|
||||||
" If we have previously stored the version number in a cache, then
|
" If we have previously stored the version number in a cache, then
|
||||||
@ -12,18 +14,23 @@ function! ale_linters#ruby#reek#VersionCheck(buffer) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 'reek --version'
|
let l:executable = ale#Var(a:buffer, 'ruby_reek_executable')
|
||||||
|
|
||||||
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'reek')
|
||||||
|
\ . ' --version'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#ruby#reek#GetCommand(buffer, version_output) abort
|
function! ale_linters#ruby#reek#GetCommand(buffer, version_output) abort
|
||||||
let l:version = ale#semver#GetVersion('reek', a:version_output)
|
let l:version = ale#semver#GetVersion('reek', a:version_output)
|
||||||
|
let l:executable = ale#Var(a:buffer, 'ruby_reek_executable')
|
||||||
|
|
||||||
" Tell reek what the filename is if the version of reek is new enough.
|
" Tell reek what the filename is if the version of reek is new enough.
|
||||||
let l:display_name_args = ale#semver#GTE(l:version, [5, 0, 0])
|
let l:display_name_args = ale#semver#GTE(l:version, [5, 0, 0])
|
||||||
\ ? ' --stdin-filename %s'
|
\ ? ' --stdin-filename %s'
|
||||||
\ : ''
|
\ : ''
|
||||||
|
|
||||||
return 'reek -f json --no-progress --no-color'
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'reek')
|
||||||
|
\ . ' -f json --no-progress --no-color'
|
||||||
\ . l:display_name_args
|
\ . l:display_name_args
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -62,7 +69,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('ruby', {
|
call ale#linter#Define('ruby', {
|
||||||
\ 'name': 'reek',
|
\ 'name': 'reek',
|
||||||
\ 'executable': 'reek',
|
\ 'executable_callback': ale#VarFunc('ruby_reek_executable'),
|
||||||
\ 'command_chain': [
|
\ 'command_chain': [
|
||||||
\ {'callback': 'ale_linters#ruby#reek#VersionCheck'},
|
\ {'callback': 'ale_linters#ruby#reek#VersionCheck'},
|
||||||
\ {'callback': 'ale_linters#ruby#reek#GetCommand'},
|
\ {'callback': 'ale_linters#ruby#reek#GetCommand'},
|
||||||
|
@ -2,12 +2,9 @@
|
|||||||
" Description: RuboCop, a code style analyzer for Ruby files
|
" Description: RuboCop, a code style analyzer for Ruby files
|
||||||
|
|
||||||
function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
|
function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
|
||||||
let l:executable = ale#handlers#rubocop#GetExecutable(a:buffer)
|
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||||
let l:exec_args = l:executable =~? 'bundle$'
|
|
||||||
\ ? ' exec rubocop'
|
|
||||||
\ : ''
|
|
||||||
|
|
||||||
return ale#Escape(l:executable) . l:exec_args
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'rubocop')
|
||||||
\ . ' --format json --force-exclusion '
|
\ . ' --format json --force-exclusion '
|
||||||
\ . ale#Var(a:buffer, 'ruby_rubocop_options')
|
\ . ale#Var(a:buffer, 'ruby_rubocop_options')
|
||||||
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
|
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
|
||||||
@ -55,7 +52,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('ruby', {
|
call ale#linter#Define('ruby', {
|
||||||
\ 'name': 'rubocop',
|
\ 'name': 'rubocop',
|
||||||
\ 'executable_callback': 'ale#handlers#rubocop#GetExecutable',
|
\ 'executable_callback': ale#VarFunc('ruby_rubocop_executable'),
|
||||||
\ 'command_callback': 'ale_linters#ruby#rubocop#GetCommand',
|
\ 'command_callback': 'ale_linters#ruby#rubocop#GetCommand',
|
||||||
\ 'callback': 'ale_linters#ruby#rubocop#Handle',
|
\ 'callback': 'ale_linters#ruby#rubocop#Handle',
|
||||||
\})
|
\})
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
call ale#Set('ruby_rubocop_options', '')
|
||||||
|
call ale#Set('ruby_rubocop_executable', 'rubocop')
|
||||||
|
|
||||||
function! ale#fixers#rubocop#GetCommand(buffer) abort
|
function! ale#fixers#rubocop#GetCommand(buffer) abort
|
||||||
let l:executable = ale#handlers#rubocop#GetExecutable(a:buffer)
|
let l:executable = ale#Var(a:buffer, 'ruby_rubocop_executable')
|
||||||
let l:exec_args = l:executable =~? 'bundle$'
|
|
||||||
\ ? ' exec rubocop'
|
|
||||||
\ : ''
|
|
||||||
let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
let l:config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
||||||
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
|
let l:options = ale#Var(a:buffer, 'ruby_rubocop_options')
|
||||||
|
|
||||||
return ale#Escape(l:executable) . l:exec_args
|
return ale#handlers#ruby#EscapeExecutable(l:executable, 'rubocop')
|
||||||
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
|
\ . (!empty(l:config) ? ' --config ' . ale#Escape(l:config) : '')
|
||||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||||
\ . ' --auto-correct %t'
|
\ . ' --auto-correct %t'
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
call ale#Set('ruby_rubocop_options', '')
|
|
||||||
call ale#Set('ruby_rubocop_executable', 'rubocop')
|
|
||||||
|
|
||||||
function! ale#handlers#rubocop#GetExecutable(buffer) abort
|
|
||||||
return ale#Var(a:buffer, 'ruby_rubocop_executable')
|
|
||||||
endfunction
|
|
@ -37,3 +37,10 @@ function! ale#handlers#ruby#HandleSyntaxErrors(buffer, lines) abort
|
|||||||
return s:HandleSyntaxError(a:buffer, a:lines)
|
return s:HandleSyntaxError(a:buffer, a:lines)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#handlers#ruby#EscapeExecutable(executable, bundle_exec) abort
|
||||||
|
let l:exec_args = a:executable =~? 'bundle'
|
||||||
|
\ ? ' exec ' . a:bundle_exec
|
||||||
|
\ : ''
|
||||||
|
|
||||||
|
return ale#Escape(a:executable) . l:exec_args
|
||||||
|
endfunction
|
||||||
|
@ -5,6 +5,15 @@ ALE Ruby Integration *ale-ruby-options*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
brakeman *ale-ruby-brakeman*
|
brakeman *ale-ruby-brakeman*
|
||||||
|
|
||||||
|
g:ale_ruby_brakeman_executable *g:ale_ruby_brakeman_executable*
|
||||||
|
*b:ale_ruby_brakeman_executable*
|
||||||
|
Type: String
|
||||||
|
Default: `'brakeman'`
|
||||||
|
|
||||||
|
Override the invoked brakeman binary. Set this to `'bundle'` to invoke
|
||||||
|
`'bundle` `exec` brakeman'.
|
||||||
|
|
||||||
|
|
||||||
g:ale_ruby_brakeman_options *g:ale_ruby_brakeman_options*
|
g:ale_ruby_brakeman_options *g:ale_ruby_brakeman_options*
|
||||||
*b:ale_ruby_brakeman_options*
|
*b:ale_ruby_brakeman_options*
|
||||||
Type: |String|
|
Type: |String|
|
||||||
@ -20,10 +29,11 @@ g:ale_ruby_rails_best_practices_executable
|
|||||||
*g:ale_ruby_rails_best_practices_executable*
|
*g:ale_ruby_rails_best_practices_executable*
|
||||||
*b:ale_ruby_rails_best_practices_executable*
|
*b:ale_ruby_rails_best_practices_executable*
|
||||||
Type: String
|
Type: String
|
||||||
Default: 'rails_best_practices'
|
Default: `'rails_best_practices'`
|
||||||
|
|
||||||
Override the invoked rails_best_practices binary. Set this to `'bundle'` to
|
Override the invoked rails_best_practices binary. Set this to `'bundle'` to
|
||||||
invoke `'bundle` `exec` `rails_best_practices'`.
|
invoke `'bundle` `exec` rails_best_practices'.
|
||||||
|
|
||||||
|
|
||||||
g:ale_ruby_rails_best_practices_options
|
g:ale_ruby_rails_best_practices_options
|
||||||
*g:ale_ruby_rails_best_practices_options*
|
*g:ale_ruby_rails_best_practices_options*
|
||||||
@ -37,6 +47,15 @@ g:ale_ruby_rails_best_practices_options
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
reek *ale-ruby-reek*
|
reek *ale-ruby-reek*
|
||||||
|
|
||||||
|
g:ale_ruby_reek_executable *g:ale_ruby_reek_executable*
|
||||||
|
*b:ale_ruby_reek_executable*
|
||||||
|
Type: String
|
||||||
|
Default: `'reek'`
|
||||||
|
|
||||||
|
Override the invoked reek binary. Set this to `'bundle'` to invoke
|
||||||
|
`'bundle` `exec` reek'.
|
||||||
|
|
||||||
|
|
||||||
g:ale_ruby_reek_show_context *g:ale_ruby_reek_show_context*
|
g:ale_ruby_reek_show_context *g:ale_ruby_reek_show_context*
|
||||||
*b:ale_ruby_reek_show_context*
|
*b:ale_ruby_reek_show_context*
|
||||||
Type: |Number|
|
Type: |Number|
|
||||||
@ -63,8 +82,8 @@ g:ale_ruby_rubocop_executable *g:ale_ruby_rubocop_executable*
|
|||||||
Type: String
|
Type: String
|
||||||
Default: `'rubocop'`
|
Default: `'rubocop'`
|
||||||
|
|
||||||
Override the invoked rubocop binary. This is useful for running rubocop
|
Override the invoked rubocop binary. Set this to `'bundle'` to invoke
|
||||||
from binstubs or a bundle.
|
`'bundle` `exec` rubocop'.
|
||||||
|
|
||||||
|
|
||||||
g:ale_ruby_rubocop_options *g:ale_ruby_rubocop_options*
|
g:ale_ruby_rubocop_options *g:ale_ruby_rubocop_options*
|
||||||
|
@ -12,7 +12,8 @@ Execute(The brakeman command callback should detect absence of a valid Rails app
|
|||||||
Execute(The brakeman command callback should find a valid Rails app root):
|
Execute(The brakeman command callback should find a valid Rails app root):
|
||||||
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
|
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
|
||||||
|
|
||||||
AssertLinter 'brakeman', 'brakeman -f json -q -p '
|
AssertLinter 'brakeman', ale#Escape('brakeman')
|
||||||
|
\ . ' -f json -q -p '
|
||||||
\ . ale#Escape(ale#path#Simplify(g:dir . '/../ruby_fixtures/valid_rails_app'))
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../ruby_fixtures/valid_rails_app'))
|
||||||
|
|
||||||
Execute(The brakeman command callback should include configured options):
|
Execute(The brakeman command callback should include configured options):
|
||||||
@ -20,5 +21,17 @@ Execute(The brakeman command callback should include configured options):
|
|||||||
|
|
||||||
let g:ale_ruby_brakeman_options = '--combobulate'
|
let g:ale_ruby_brakeman_options = '--combobulate'
|
||||||
|
|
||||||
AssertLinter 'brakeman', 'brakeman -f json -q --combobulate -p '
|
AssertLinter 'brakeman', ale#Escape('brakeman')
|
||||||
|
\ . ' -f json -q --combobulate -p '
|
||||||
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../ruby_fixtures/valid_rails_app'))
|
||||||
|
|
||||||
|
Execute(Setting bundle appends 'exec brakeman'):
|
||||||
|
call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
|
||||||
|
|
||||||
|
let g:ale_ruby_brakeman_executable = 'bundle'
|
||||||
|
let g:ale_ruby_brakeman_options = '--combobulate'
|
||||||
|
|
||||||
|
AssertLinter 'bundle', ale#Escape('bundle')
|
||||||
|
\ . ' exec brakeman'
|
||||||
|
\ . ' -f json -q --combobulate -p '
|
||||||
\ . ale#Escape(ale#path#Simplify(g:dir . '/../ruby_fixtures/valid_rails_app'))
|
\ . ale#Escape(ale#path#Simplify(g:dir . '/../ruby_fixtures/valid_rails_app'))
|
||||||
|
@ -7,8 +7,8 @@ After:
|
|||||||
Execute(The reek callbacks should return the correct default values):
|
Execute(The reek callbacks should return the correct default values):
|
||||||
WithChainResults ['reek 5.0.0']
|
WithChainResults ['reek 5.0.0']
|
||||||
AssertLinter 'reek', [
|
AssertLinter 'reek', [
|
||||||
\ 'reek --version',
|
\ ale#Escape('reek') . ' --version',
|
||||||
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
|
\ ale#Escape('reek') . ' -f json --no-progress --no-color --stdin-filename %s',
|
||||||
\]
|
\]
|
||||||
|
|
||||||
" Try with older versions.
|
" Try with older versions.
|
||||||
@ -16,19 +16,35 @@ Execute(The reek callbacks should return the correct default values):
|
|||||||
|
|
||||||
WithChainResults ['reek 4.8.2']
|
WithChainResults ['reek 4.8.2']
|
||||||
AssertLinter 'reek', [
|
AssertLinter 'reek', [
|
||||||
\ 'reek --version',
|
\ ale#Escape('reek') . ' --version',
|
||||||
\ 'reek -f json --no-progress --no-color',
|
\ ale#Escape('reek') . ' -f json --no-progress --no-color',
|
||||||
\]
|
\]
|
||||||
|
|
||||||
|
Execute(Setting bundle appends 'exec reek'):
|
||||||
|
let g:ale_ruby_reek_executable = 'bundle'
|
||||||
|
|
||||||
|
WithChainResults ['reek 5.0.0']
|
||||||
|
AssertLinter 'bundle', ale#Escape('bundle')
|
||||||
|
\ . ' exec reek'
|
||||||
|
\ . ' -f json --no-progress --no-color --stdin-filename %s',
|
||||||
|
|
||||||
|
" Try with older versions.
|
||||||
|
call ale#semver#ResetVersionCache()
|
||||||
|
|
||||||
|
WithChainResults ['reek 4.8.2']
|
||||||
|
AssertLinter 'bundle', ale#Escape('bundle')
|
||||||
|
\ . ' exec reek'
|
||||||
|
\ . ' -f json --no-progress --no-color'
|
||||||
|
|
||||||
Execute(The reek version check should be cached):
|
Execute(The reek version check should be cached):
|
||||||
WithChainResults ['reek 5.0.0']
|
WithChainResults ['reek 5.0.0']
|
||||||
AssertLinter 'reek', [
|
AssertLinter 'reek', [
|
||||||
\ 'reek --version',
|
\ ale#Escape('reek') . ' --version',
|
||||||
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
|
\ ale#Escape('reek') . ' -f json --no-progress --no-color --stdin-filename %s',
|
||||||
\]
|
\]
|
||||||
|
|
||||||
WithChainResults []
|
WithChainResults []
|
||||||
AssertLinter 'reek', [
|
AssertLinter 'reek', [
|
||||||
\ '',
|
\ '',
|
||||||
\ 'reek -f json --no-progress --no-color --stdin-filename %s',
|
\ ale#Escape('reek') . ' -f json --no-progress --no-color --stdin-filename %s',
|
||||||
\]
|
\]
|
||||||
|
Loading…
Reference in New Issue
Block a user