简体   繁体   中英

JSHint doesn't work in vim

On invoking :SyntasticInfo :

Syntastic version: 3.8.0-94 (Vim 800, Linux, GUI)
Info for filetype: javascript
Global mode: active
Filetype javascript is active
The current file will be checked automatically
Available checker: jshint
Currently enabled checker: jshint

I've installed both JSHint and Syntastic via vim-pathogen.

What is one supposed to configure in order to make the syntax checking work?

In Syntastic's documentation on JSHint , nothing special is mentioned about configuration, other than

This checker is initialised using the "makeprgBuild()" function and thus it accepts the standard options described at |syntastic-config-makeprg|.

On a side note, syntax checking does work for TypeScript, using Syntastic.

.vimrc:

syntax on
colorscheme industry

execute pathogen#infect()
filetype plugin on

set textwidth=0
set softtabstop=4
let &shiftwidth=&softtabstop
set autoindent
set number

" Used for using buffers and tabs the right way.
set hidden

" Enable airline
let g:airline#extensions#tabline#enabled = 1

" Use powerline fonts
let g:airline_powerline_fonts = 1

"Open NERDTree on startup
"autocmd vimenter * NERDTree

map <C-n> :NERDTreeToggle<CR>

:let mapleader = "/"

" Mappings to access buffers (don't use "\p" because a
" delay before pressing "p" would accidentally paste).
" \l       : list buffers
" \b \f \g : go back/forward/last-used
" \1 \2 \3 : go to buffer 1/2/3 etc
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
nnoremap <Leader>f :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" It's useful to show the buffer number in the status line.
"set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

" Enable color highlighting by Powerline in vim.
set t_Co=256

" Display buffer number in Airline
 let g:airline#extensions#tabline#buffer_nr_show = 1

" Enable tab support in Airline
let g:airline#extensions#tabline#enabled = 1

autocmd BufNewFile,BufRead *.ts setlocal filetype=typescript

" Close a buffer without closing its window
map <Leader>q :bp<bar>sp<bar>bn<bar>bd<CR>

" Split a window without resizing the others
set noequalalways

" Don't autoindent when editing text files --- no suffix filenames.
set noautoindent
augroup vimrc_indent
    au!
    autocmd FileType * set autoindent
augroup END

"Toggle scrolling by display lines instead of file lines.
noremap <silent> <Leader>w :call ToggleWrap()<CR>
function ToggleWrap()
  if &wrap
    echo "Wrap OFF"
    setlocal nowrap
    set virtualedit=all
    silent! nunmap <buffer> <Up>
    silent! nunmap <buffer> <Down>
    silent! nunmap <buffer> <Home>
    silent! nunmap <buffer> <End>
    silent! iunmap <buffer> <Up>
    silent! iunmap <buffer> <Down>
    silent! iunmap <buffer> <Home>
    silent! iunmap <buffer> <End>
  else
    echo "Wrap ON"
    setlocal wrap linebreak nolist
    set virtualedit=
    setlocal display+=lastline
    noremap  <buffer> <silent> <Up>   gk
    noremap  <buffer> <silent> <Down> gj
    noremap  <buffer> <silent> <Home> g<Home>
    noremap  <buffer> <silent> <End>  g<End>
    inoremap <buffer> <silent> <Up>   <C-o>gk
    inoremap <buffer> <silent> <Down> <C-o>gj
    inoremap <buffer> <silent> <Home> <C-o>g<Home>
    inoremap <buffer> <silent> <End>  <C-o>g<End>
    noremap  <buffer> <silent> k gk
    noremap  <buffer> <silent> j gj
    noremap  <buffer> <silent> 0 g0
    noremap  <buffer> <silent> $ g$
  endif
endfunction

"Disable folding
set foldenable

"JS syntax checking
let g:syntastic_javascript_checkers = ['jshint']

You don't have any configuration for Syntastic telling it to run. You might start with the recommended settings as listed when you run :help syntastic-recommended :

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

You can also manually invoke Syntastic with :SyntasticCheck

If it is on-the-fly linting that you desire, as recommended in one of the comments, then you should switch from Syntastic to ALE (I recommend ALE in general)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM