Javascript Syntax Checking From Vim

Syntax checking from vim is handy. By checking your Javascript syntax from vim, rather than the browser, you'll save time and aggravation. To do it, you'll need Spidermonkey, which allows you to run Javascript without a browser, and JsLint, a Javascript syntax-checker writter in Javascript.

Installing Spidermonkey

Consult the build instructions page for installation instructions for many architectures, or use the quick instructions below for Ubuntu and Centos.

Quick install for Ubuntu
sudo apt-get install spidermonkey-bin.
Quick install for Centos 5
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
tar zxvf js-1.7.0.tar.gz
cd js/src
make -f Makefile.ref
mv Linux_All_DBG.OBJ/js /usr/bin

Once you've installed Spidermonkey you'll be able to enter a Javascript shell by entering the command 'js' (exit with CTRL-d).

Setting Up JsLint

Next you'll need to download the JsLint Javascript syntax checking library. JsLint is composed of one Javascript file: fulljslint.js.

Download it and put it somewhere handy, for example:

wget http://www.jslint.com/fulljslint.js
mv fulljslint.js /home/admin/bin/js

Running JsLint

Next you'll need to add a Javascript file which will implement JsLint, using the technique outlined by Ian Bicking.

For example, I could create a file called runjslint.js like this as /home/admin/bin/js/runjslint.js:

load('/home/admin/bin/js/fulljslint.js');
 
var body = arguments[0];
 
var result = JSLINT(body);
if (result) {
 print('All good.');
} else {
 print('Problems:');
}
print(JSLINT.report());

This file, when ran using Spidermonkey, will check the syntax of Javascript data passed as a command line argument.

Integrating with Vim

Next you'll need to add a line to your .vimrc script to allow you to enter a command for syntax checking.

Here's an example that enables me to syntax check by typing ":js".

cabbr js !js /home/admin/bin/js/runjslint.js "`cat %`"

Formatting JsLint's Results

Last, but not least, you may want to add this Python script to change JsLint's results from HTML/CSS to plain text. Put this script in an appropriate place, for example '/home/admin/bin/python/format_lint_output.py'.

#!/usr/bin/python
import sys
import re
 
def format_lint_line(line):
 line = line.replace('<p>', '\n')
 line = line.replace('&nbsp;', ' ')
 return line
 
def remove_html_tags(data):
 p = re.compile(r'<.*?>')
 return p.sub('', data)
 
for line in sys.stdin:
 print remove_html_tags(format_lint_line(line)),

Change your .vimrc file to use it as a filter.

For example:

