Things about Javascipt syntax checking

Web
Rykka at 2015/03/18

本文地址:http://rykka.me/javscript_syntax_checking.html

While coding, We should using a thing to check if things has been done write before we run it.

Which could avoid many runtime errors...

So a syntax checker is needed, for pointing out errors.

About Javascript's syntax style

But, along with javscript's errors, there is a debate about semicolon(;) which should or not be use it, u might be heard.

If you are a c/c++/java user, then using it may calm you down,

but If you are a python user, the semicolon may make you sick.

In fact, we can ignore semicolon for free, as ALL browser will automatic insert semicolon (asi) as expected.

izs has write a nice (and a bit agressive) article about it.

How we check syntax in vim

In vim, we can using syntastic to check syntax while coding.

You can use Vundle or NeoBundle to install it, like:

..code:: vim

NeoBundleInstall 'scrooloose/syntastic'

After installation, you should saw syntax tips while editing with javscript filetypes.

But, by default it's using jslint, and the missing semicolon will raise errors.

To ignore warning, we should use jshint instead.

npm install -g jshint

Then change the syntastic setting in your vimrc.

let g:syntastic_javascript_checkers = ['jshint']

After that, while writing js, you should see there will be warning , not error when missing semicolon.

To depress the warning, we can write a .jslintrc to configure it's option.

~/.jslintrc

{
    asi: true
}

(More options can be found on http://jshint.com/docs/options/)

Then no warning of semicolon should be seen.

That's all, enjoy your javascript coding~

:)