summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorJustin Searls <searls@gmail.com>2018-12-10 16:02:32 -0500
committerBjorn Neergaard <bjorn@neersighted.com>2018-12-10 14:02:32 -0700
commit2cfa09e02d65cd06649fb1ae5f988b7a110a124d (patch)
treed92176e4ddc7dfa5b42c7018ca568d0a73b156a5 /ale_linters
parentc899ff3523e716efb71907234d7ca2e740c9e761 (diff)
downloadale-2cfa09e02d65cd06649fb1ae5f988b7a110a124d.zip
Adds standardrb linter (#2133)
See: https://github.com/testdouble/standard StandardRB is to RuboCop what StandardJS is to ESLint. This commit naively copies the RuboCop linter and fixer to point at the standardrb executable. Any other adjustments are very minor (the only I can think of is that standardrb takes a `--fix` option instead of `--auto-correct`). This raises a confusing point to me as both developer and a user: since ale enables all linters by default, won't this run both RuboCop and StandardRB (the results of which will almost always be in conflict with one another)? How does ale already solve for this for the similar case of StandardJS and ESLint?
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/ruby/rubocop.vim32
-rw-r--r--ale_linters/ruby/standardrb.vim23
2 files changed, 24 insertions, 31 deletions
diff --git a/ale_linters/ruby/rubocop.vim b/ale_linters/ruby/rubocop.vim
index 45218394..790ca82c 100644
--- a/ale_linters/ruby/rubocop.vim
+++ b/ale_linters/ruby/rubocop.vim
@@ -13,36 +13,6 @@ function! ale_linters#ruby#rubocop#GetCommand(buffer) abort
\ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
endfunction
-function! ale_linters#ruby#rubocop#Handle(buffer, lines) abort
- try
- let l:errors = json_decode(a:lines[0])
- catch
- return []
- endtry
-
- if !has_key(l:errors, 'summary')
- \|| l:errors['summary']['offense_count'] == 0
- \|| empty(l:errors['files'])
- return []
- endif
-
- let l:output = []
-
- for l:error in l:errors['files'][0]['offenses']
- let l:start_col = l:error['location']['column'] + 0
- call add(l:output, {
- \ 'lnum': l:error['location']['line'] + 0,
- \ 'col': l:start_col,
- \ 'end_col': l:start_col + l:error['location']['length'] - 1,
- \ 'code': l:error['cop_name'],
- \ 'text': l:error['message'],
- \ 'type': ale_linters#ruby#rubocop#GetType(l:error['severity']),
- \})
- endfor
-
- return l:output
-endfunction
-
function! ale_linters#ruby#rubocop#GetType(severity) abort
if a:severity is? 'convention'
\|| a:severity is? 'warning'
@@ -57,5 +27,5 @@ call ale#linter#Define('ruby', {
\ 'name': 'rubocop',
\ 'executable_callback': ale#VarFunc('ruby_rubocop_executable'),
\ 'command_callback': 'ale_linters#ruby#rubocop#GetCommand',
-\ 'callback': 'ale_linters#ruby#rubocop#Handle',
+\ 'callback': 'ale#ruby#HandleRubocopOutput',
\})
diff --git a/ale_linters/ruby/standardrb.vim b/ale_linters/ruby/standardrb.vim
new file mode 100644
index 00000000..95e10934
--- /dev/null
+++ b/ale_linters/ruby/standardrb.vim
@@ -0,0 +1,23 @@
+" Author: Justin Searls https://github.com/searls, ynonp - https://github.com/ynonp, Eddie Lebow https://github.com/elebow
+" based on the ale rubocop linter
+" Description: StandardRB - Ruby Style Guide, with linter & automatic code fixer
+
+call ale#Set('ruby_standardrb_executable', 'standardrb')
+call ale#Set('ruby_standardrb_options', '')
+
+function! ale_linters#ruby#standardrb#GetCommand(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'ruby_standardrb_executable')
+
+ return ale#handlers#ruby#EscapeExecutable(l:executable, 'standardrb')
+ \ . ' --format json --force-exclusion '
+ \ . ale#Var(a:buffer, 'ruby_standardrb_options')
+ \ . ' --stdin ' . ale#Escape(expand('#' . a:buffer . ':p'))
+endfunction
+
+" standardrb is based on RuboCop so the callback is the same
+call ale#linter#Define('ruby', {
+\ 'name': 'standardrb',
+\ 'executable_callback': ale#VarFunc('ruby_standardrb_executable'),
+\ 'command_callback': 'ale_linters#ruby#standardrb#GetCommand',
+\ 'callback': 'ale#ruby#HandleRubocopOutput',
+\})