2

I spent some two hours trying to understand why the JavaScript file I am including in my Facebook application is not showing when I view the source of my page. Then guess what the problem turned out to be? I forget to add the final closing bracket of a statement, and as Facebook processes the scripts before adding them (to avoid having unexpected errors in Facebook platform), it didn't attach this script because it has a syntax error!! That is, a whole JavaScript was not added because of a missing bracket!

So to save my time in the future I want to get some syntax validation tools for the scripting languages I am using: PHP, Python, JavaScript, MySQL (although not really a scripting language). Can anybody help me with that? It would be great if they are Vim plugins as I use it heavily.

Feel free to share validation tools for other programming languages, I don't want to keep this post for me only.

Rafid
  • 18,991
  • 23
  • 72
  • 108

3 Answers3

4

It's tagged with VIM so I would suggeest to look at jslint.vim.

I use it (with a few fixes for Windows XP) with VIM 7.3.

Other nice (and much easier to setup on Windows) tool is syntastic.vim. According to documentation it works for eruby, haml, html, javascript, php, python, ruby and sass.

Grzegorz Gierlik
  • 11,112
  • 4
  • 47
  • 55
  • Yes, vim is the most important tag here because I use it a lot :-) Thanks man! – Rafid Jan 13 '11 at 11:20
  • Oh, syntastic.vim seems great. I will try it. – Rafid Jan 13 '11 at 11:43
  • unfortunately, this plugin didn't work for me :-( Have you tried it? Any suggestion? – Rafid Jan 16 '11 at 10:29
  • @Promather -- which one and on which operating system? – Grzegorz Gierlik Jan 17 '11 at 11:33
  • Oh sorry, I should have updated you. I tried it again and it worked. I was talking about syntastic.vim. But I ended up removing it finally. It caused some conflicts with the find/replace I use, probably because I use lvimgrep rather than vimgrep. I should spend some time to make it work for me. – Rafid Jan 17 '11 at 11:52
1

Javascript: JSLint

Python: PyLint, PyChecker, PyFlakes

PHP: Is there a static code analyzer [like Lint] for PHP files?

With scrip^H^H^H^Hdynamic languages, i advise to carefully configure the various lint-like tools, because the style of programming and requirements of the project dictate different needs as for what should be forbidden or not.

For instance, you might want to avoid 'import *' in Python, except in a few cases. Or eval() except you really know what you are doing, etc.

There are several VIM plugins to integrate these tools.

Community
  • 1
  • 1
Marco Mariani
  • 13,556
  • 6
  • 39
  • 55
  • 1
    For other languages, search ie. "Ruby lint". It's also useful to read the rationale behind the style guides. You might find that Google has different needs than you: http://google-styleguide.googlecode.com/svn/trunk/pyguide.html. The same goes for PEP8 or Crockford's advices. – Marco Mariani Jan 13 '11 at 11:23
1

Have a look at the JS Editor available from http://www.yaldex.com/Free_JavaScript_Editor.htm

Their interface is really nice but restricted to Javascript only.

I have used Notepad++ in the past which highlights syntax sufficiently well but lacks other features you'd normally expect in an IDE.

Chandranshu
  • 3,669
  • 3
  • 20
  • 37