Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jshint linter #2

Merged
merged 3 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ name. That seems to be the fairest way to arrange this table.
| -------- | ----- |
| Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set) |
| Bourne Shell | [-n flag](http://linux.die.net/man/1/sh) |
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/) |
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) |
| Python | [flake8](http://flake8.pycqa.org/en/latest/) |
| Ruby | [rubocop](https://github.com/bbatsov/rubocop) |

Expand Down
58 changes: 58 additions & 0 deletions ale_linters/javascript/jshint.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
" Author: Chris Kyrouac - https://github.com/fijshion

if exists('g:loaded_ale_linters_javascript_jshint')
finish
endif

let g:loaded_ale_linters_javascript_jshint = 1

" Set this to the location of the jshint configuration file
if !exists('g:ale_jshint_config_loc')
let g:ale_jshint_config_loc = '.jshintrc'
endif

function! ale_linters#javascript#jshint#Handle(buffer, lines)
" Matches patterns line the following:
"
" stdin:57:9: Missing name in function declaration.
" stdin:60:5: Attempting to override 'test2' which is a constant.
" stdin:57:10: 'test' is defined but never used.
" stdin:57:1: 'function' is defined but never used.
let pattern = '^.\+:\(\d\+\):\(\d\+\): \(.\+\)'
let output = []

for line in a:lines
let l:match = matchlist(line, pattern)

if len(l:match) == 0
continue
endif

let text = l:match[3]
let marker_parts = l:match[4]

if len(marker_parts) == 2
let text = text . ' (' . marker_parts[1] . ')'
endif

" vcol is Needed to indicate that the column is a character.
call add(output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0,
\ 'vcol': 0,
\ 'col': l:match[2] + 0,
\ 'text': text,
\ 'type': 'E',
\ 'nr': -1,
\})
endfor

return output
endfunction

call ALEAddLinter('javascript', {
\ 'name': 'jshint',
\ 'executable': 'jshint',
\ 'command': 'jshint --reporter unix --config ' . g:ale_jshint_config_loc . ' -',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a default for the config location or make the config option in some way. I now offer a command_callback option which lets you generate the command string which will be run in a job. The function takes a buffer number as its only argument. You can look at the shell linter I just added around an hour ago for an example of its use.

Thank you for adding more tools! You contribution is much appreciated. I need to add an option for selecting which linters you want, which is part of why I now require a 'name' option in the dictionary here for identifying which linter it is for which filetype. I'll add that once my RSI clears up. I've been having some issues recently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I forgot to include plugin/ale/aaflags.vim in this commit. Force pushed an update. Let me know if you like it.

Thank you for writing this! I've been using it all day.. it's very useful and speedy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. I'll keep adding more to it especially after I am able to recover from some recent RSI issues I have been experiencing.

\ 'callback': 'ale_linters#javascript#jshint#Handle',
\})