cabbr js !js /home/admin/bin/js/runjslint.js "`cat %`" \| /home/admin/bin/python/format_lint_output.py

  • tommy9696 (not verified)
    Tue, 2010-02-02 08:15

    Syntastic comes in two parts: the syntax checker plugins, and the core script
    (i.e. syntastic.vim). 646-223 dumps The syntax checker plugins are defined on a per-filetype
    basis where each one wraps up an external syntax checking program. The core
    script delegates off to these plugins and uses their output to provide the syntastic functionality. Currently, syntax checking plugins exist for eruby,
    haml, html, javascript, php, 642-357 dumps python, ruby and sass. If your language is not supported then see |syntastic- VCP-410 dumps syntax-checkers| for details on how to implement a syntax checking plugin, and be sure to send me a
    patch ;-)

  • 冷却器 (not verified)
    Thu, 2010-01-28 01:22
  • Anonymous (not verified)
    Wed, 2010-01-13 16:08
  • Anonymous (not verified)
    Wed, 2010-01-20 09:52
  • Anonymous (not verified)
    Mon, 2010-02-08 09:39
  • Anonymous (not verified)
    Thu, 2009-11-12 07:10
  • Anonymous (not verified)
    Thu, 2009-11-12 07:08
  • Anonymousa (not verified)
    Thu, 2009-10-29 10:20
  • Anonymous (not verified)
    Thu, 2009-10-29 10:18
  • Anonymous (not verified)
    Thu, 2009-10-29 10:17
  • mindspring (not verified)
    Wed, 2009-10-28 19:07

    Excellent post thank you very much for taking the time to share with those who are starting on the subject. Greetings

  • ape (not verified)
    Fri, 2009-10-23 06:35
  • Anonymous (not verified)
    Tue, 2009-10-20 01:31
  • Anonymous (not verified)
    Sun, 2009-10-18 16:15

    منتدى
     

    دعم المواقع  برامج حماية  برامج النت  برامج محمولة  برامج نوكيا  العاب نوكيا  كرة القدم  العاب كمبيوتر  العاب بلاي ستيشن

     العاب تورنت  افلام كرتون  العاب اطفال  صور كرتون  اغاني اطفال  مطبخ المنتدى  قــســم التشويق والاثارة  منتدى التجارين

     منتديات منتدانا



    برج الجدى
      ,
    برج الحمل
    ,
     برج الميزان
    ,
     برج الجوزاء
    ,
     برج الحوت
    , 
    برج العذراء
    ,
     برج العقرب

     برج الاسد

     برج القوس
    , 
    برج الثور
    , 
    برج الدلو
     
    برج السرطان

    , 
    الابراج الصينية


    صور عربيات  ,  تحميل ثيمات نوكيا 
    , صور انتريهات 
    , طبخ جزائرى ,
     اجدد الرسائل الرومانسية 
    ,   صور
    دراغون بول
     ,  
    صور رعب ,
     صور حزينه ,
    المحاسبة
    المالية
    ,
    كوانزو
    , ليلة
    الدخله

     switchsniffer شرح
     , 
    اغاني عيد ميلاد
    ,   حمامات
    غرف نوم الاطفال 
    ستائر
    صالونات
    غرف النوم 
    , silkroad لعبة

    اذكار الصباح والمساء  
    محمد حسين يعقوب 
    , تفسير القران الكريم

    مفاتيح كاسبر سكاي 
    , كاسبر سكاى   , المواقع الاباحية 
    , مسلسل القناص


    العاب باربى 
    | 
    صور رعب   | 
    الهالات السوداء  
    |  
    ملفات
    psd 
    |  
    خطوط للفوتوشوب  | 
    ميريام | 
    طيور|

     

    طلبات الاستضافة/الدومينات
    الحوار العام
    الشباب والبنات

     التعارف
    قضايا
    المدونات
    السياحة والسفر
    العلوم النفسية
    برامج مهمة
    برامج الرسم
    برامج الملتيمديا

    الويندوز

    برامج متنوعة
    ثيمات نوكيا
    مقاطع البلوتوث
    الرسائل
    كرة القدم العالمية
     كرة القدم العربية
     كرة القدم المصرية
    المصارعة
     شفرات الالعاب

    الضحك والفرفشة
    الكاريكاتير
    السيارات
     اليوتيوب
    الافلام الاجنبية
    الصور
    تعليم جرافيكس
     تزيين العروسة
     العناية بالبشرة
     الديكور
     الاثاث
    مطبخ
    قصص رومانسية

    كلام فى الحب
    قصص رعب
     طيور الزينة
    اسماك
    الصيد
    اللغة الانجليزية
     اللغة الفرنسية
    اللغة الالمانية
    اللغة الايطالية
    الحاسب الالى
     المحاسبة
    البورصة
     الشهادات التجارية
    استضافة مواقع ومنتديات
    اغاني الكرتون

    امتحان ثانويه
    عامه


    Winning Eleven


    نغمات مضحكة

    القصص الاسلامية
     الصور الاسلامية
    صيانة الموبايل

    برنامج رسم

    صور حب
     

     
     

  • Anonymous (not verified)
    Sun, 2009-10-18 13:46
  • Anonymous (not verified)
    Sat, 2009-10-17 02:27
  • Anonymous (not verified)
    Wed, 2009-07-15 14:44

    awesome tutorial, man. I don't know what most js hackers use. Maybe notepad plus firebug? Anyway, your tutorial saved me a TON of time adapting my habitual linux/vim/php environment to js.

    Suggestion: while it's nice to see an attempt at a CAPTCHA in your submit form, you might want to check out recaptcha to get something more ironclad in place and prevent any more chinese spam from piling up.

    Anyway, thanks again

  • I <3 Vim (not verified)
    Fri, 2009-01-23 17:10

    You can have vim auto-lint for you:

    :autocmd BufWritePre,FileWritePre,FileAppendPre *.js js

    You may prefer to use the *Post instead of the *Pre.

  • Anonymous (not verified)
    Sun, 2008-08-31 19:25

    The next step would be making it integrate with Quickfix, I suppose. I do that with Python, so I type :make to syntax check my Python code.

  • Anonymous (not verified)
    Wed, 2010-01-13 20:11

    This is exactly what I was looking for. Thanks for sharing this great article! That is very interesting Smile I love reading and I am always searching for informative information like this!

    Top 10 MMA Pound For Pound Fighter Rankings | Mixed martial arts | Mma Pound For Pound day 1

  • Reid (not verified)
    Sun, 2008-08-31 07:53

    eclim is a very weird project that tries to integrate vim with eclipse, but even if you don't use that, it comes bundled with integrated jslint checking. It's awesome. When you write out the file, it flags any lint errors in the file with a "sign" (type ":help signs").

    http://eclim.sf.net

  • mde (not verified)
    Sun, 2008-09-07 02:57

    Very nice post, sir. Thanks for this.

    I just posted a bit on my blog about using Lynx instead to filter the HTML output into plaintext. Maybe prettier output than the Python script.

    Thanks again -- makes my JavaScripty day-to-day just a bit nicer.

    Matthew

  • Anonymous (not verified)
    Tue, 2009-10-13 09:03

    Djerba wczasy
    Meksyk Last Minute
    wczasy meksyk acapulco
    wycieczki wczasy cancun
    Goa Wakacje
    Dubaj last minute
    Jamajka last minute
    Barbados wakacje
    polinezja francuska wakacje
    sri lanka last minute
    Tanzania wycieczki
    Zanzibar
    fuertaventura last minute
    Rejsy morskie
    wycieczkowe
    Last Minute all
    inclusive
    wycieczki
    Egipt last minute
    wycieczki
    first minute 2010
    wczasy 2010 all
    inclusive wycieczki wczasy bali tajlandia kuba teneryfa dominikana
    wakacje

  • Andy (not verified)
    Thu, 2008-11-13 16:16

    This and other blog posts inspired me to come up with another method, so I altered the rhino version so that it works with spidermonkey as a pipe or redirect target. It's a bit more flexible, doesn't require html parsing, and a pantload faster than the Rhino version. Enjoy!

    http://whereisandy.com/code/jslint

  • Hans (not verified)
    Sat, 2010-02-06 01:12

    Thanks for share this :)

    nowGoogle.com adalah Multiple Search Engine Popular agar semakin membuka
    Peluang Usaha Ahasu Gnaulep yang bisa membuat kita memiliki
    Efek Blogging Terhadap Motivasi Diri

    Jasa Pembuatan Blog
    Paket Ebook Bisnis
    Blog Bisnis Online
    Blog Motivasi
    Increase Your Traffic With Klikrar
    Financial Journey
    Aetna Health Insurance
    Free Download Mp3
    Blogging Resources
    Professional Journal
    bibit parfum
    Bisnis Hosting

  • 出会い系サイト (not verified)
    Thu, 2009-10-15 10:17

    出会い系サイトにで安心の出会いを楽しんでみませんか?
    出会い系サイトは出会うためのサイトなので確実に出会いが探せます!
    出会い系サイトに登録している方生活していて出会いがあまりない方ばかりです!
    出会い系サイトは安心で優良です!
    出会い系サイトの登録は無料ででき、
    出会い系サイトトでは楽しく出会うことが出来ます!
    出会い系サイトの中には悪徳の
    出会い系サイトのありちゃんと出会い系サイトを見極める必要があります!
    出会い系サイトの見極め方はとてもかんたんで
    出会い系サイト紹介所の紹介に掲載されているサイトなどが
    出会い系サイトの中でも信用が出来る
    出会い系サイトなんだと思います!
    出会い系サイトにはとても多くの会員がいてその中には
    出会い系サイトから誘導させて悪徳の
    出会い系サイトに登録をされようとしてきます!
    出会い系サイトでこういったユーザーに出会わないことが
    出会い系サイトで出会える秘訣だと思います!
    出会い系サイトはみなさんの出会いのために
    出会い系サイトを経営しています!
    出会い系サイトに抵抗がある方も一度無料の
    出会い系サイトで出会いをしてみませんか??
    出会い系サイトは貴方の出会いの気持ちを応援いたします!
    出会い系サイトで素敵な出会いを見つけましょう!

  • Anonymous (not verified)
    Sun, 2009-10-18 13:47

    児童文学
    チューハイ
    アイス

    漢字
    猫の飼育
    言葉
    フィギュアスケート

    パ・リーグ
    化粧水

  • Anonymous (not verified)
    Sun, 2009-10-25 21:55

    I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
    Kenali Dan Kunjungi Objek Wisata Di Pandeglang | Love For Blogging | Belajar SEO Blogspot | Miss925 | seo go blog | Kenali dan kunjungi objek wisata di pandeglang | 6 M U | Apa Sih Asyiknya Belajar SEO?

  • Anonymous (not verified)
    Sat, 2010-01-09 04:00

    中古DVD
    DVD
    中古ビデオ
    ドカベン
    韓国ドラマを紹介
    中古ビデオ
    オダギリジョー
    デスメタル
    アダルトDVD
    アダルトDVD
    チュモン
    栗林里莉
    香椎由宇
    ドラゴンボールZ
    星のカービィ
    武勇伝
    韓国ドラマ
    中古DVD
    中古DVD
    牧場の少女カトリ
    セックス・アンド・ザ・シティ
    妖怪人間ベム
    アダルトDVD
    チャン・ドンゴン
    伊勢谷友介
    イ・ビョンホン
    キム・ヘス
    ペ・ヨンジュン
    イ・ボヨン
    アダルトDVD
    持田茜

  • Anonymous (not verified)
    Thu, 2009-10-29 08:16

    割り切り
    セックスフレンド
    処女
    割り切り
    割り切り処女セックスフレンド

  • pariuri sportive (not verified)
    Mon, 2010-01-25 20:17

    Nice tutorial but the comments are spammy